From 1cba3f350c438e281a270d070ea25c8e1bee6959 Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sun, 12 Oct 2025 22:12:15 +0300 Subject: [PATCH 1/6] formatting --- src/shared/html-sanitizer.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shared/html-sanitizer.ts b/src/shared/html-sanitizer.ts index ea3d475b..c78d7dd8 100644 --- a/src/shared/html-sanitizer.ts +++ b/src/shared/html-sanitizer.ts @@ -6,8 +6,6 @@ function removeZalgoText(text: string): string { return text.replaceAll(zalgoRegex, ""); } - - export function sanitizeHtml(html: string): string { if (!html || typeof html !== "string") { return ""; From 60ae7d40faf99a04d84dd225fc4ecc9ccfa4be28 Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sun, 12 Oct 2025 22:34:05 +0300 Subject: [PATCH 2/6] Fix: Image path persists upon clearing image --- .../game-details/modals/edit-game-modal.tsx | 68 ++++++++++++++++--- 1 file changed, 57 insertions(+), 11 deletions(-) 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 a31ce400..71497916 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 @@ -67,6 +67,11 @@ export function EditGameModal({ }; const setCustomGameAssets = useCallback((game: LibraryGame | Game) => { + // Check if assets were removed (URLs are null but original paths exist) + const iconRemoved = !game.iconUrl && (game as any).originalIconPath; + const logoRemoved = !game.logoImageUrl && (game as any).originalLogoPath; + const heroRemoved = !game.libraryHeroImageUrl && (game as any).originalHeroPath; + setAssetPaths({ icon: extractLocalPath(game.iconUrl), logo: extractLocalPath(game.logoImageUrl), @@ -85,10 +90,22 @@ export function EditGameModal({ (game as any).originalHeroPath || extractLocalPath(game.libraryHeroImageUrl), }); + + // Set removed assets state based on whether assets were explicitly removed + setRemovedAssets({ + icon: iconRemoved, + logo: logoRemoved, + hero: heroRemoved, + }); }, []); const setNonCustomGameAssets = useCallback( (game: LibraryGame) => { + // Check if assets were removed (custom URLs are null but original paths exist) + const iconRemoved = !game.customIconUrl && (game as any).customOriginalIconPath; + const logoRemoved = !game.customLogoImageUrl && (game as any).customOriginalLogoPath; + const heroRemoved = !game.customHeroImageUrl && (game as any).customOriginalHeroPath; + setAssetPaths({ icon: extractLocalPath(game.customIconUrl), logo: extractLocalPath(game.customLogoImageUrl), @@ -111,6 +128,13 @@ export function EditGameModal({ extractLocalPath(game.customHeroImageUrl), }); + // Set removed assets state based on whether assets were explicitly removed + setRemovedAssets({ + icon: iconRemoved, + logo: logoRemoved, + hero: heroRemoved, + }); + setDefaultUrls({ icon: shopDetails?.assets?.iconUrl || game.iconUrl || null, logo: shopDetails?.assets?.logoImageUrl || game.logoImageUrl || null, @@ -148,8 +172,12 @@ export function EditGameModal({ }; const getAssetDisplayPath = (assetType: AssetType): string => { - // Use original path if available, otherwise fall back to display path - return originalAssetPaths[assetType] || assetDisplayPaths[assetType]; + // If asset was removed, don't show any path + if (removedAssets[assetType]) { + return ""; + } + // Use display path first, then fall back to original path + return assetDisplayPaths[assetType] || originalAssetPaths[assetType]; }; const setAssetPath = (assetType: AssetType, path: string): void => { @@ -226,12 +254,13 @@ export function EditGameModal({ setRemovedAssets((prev) => ({ ...prev, [assetType]: true })); setAssetPath(assetType, ""); setAssetDisplayPath(assetType, ""); - setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: "" })); + // Don't clear originalAssetPaths - keep them for reference but don't use them for display } else { - // For non-custom games, clear custom assets (restore to shop defaults) + // For non-custom games, also mark asset as removed and clear paths (restore to shop defaults) + setRemovedAssets((prev) => ({ ...prev, [assetType]: true })); setAssetPath(assetType, ""); setAssetDisplayPath(assetType, ""); - setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: "" })); + // Don't clear originalAssetPaths - keep them for reference but don't use them for display } }; @@ -403,9 +432,9 @@ export function EditGameModal({ // Helper function to prepare non-custom game assets const prepareNonCustomGameAssets = () => { return { - customIconUrl: assetPaths.icon ? `local:${assetPaths.icon}` : null, - customLogoImageUrl: assetPaths.logo ? `local:${assetPaths.logo}` : null, - customHeroImageUrl: assetPaths.hero ? `local:${assetPaths.hero}` : null, + customIconUrl: removedAssets.icon ? null : (assetPaths.icon ? `local:${assetPaths.icon}` : null), + customLogoImageUrl: removedAssets.logo ? null : (assetPaths.logo ? `local:${assetPaths.logo}` : null), + customHeroImageUrl: removedAssets.hero ? null : (assetPaths.hero ? `local:${assetPaths.hero}` : null), }; }; @@ -439,9 +468,9 @@ export function EditGameModal({ customIconUrl, customLogoImageUrl, customHeroImageUrl, - customOriginalIconPath: originalAssetPaths.icon || undefined, - customOriginalLogoPath: originalAssetPaths.logo || undefined, - customOriginalHeroPath: originalAssetPaths.hero || undefined, + customOriginalIconPath: removedAssets.icon ? undefined : (originalAssetPaths.icon || undefined), + customOriginalLogoPath: removedAssets.logo ? undefined : (originalAssetPaths.logo || undefined), + customOriginalHeroPath: removedAssets.hero ? undefined : (originalAssetPaths.hero || undefined), }); }; @@ -484,6 +513,23 @@ export function EditGameModal({ hero: false, }); + // Clear all asset paths to ensure clean state + setAssetPaths({ + icon: "", + logo: "", + hero: "", + }); + setAssetDisplayPaths({ + icon: "", + logo: "", + hero: "", + }); + setOriginalAssetPaths({ + icon: "", + logo: "", + hero: "", + }); + if (isCustomGame(game)) { setCustomGameAssets(game); // Clear default URLs for custom games From 68e2e2a772593580dd0c722a5b0ca542f424a9dd Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sun, 12 Oct 2025 22:39:26 +0300 Subject: [PATCH 3/6] Fix: conditional structure --- .../game-details/modals/edit-game-modal.tsx | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) 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 71497916..d8d47cf4 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 @@ -70,7 +70,8 @@ export function EditGameModal({ // Check if assets were removed (URLs are null but original paths exist) const iconRemoved = !game.iconUrl && (game as any).originalIconPath; const logoRemoved = !game.logoImageUrl && (game as any).originalLogoPath; - const heroRemoved = !game.libraryHeroImageUrl && (game as any).originalHeroPath; + const heroRemoved = + !game.libraryHeroImageUrl && (game as any).originalHeroPath; setAssetPaths({ icon: extractLocalPath(game.iconUrl), @@ -102,9 +103,12 @@ export function EditGameModal({ const setNonCustomGameAssets = useCallback( (game: LibraryGame) => { // Check if assets were removed (custom URLs are null but original paths exist) - const iconRemoved = !game.customIconUrl && (game as any).customOriginalIconPath; - const logoRemoved = !game.customLogoImageUrl && (game as any).customOriginalLogoPath; - const heroRemoved = !game.customHeroImageUrl && (game as any).customOriginalHeroPath; + const iconRemoved = + !game.customIconUrl && (game as any).customOriginalIconPath; + const logoRemoved = + !game.customLogoImageUrl && (game as any).customOriginalLogoPath; + const heroRemoved = + !game.customHeroImageUrl && (game as any).customOriginalHeroPath; setAssetPaths({ icon: extractLocalPath(game.customIconUrl), @@ -249,19 +253,11 @@ export function EditGameModal({ }; const handleRestoreDefault = (assetType: AssetType) => { - if (game && isCustomGame(game)) { - // For custom games, mark asset as removed and clear paths - setRemovedAssets((prev) => ({ ...prev, [assetType]: true })); - setAssetPath(assetType, ""); - setAssetDisplayPath(assetType, ""); - // Don't clear originalAssetPaths - keep them for reference but don't use them for display - } else { - // For non-custom games, also mark asset as removed and clear paths (restore to shop defaults) - setRemovedAssets((prev) => ({ ...prev, [assetType]: true })); - setAssetPath(assetType, ""); - setAssetDisplayPath(assetType, ""); - // Don't clear originalAssetPaths - keep them for reference but don't use them for display - } + // Mark asset as removed and clear paths (for both custom and non-custom games) + setRemovedAssets((prev) => ({ ...prev, [assetType]: true })); + setAssetPath(assetType, ""); + setAssetDisplayPath(assetType, ""); + // Don't clear originalAssetPaths - keep them for reference but don't use them for display }; const getOriginalTitle = (): string => { @@ -432,9 +428,21 @@ export function EditGameModal({ // Helper function to prepare non-custom game assets const prepareNonCustomGameAssets = () => { return { - customIconUrl: removedAssets.icon ? null : (assetPaths.icon ? `local:${assetPaths.icon}` : null), - customLogoImageUrl: removedAssets.logo ? null : (assetPaths.logo ? `local:${assetPaths.logo}` : null), - customHeroImageUrl: removedAssets.hero ? null : (assetPaths.hero ? `local:${assetPaths.hero}` : null), + customIconUrl: removedAssets.icon + ? null + : assetPaths.icon + ? `local:${assetPaths.icon}` + : null, + customLogoImageUrl: removedAssets.logo + ? null + : assetPaths.logo + ? `local:${assetPaths.logo}` + : null, + customHeroImageUrl: removedAssets.hero + ? null + : assetPaths.hero + ? `local:${assetPaths.hero}` + : null, }; }; @@ -468,9 +476,15 @@ export function EditGameModal({ customIconUrl, customLogoImageUrl, customHeroImageUrl, - customOriginalIconPath: removedAssets.icon ? undefined : (originalAssetPaths.icon || undefined), - customOriginalLogoPath: removedAssets.logo ? undefined : (originalAssetPaths.logo || undefined), - customOriginalHeroPath: removedAssets.hero ? undefined : (originalAssetPaths.hero || undefined), + customOriginalIconPath: removedAssets.icon + ? undefined + : originalAssetPaths.icon || undefined, + customOriginalLogoPath: removedAssets.logo + ? undefined + : originalAssetPaths.logo || undefined, + customOriginalHeroPath: removedAssets.hero + ? undefined + : originalAssetPaths.hero || undefined, }); }; From 0cd4c3ccf6e6c28ae9cc27f1827814c46b0b378e Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sun, 12 Oct 2025 22:45:20 +0300 Subject: [PATCH 4/6] Fix: extracted ternary operations --- .../game-details/modals/edit-game-modal.tsx | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) 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 d8d47cf4..38caa5a0 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 @@ -427,22 +427,28 @@ export function EditGameModal({ // Helper function to prepare non-custom game assets const prepareNonCustomGameAssets = () => { + const customIconUrl = removedAssets.icon + ? null + : assetPaths.icon + ? `local:${assetPaths.icon}` + : null; + + const customLogoImageUrl = removedAssets.logo + ? null + : assetPaths.logo + ? `local:${assetPaths.logo}` + : null; + + const customHeroImageUrl = removedAssets.hero + ? null + : assetPaths.hero + ? `local:${assetPaths.hero}` + : null; + return { - customIconUrl: removedAssets.icon - ? null - : assetPaths.icon - ? `local:${assetPaths.icon}` - : null, - customLogoImageUrl: removedAssets.logo - ? null - : assetPaths.logo - ? `local:${assetPaths.logo}` - : null, - customHeroImageUrl: removedAssets.hero - ? null - : assetPaths.hero - ? `local:${assetPaths.hero}` - : null, + customIconUrl, + customLogoImageUrl, + customHeroImageUrl, }; }; From a946f3bd5a28d1aac074f9b5961e994bca58e34d Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sun, 12 Oct 2025 22:48:33 +0300 Subject: [PATCH 5/6] Fix: extracted ternary operations --- .../src/pages/game-details/modals/edit-game-modal.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 38caa5a0..2d6ae0fe 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 @@ -427,21 +427,24 @@ export function EditGameModal({ // Helper function to prepare non-custom game assets const prepareNonCustomGameAssets = () => { + const hasIconPath = assetPaths.icon; const customIconUrl = removedAssets.icon ? null - : assetPaths.icon + : hasIconPath ? `local:${assetPaths.icon}` : null; + const hasLogoPath = assetPaths.logo; const customLogoImageUrl = removedAssets.logo ? null - : assetPaths.logo + : hasLogoPath ? `local:${assetPaths.logo}` : null; + const hasHeroPath = assetPaths.hero; const customHeroImageUrl = removedAssets.hero ? null - : assetPaths.hero + : hasHeroPath ? `local:${assetPaths.hero}` : null; From e71211f1aad7daac1442fe2f3244b0baf2f8543c Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sun, 12 Oct 2025 22:51:35 +0300 Subject: [PATCH 6/6] Fix: extracted ternary operations --- .../game-details/modals/edit-game-modal.tsx | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) 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 2d6ae0fe..2de46304 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 @@ -428,25 +428,22 @@ export function EditGameModal({ // Helper function to prepare non-custom game assets const prepareNonCustomGameAssets = () => { const hasIconPath = assetPaths.icon; - const customIconUrl = removedAssets.icon - ? null - : hasIconPath - ? `local:${assetPaths.icon}` - : null; + let customIconUrl: string | null = null; + if (!removedAssets.icon && hasIconPath) { + customIconUrl = `local:${assetPaths.icon}`; + } const hasLogoPath = assetPaths.logo; - const customLogoImageUrl = removedAssets.logo - ? null - : hasLogoPath - ? `local:${assetPaths.logo}` - : null; + let customLogoImageUrl: string | null = null; + if (!removedAssets.logo && hasLogoPath) { + customLogoImageUrl = `local:${assetPaths.logo}`; + } const hasHeroPath = assetPaths.hero; - const customHeroImageUrl = removedAssets.hero - ? null - : hasHeroPath - ? `local:${assetPaths.hero}` - : null; + let customHeroImageUrl: string | null = null; + if (!removedAssets.hero && hasHeroPath) { + customHeroImageUrl = `local:${assetPaths.hero}`; + } return { customIconUrl,