import { registerEvent } from "../register-event"; import { gamesSublevel, gamesShopAssetsSublevel, levelKeys } from "@main/level"; import type { GameShop } from "@types"; const updateCustomGame = async ( _event: Electron.IpcMainInvokeEvent, shop: GameShop, objectId: string, title: string, iconUrl?: string, logoImageUrl?: string, libraryHeroImageUrl?: string ) => { const gameKey = levelKeys.game(shop, objectId); const existingGame = await gamesSublevel.get(gameKey); if (!existingGame) { throw new Error("Game not found"); } const updatedGame = { ...existingGame, title, iconUrl: iconUrl || null, logoImageUrl: logoImageUrl || null, libraryHeroImageUrl: libraryHeroImageUrl || null, }; await gamesSublevel.put(gameKey, updatedGame); const existingAssets = await gamesShopAssetsSublevel.get(gameKey); if (existingAssets) { const updatedAssets = { ...existingAssets, title, iconUrl: iconUrl || null, libraryHeroImageUrl: libraryHeroImageUrl || "", libraryImageUrl: iconUrl || "", logoImageUrl: logoImageUrl || "", coverImageUrl: iconUrl || "", }; await gamesShopAssetsSublevel.put(gameKey, updatedAssets); } return updatedGame; }; registerEvent("updateCustomGame", updateCustomGame);