feat: sync game data when opening game page

This commit is contained in:
Zamitto
2025-05-26 10:06:19 -03:00
parent 4893d61ee3
commit 1c6bc49ed0
6 changed files with 52 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ import "./library/create-game-shortcut";
import "./library/close-game";
import "./library/delete-game-folder";
import "./library/get-game-by-object-id";
import "./library/sync-game-by-object-id";
import "./library/get-library";
import "./library/extract-game-download";
import "./library/open-game";

View File

@@ -0,0 +1,26 @@
import { registerEvent } from "../register-event";
import { gamesSublevel, levelKeys } from "@main/level";
import { HydraApi } from "@main/services";
import type { GameShop, UserGameDetails } from "@types";
const syncGameByObjectId = async (
_event: Electron.IpcMainInvokeEvent,
shop: GameShop,
objectId: string
) => {
return HydraApi.get<UserGameDetails>(
`/profile/games/${shop}/${objectId}`
).then(async (res) => {
const gameKey = levelKeys.game(shop, objectId);
const game = await gamesSublevel.get(gameKey);
gamesSublevel.put(gameKey, {
...(game ?? { remoteId: null }),
...res,
});
return res;
});
};
registerEvent("syncGameByObjectId", syncGameByObjectId);