fix: original path to image not showing in modal after updating game asset

This commit is contained in:
Moyasee
2025-09-30 02:09:19 +03:00
parent f0cb2f9579
commit 959bed746b
6 changed files with 81 additions and 13 deletions

View File

@@ -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);

View File

@@ -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<Game> => {
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);

View File

@@ -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,

View File

@@ -125,7 +125,10 @@ declare global {
title: string,
iconUrl?: string,
logoImageUrl?: string,
libraryHeroImageUrl?: string
libraryHeroImageUrl?: string,
originalIconPath?: string,
originalLogoPath?: string,
originalHeroPath?: string
) => Promise<Game>;
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<Game>;
createGameShortcut: (
shop: GameShop,

View File

@@ -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
);
};

View File

@@ -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;