diff --git a/src/main/events/library/update-custom-game.ts b/src/main/events/library/update-custom-game.ts index 82d7f45f..62473e54 100644 --- a/src/main/events/library/update-custom-game.ts +++ b/src/main/events/library/update-custom-game.ts @@ -11,7 +11,10 @@ const updateCustomGame = async ( title: string, iconUrl?: string, logoImageUrl?: string, - libraryHeroImageUrl?: string + libraryHeroImageUrl?: string, + originalIconPath?: string, + originalLogoPath?: string, + originalHeroPath?: string ) => { const gameKey = levelKeys.game(shop, objectId); @@ -40,6 +43,9 @@ const updateCustomGame = async ( iconUrl: iconUrl || null, logoImageUrl: logoImageUrl || null, libraryHeroImageUrl: libraryHeroImageUrl || null, + originalIconPath: originalIconPath || existingGame.originalIconPath || null, + originalLogoPath: originalLogoPath || existingGame.originalLogoPath || null, + originalHeroPath: originalHeroPath || existingGame.originalHeroPath || null, }; await gamesSublevel.put(gameKey, updatedGame); diff --git a/src/main/events/library/update-game-custom-assets.ts b/src/main/events/library/update-game-custom-assets.ts index 4bd4e517..8cfc79f0 100644 --- a/src/main/events/library/update-game-custom-assets.ts +++ b/src/main/events/library/update-game-custom-assets.ts @@ -38,7 +38,10 @@ const updateGameData = async ( title: string, customIconUrl?: string | null, customLogoImageUrl?: string | null, - customHeroImageUrl?: string | null + customHeroImageUrl?: string | null, + customOriginalIconPath?: string | null, + customOriginalLogoPath?: string | null, + customOriginalHeroPath?: string | null ): Promise => { const updatedGame = { ...existingGame, @@ -46,6 +49,9 @@ const updateGameData = async ( ...(customIconUrl !== undefined && { customIconUrl }), ...(customLogoImageUrl !== undefined && { customLogoImageUrl }), ...(customHeroImageUrl !== undefined && { customHeroImageUrl }), + ...(customOriginalIconPath !== undefined && { customOriginalIconPath }), + ...(customOriginalLogoPath !== undefined && { customOriginalLogoPath }), + ...(customOriginalHeroPath !== undefined && { customOriginalHeroPath }), }; await gamesSublevel.put(gameKey, updatedGame); @@ -87,7 +93,10 @@ const updateGameCustomAssets = async ( title: string, customIconUrl?: string | null, customLogoImageUrl?: string | null, - customHeroImageUrl?: string | null + customHeroImageUrl?: string | null, + customOriginalIconPath?: string | null, + customOriginalLogoPath?: string | null, + customOriginalHeroPath?: string | null ) => { const gameKey = levelKeys.game(shop, objectId); @@ -109,7 +118,10 @@ const updateGameCustomAssets = async ( title, customIconUrl, customLogoImageUrl, - customHeroImageUrl + customHeroImageUrl, + customOriginalIconPath, + customOriginalLogoPath, + customOriginalHeroPath ); await updateShopAssets(gameKey, title); diff --git a/src/preload/index.ts b/src/preload/index.ts index e536f8c7..e4a29c90 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -158,7 +158,10 @@ contextBridge.exposeInMainWorld("electron", { title: string, iconUrl?: string, logoImageUrl?: string, - libraryHeroImageUrl?: string + libraryHeroImageUrl?: string, + originalIconPath?: string, + originalLogoPath?: string, + originalHeroPath?: string ) => ipcRenderer.invoke( "updateCustomGame", @@ -167,7 +170,10 @@ contextBridge.exposeInMainWorld("electron", { title, iconUrl, logoImageUrl, - libraryHeroImageUrl + libraryHeroImageUrl, + originalIconPath, + originalLogoPath, + originalHeroPath ), updateGameCustomAssets: ( shop: GameShop, @@ -175,7 +181,10 @@ contextBridge.exposeInMainWorld("electron", { title: string, customIconUrl?: string | null, customLogoImageUrl?: string | null, - customHeroImageUrl?: string | null + customHeroImageUrl?: string | null, + customOriginalIconPath?: string | null, + customOriginalLogoPath?: string | null, + customOriginalHeroPath?: string | null ) => ipcRenderer.invoke( "updateGameCustomAssets", @@ -184,7 +193,10 @@ contextBridge.exposeInMainWorld("electron", { title, customIconUrl, customLogoImageUrl, - customHeroImageUrl + customHeroImageUrl, + customOriginalIconPath, + customOriginalLogoPath, + customOriginalHeroPath ), createGameShortcut: ( shop: GameShop, diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 81d18940..9477edb5 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -125,7 +125,10 @@ declare global { title: string, iconUrl?: string, logoImageUrl?: string, - libraryHeroImageUrl?: string + libraryHeroImageUrl?: string, + originalIconPath?: string, + originalLogoPath?: string, + originalHeroPath?: string ) => Promise; copyCustomGameAsset: ( sourcePath: string, @@ -141,7 +144,10 @@ declare global { title: string, customIconUrl?: string | null, customLogoImageUrl?: string | null, - customHeroImageUrl?: string | null + customHeroImageUrl?: string | null, + customOriginalIconPath?: string | null, + customOriginalLogoPath?: string | null, + customOriginalHeroPath?: string | null ) => Promise; createGameShortcut: ( shop: GameShop, diff --git a/src/renderer/src/pages/game-details/modals/edit-game-modal.tsx b/src/renderer/src/pages/game-details/modals/edit-game-modal.tsx index e55772c6..37801c6f 100644 --- a/src/renderer/src/pages/game-details/modals/edit-game-modal.tsx +++ b/src/renderer/src/pages/game-details/modals/edit-game-modal.tsx @@ -39,6 +39,11 @@ export function EditGameModal({ logo: "", hero: "", }); + const [originalAssetPaths, setOriginalAssetPaths] = useState({ + icon: "", + logo: "", + hero: "", + }); const [defaultUrls, setDefaultUrls] = useState({ icon: null as string | null, logo: null as string | null, @@ -66,6 +71,11 @@ export function EditGameModal({ logo: extractLocalPath(game.logoImageUrl), hero: extractLocalPath(game.libraryHeroImageUrl), }); + setOriginalAssetPaths({ + icon: (game as any).originalIconPath || extractLocalPath(game.iconUrl), + logo: (game as any).originalLogoPath || extractLocalPath(game.logoImageUrl), + hero: (game as any).originalHeroPath || extractLocalPath(game.libraryHeroImageUrl), + }); }, []); const setNonCustomGameAssets = useCallback( @@ -80,6 +90,11 @@ export function EditGameModal({ logo: extractLocalPath(game.customLogoImageUrl), hero: extractLocalPath(game.customHeroImageUrl), }); + setOriginalAssetPaths({ + icon: (game as any).customOriginalIconPath || extractLocalPath(game.customIconUrl), + logo: (game as any).customOriginalLogoPath || extractLocalPath(game.customLogoImageUrl), + hero: (game as any).customOriginalHeroPath || extractLocalPath(game.customHeroImageUrl), + }); setDefaultUrls({ icon: shopDetails?.assets?.iconUrl || game.iconUrl || null, @@ -118,7 +133,8 @@ export function EditGameModal({ }; const getAssetDisplayPath = (assetType: AssetType): string => { - return assetDisplayPaths[assetType]; + // Use original path if available, otherwise fall back to display path + return originalAssetPaths[assetType] || assetDisplayPaths[assetType]; }; const setAssetPath = (assetType: AssetType, path: string): void => { @@ -153,10 +169,13 @@ export function EditGameModal({ ); setAssetPath(assetType, copiedAssetUrl.replace("local:", "")); setAssetDisplayPath(assetType, originalPath); + // Store the original path for display purposes + setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: originalPath })); } catch (error) { console.error(`Failed to copy ${assetType} asset:`, error); setAssetPath(assetType, originalPath); setAssetDisplayPath(assetType, originalPath); + setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: originalPath })); } } }; @@ -164,6 +183,7 @@ export function EditGameModal({ const handleRestoreDefault = (assetType: AssetType) => { setAssetPath(assetType, ""); setAssetDisplayPath(assetType, ""); + setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: "" })); }; const getOriginalTitle = (): string => { @@ -326,7 +346,10 @@ export function EditGameModal({ gameName.trim(), iconUrl || undefined, logoImageUrl || undefined, - libraryHeroImageUrl || undefined + libraryHeroImageUrl || undefined, + originalAssetPaths.icon || undefined, + originalAssetPaths.logo || undefined, + originalAssetPaths.hero || undefined ); }; @@ -341,7 +364,10 @@ export function EditGameModal({ gameName.trim(), customIconUrl, customLogoImageUrl, - customHeroImageUrl + customHeroImageUrl, + originalAssetPaths.icon || undefined, + originalAssetPaths.logo || undefined, + originalAssetPaths.hero || undefined ); }; diff --git a/src/types/level.types.ts b/src/types/level.types.ts index 73fce370..8a6c56a0 100644 --- a/src/types/level.types.ts +++ b/src/types/level.types.ts @@ -38,6 +38,12 @@ export interface Game { customIconUrl?: string | null; customLogoImageUrl?: string | null; customHeroImageUrl?: string | null; + originalIconPath?: string | null; + originalLogoPath?: string | null; + originalHeroPath?: string | null; + customOriginalIconPath?: string | null; + customOriginalLogoPath?: string | null; + customOriginalHeroPath?: string | null; playTimeInMilliseconds: number; unsyncedDeltaPlayTimeInMilliseconds?: number; lastTimePlayed: Date | null;