mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-15 16:33:02 -03:00
Merge pull request #1795 from hydralauncher/feat/revert-title-and-cleanup-fix
Fix: Playtime font size and original path in edit game modal fix
This commit is contained in:
@@ -4,15 +4,33 @@ import type { GameShop } from "@types";
|
||||
import fs from "node:fs";
|
||||
import { logger } from "@main/services";
|
||||
|
||||
interface UpdateCustomGameParams {
|
||||
shop: GameShop;
|
||||
objectId: string;
|
||||
title: string;
|
||||
iconUrl?: string;
|
||||
logoImageUrl?: string;
|
||||
libraryHeroImageUrl?: string;
|
||||
originalIconPath?: string;
|
||||
originalLogoPath?: string;
|
||||
originalHeroPath?: string;
|
||||
}
|
||||
|
||||
const updateCustomGame = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
title: string,
|
||||
iconUrl?: string,
|
||||
logoImageUrl?: string,
|
||||
libraryHeroImageUrl?: string
|
||||
params: UpdateCustomGameParams
|
||||
) => {
|
||||
const {
|
||||
shop,
|
||||
objectId,
|
||||
title,
|
||||
iconUrl,
|
||||
logoImageUrl,
|
||||
libraryHeroImageUrl,
|
||||
originalIconPath,
|
||||
originalLogoPath,
|
||||
originalHeroPath,
|
||||
} = params;
|
||||
const gameKey = levelKeys.game(shop, objectId);
|
||||
|
||||
const existingGame = await gamesSublevel.get(gameKey);
|
||||
@@ -40,6 +58,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);
|
||||
|
||||
@@ -32,20 +32,39 @@ const collectOldAssetPaths = (
|
||||
return oldAssetPaths;
|
||||
};
|
||||
|
||||
const updateGameData = async (
|
||||
gameKey: string,
|
||||
existingGame: Game,
|
||||
title: string,
|
||||
customIconUrl?: string | null,
|
||||
customLogoImageUrl?: string | null,
|
||||
customHeroImageUrl?: string | null
|
||||
): Promise<Game> => {
|
||||
interface UpdateGameDataParams {
|
||||
gameKey: string;
|
||||
existingGame: Game;
|
||||
title: string;
|
||||
customIconUrl?: string | null;
|
||||
customLogoImageUrl?: string | null;
|
||||
customHeroImageUrl?: string | null;
|
||||
customOriginalIconPath?: string | null;
|
||||
customOriginalLogoPath?: string | null;
|
||||
customOriginalHeroPath?: string | null;
|
||||
}
|
||||
|
||||
const updateGameData = async (params: UpdateGameDataParams): Promise<Game> => {
|
||||
const {
|
||||
gameKey,
|
||||
existingGame,
|
||||
title,
|
||||
customIconUrl,
|
||||
customLogoImageUrl,
|
||||
customHeroImageUrl,
|
||||
customOriginalIconPath,
|
||||
customOriginalLogoPath,
|
||||
customOriginalHeroPath,
|
||||
} = params;
|
||||
const updatedGame = {
|
||||
...existingGame,
|
||||
title,
|
||||
...(customIconUrl !== undefined && { customIconUrl }),
|
||||
...(customLogoImageUrl !== undefined && { customLogoImageUrl }),
|
||||
...(customHeroImageUrl !== undefined && { customHeroImageUrl }),
|
||||
...(customOriginalIconPath !== undefined && { customOriginalIconPath }),
|
||||
...(customOriginalLogoPath !== undefined && { customOriginalLogoPath }),
|
||||
...(customOriginalHeroPath !== undefined && { customOriginalHeroPath }),
|
||||
};
|
||||
|
||||
await gamesSublevel.put(gameKey, updatedGame);
|
||||
@@ -80,15 +99,33 @@ const deleteOldAssetFiles = async (oldAssetPaths: string[]): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
interface UpdateGameCustomAssetsParams {
|
||||
shop: GameShop;
|
||||
objectId: string;
|
||||
title: string;
|
||||
customIconUrl?: string | null;
|
||||
customLogoImageUrl?: string | null;
|
||||
customHeroImageUrl?: string | null;
|
||||
customOriginalIconPath?: string | null;
|
||||
customOriginalLogoPath?: string | null;
|
||||
customOriginalHeroPath?: string | null;
|
||||
}
|
||||
|
||||
const updateGameCustomAssets = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
title: string,
|
||||
customIconUrl?: string | null,
|
||||
customLogoImageUrl?: string | null,
|
||||
customHeroImageUrl?: string | null
|
||||
params: UpdateGameCustomAssetsParams
|
||||
) => {
|
||||
const {
|
||||
shop,
|
||||
objectId,
|
||||
title,
|
||||
customIconUrl,
|
||||
customLogoImageUrl,
|
||||
customHeroImageUrl,
|
||||
customOriginalIconPath,
|
||||
customOriginalLogoPath,
|
||||
customOriginalHeroPath,
|
||||
} = params;
|
||||
const gameKey = levelKeys.game(shop, objectId);
|
||||
|
||||
const existingGame = await gamesSublevel.get(gameKey);
|
||||
@@ -103,14 +140,17 @@ const updateGameCustomAssets = async (
|
||||
customHeroImageUrl
|
||||
);
|
||||
|
||||
const updatedGame = await updateGameData(
|
||||
const updatedGame = await updateGameData({
|
||||
gameKey,
|
||||
existingGame,
|
||||
title,
|
||||
customIconUrl,
|
||||
customLogoImageUrl,
|
||||
customHeroImageUrl
|
||||
);
|
||||
customHeroImageUrl,
|
||||
customOriginalIconPath,
|
||||
customOriginalLogoPath,
|
||||
customOriginalHeroPath,
|
||||
});
|
||||
|
||||
await updateShopAssets(gameKey, title);
|
||||
|
||||
|
||||
@@ -152,40 +152,28 @@ contextBridge.exposeInMainWorld("electron", {
|
||||
deleteTempFile: (filePath: string) =>
|
||||
ipcRenderer.invoke("deleteTempFile", filePath),
|
||||
cleanupUnusedAssets: () => ipcRenderer.invoke("cleanupUnusedAssets"),
|
||||
updateCustomGame: (
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
title: string,
|
||||
iconUrl?: string,
|
||||
logoImageUrl?: string,
|
||||
libraryHeroImageUrl?: string
|
||||
) =>
|
||||
ipcRenderer.invoke(
|
||||
"updateCustomGame",
|
||||
shop,
|
||||
objectId,
|
||||
title,
|
||||
iconUrl,
|
||||
logoImageUrl,
|
||||
libraryHeroImageUrl
|
||||
),
|
||||
updateGameCustomAssets: (
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
title: string,
|
||||
customIconUrl?: string | null,
|
||||
customLogoImageUrl?: string | null,
|
||||
customHeroImageUrl?: string | null
|
||||
) =>
|
||||
ipcRenderer.invoke(
|
||||
"updateGameCustomAssets",
|
||||
shop,
|
||||
objectId,
|
||||
title,
|
||||
customIconUrl,
|
||||
customLogoImageUrl,
|
||||
customHeroImageUrl
|
||||
),
|
||||
updateCustomGame: (params: {
|
||||
shop: GameShop;
|
||||
objectId: string;
|
||||
title: string;
|
||||
iconUrl?: string;
|
||||
logoImageUrl?: string;
|
||||
libraryHeroImageUrl?: string;
|
||||
originalIconPath?: string;
|
||||
originalLogoPath?: string;
|
||||
originalHeroPath?: string;
|
||||
}) => ipcRenderer.invoke("updateCustomGame", params),
|
||||
updateGameCustomAssets: (params: {
|
||||
shop: GameShop;
|
||||
objectId: string;
|
||||
title: string;
|
||||
customIconUrl?: string | null;
|
||||
customLogoImageUrl?: string | null;
|
||||
customHeroImageUrl?: string | null;
|
||||
customOriginalIconPath?: string | null;
|
||||
customOriginalLogoPath?: string | null;
|
||||
customOriginalHeroPath?: string | null;
|
||||
}) => ipcRenderer.invoke("updateGameCustomAssets", params),
|
||||
createGameShortcut: (
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
|
||||
38
src/renderer/src/declaration.d.ts
vendored
38
src/renderer/src/declaration.d.ts
vendored
@@ -119,14 +119,17 @@ declare global {
|
||||
logoImageUrl?: string,
|
||||
libraryHeroImageUrl?: string
|
||||
) => Promise<Game>;
|
||||
updateCustomGame: (
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
title: string,
|
||||
iconUrl?: string,
|
||||
logoImageUrl?: string,
|
||||
libraryHeroImageUrl?: string
|
||||
) => Promise<Game>;
|
||||
updateCustomGame: (params: {
|
||||
shop: GameShop;
|
||||
objectId: string;
|
||||
title: string;
|
||||
iconUrl?: string;
|
||||
logoImageUrl?: string;
|
||||
libraryHeroImageUrl?: string;
|
||||
originalIconPath?: string;
|
||||
originalLogoPath?: string;
|
||||
originalHeroPath?: string;
|
||||
}) => Promise<Game>;
|
||||
copyCustomGameAsset: (
|
||||
sourcePath: string,
|
||||
assetType: "icon" | "logo" | "hero"
|
||||
@@ -135,14 +138,17 @@ declare global {
|
||||
deletedCount: number;
|
||||
errors: string[];
|
||||
}>;
|
||||
updateGameCustomAssets: (
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
title: string,
|
||||
customIconUrl?: string | null,
|
||||
customLogoImageUrl?: string | null,
|
||||
customHeroImageUrl?: string | null
|
||||
) => Promise<Game>;
|
||||
updateGameCustomAssets: (params: {
|
||||
shop: GameShop;
|
||||
objectId: string;
|
||||
title: string;
|
||||
customIconUrl?: string | null;
|
||||
customLogoImageUrl?: string | null;
|
||||
customHeroImageUrl?: string | null;
|
||||
customOriginalIconPath?: string | null;
|
||||
customOriginalLogoPath?: string | null;
|
||||
customOriginalHeroPath?: string | null;
|
||||
}) => Promise<Game>;
|
||||
createGameShortcut: (
|
||||
shop: GameShop,
|
||||
objectId: string,
|
||||
|
||||
@@ -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,14 @@ 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,11 +93,25 @@ 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,
|
||||
logo: shopDetails?.assets?.logoImageUrl || game.logoImageUrl || null,
|
||||
hero: shopDetails?.assets?.libraryHeroImageUrl || game.libraryHeroImageUrl || null,
|
||||
hero:
|
||||
shopDetails?.assets?.libraryHeroImageUrl ||
|
||||
game.libraryHeroImageUrl ||
|
||||
null,
|
||||
});
|
||||
},
|
||||
[shopDetails]
|
||||
@@ -115,15 +142,16 @@ 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 => {
|
||||
setAssetPaths(prev => ({ ...prev, [assetType]: path }));
|
||||
setAssetPaths((prev) => ({ ...prev, [assetType]: path }));
|
||||
};
|
||||
|
||||
const setAssetDisplayPath = (assetType: AssetType, path: string): void => {
|
||||
setAssetDisplayPaths(prev => ({ ...prev, [assetType]: path }));
|
||||
setAssetDisplayPaths((prev) => ({ ...prev, [assetType]: path }));
|
||||
};
|
||||
|
||||
const getDefaultUrl = (assetType: AssetType): string | null => {
|
||||
@@ -150,10 +178,19 @@ 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,
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -161,6 +198,7 @@ export function EditGameModal({
|
||||
const handleRestoreDefault = (assetType: AssetType) => {
|
||||
setAssetPath(assetType, "");
|
||||
setAssetDisplayPath(assetType, "");
|
||||
setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: "" }));
|
||||
};
|
||||
|
||||
const getOriginalTitle = (): string => {
|
||||
@@ -293,7 +331,9 @@ export function EditGameModal({
|
||||
// Helper function to prepare custom game assets
|
||||
const prepareCustomGameAssets = (game: LibraryGame | Game) => {
|
||||
const iconUrl = assetPaths.icon ? `local:${assetPaths.icon}` : game.iconUrl;
|
||||
const logoImageUrl = assetPaths.logo ? `local:${assetPaths.logo}` : game.logoImageUrl;
|
||||
const logoImageUrl = assetPaths.logo
|
||||
? `local:${assetPaths.logo}`
|
||||
: game.logoImageUrl;
|
||||
const libraryHeroImageUrl = assetPaths.hero
|
||||
? `local:${assetPaths.hero}`
|
||||
: game.libraryHeroImageUrl;
|
||||
@@ -315,14 +355,17 @@ export function EditGameModal({
|
||||
const { iconUrl, logoImageUrl, libraryHeroImageUrl } =
|
||||
prepareCustomGameAssets(game);
|
||||
|
||||
return window.electron.updateCustomGame(
|
||||
game.shop,
|
||||
game.objectId,
|
||||
gameName.trim(),
|
||||
iconUrl || undefined,
|
||||
logoImageUrl || undefined,
|
||||
libraryHeroImageUrl || undefined
|
||||
);
|
||||
return window.electron.updateCustomGame({
|
||||
shop: game.shop,
|
||||
objectId: game.objectId,
|
||||
title: gameName.trim(),
|
||||
iconUrl: iconUrl || undefined,
|
||||
logoImageUrl: logoImageUrl || undefined,
|
||||
libraryHeroImageUrl: libraryHeroImageUrl || undefined,
|
||||
originalIconPath: originalAssetPaths.icon || undefined,
|
||||
originalLogoPath: originalAssetPaths.logo || undefined,
|
||||
originalHeroPath: originalAssetPaths.hero || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
// Helper function to update non-custom game
|
||||
@@ -330,14 +373,17 @@ export function EditGameModal({
|
||||
const { customIconUrl, customLogoImageUrl, customHeroImageUrl } =
|
||||
prepareNonCustomGameAssets();
|
||||
|
||||
return window.electron.updateGameCustomAssets(
|
||||
game.shop,
|
||||
game.objectId,
|
||||
gameName.trim(),
|
||||
return window.electron.updateGameCustomAssets({
|
||||
shop: game.shop,
|
||||
objectId: game.objectId,
|
||||
title: gameName.trim(),
|
||||
customIconUrl,
|
||||
customLogoImageUrl,
|
||||
customHeroImageUrl
|
||||
);
|
||||
customHeroImageUrl,
|
||||
customOriginalIconPath: originalAssetPaths.icon || undefined,
|
||||
customOriginalLogoPath: originalAssetPaths.logo || undefined,
|
||||
customOriginalHeroPath: originalAssetPaths.hero || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
const handleUpdateGame = async () => {
|
||||
|
||||
@@ -164,10 +164,12 @@
|
||||
|
||||
&-long {
|
||||
display: inline;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
&-short {
|
||||
display: none;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
// When the card is narrow (less than 180px), show short format
|
||||
|
||||
@@ -44,7 +44,6 @@ export function UserLibraryGameCard({
|
||||
const [isTooltipHovered, setIsTooltipHovered] = useState(false);
|
||||
const [isPinning, setIsPinning] = useState(false);
|
||||
|
||||
|
||||
const getStatsItemCount = useCallback(() => {
|
||||
let statsCount = 1;
|
||||
if (game.achievementsPointsEarnedSum > 0) statsCount++;
|
||||
@@ -91,15 +90,15 @@ export function UserLibraryGameCard({
|
||||
|
||||
const hours = minutes / 60;
|
||||
const hoursKey = isShort ? "amount_hours_short" : "amount_hours";
|
||||
const hoursAmount = isShort ? Math.floor(hours) : numberFormatter.format(hours);
|
||||
|
||||
const hoursAmount = isShort
|
||||
? Math.floor(hours)
|
||||
: numberFormatter.format(hours);
|
||||
|
||||
return t(hoursKey, { amount: hoursAmount });
|
||||
},
|
||||
[numberFormatter, t]
|
||||
);
|
||||
|
||||
|
||||
|
||||
const toggleGamePinned = async () => {
|
||||
setIsPinning(true);
|
||||
|
||||
@@ -162,7 +161,7 @@ export function UserLibraryGameCard({
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
<div
|
||||
className="user-library-game__playtime"
|
||||
data-tooltip-place="top"
|
||||
data-tooltip-content={
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user