diff --git a/src/main/handlers/fileSystem.ts b/src/main/handlers/fileSystem.ts index 90e348a..78604d5 100644 --- a/src/main/handlers/fileSystem.ts +++ b/src/main/handlers/fileSystem.ts @@ -27,7 +27,7 @@ const FileSystemHandlers: TFileSystemHandlers = { return { path, files }; }, revealInFileExplorer: async (_, path) => { - shell.showItemInFolder(path); + shell.openPath(path); }, }; diff --git a/src/main/main.ts b/src/main/main.ts index 23c49f7..b7e802e 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -95,7 +95,10 @@ class Main { RESOURCES_PATH, IS_DEV: isDev, }); + await Games.fillSteamGames(); + await Games.updateGamesIcons(); + Stores.Settings.set("runtimeValues.isLoadingApp", false); protocol.registerFileProtocol("file", (request, callback) => { diff --git a/src/main/utils/games.ts b/src/main/utils/games.ts index 6702e5c..bcebaab 100644 --- a/src/main/utils/games.ts +++ b/src/main/utils/games.ts @@ -7,6 +7,8 @@ import Processes from "./processes"; import Stores from "../stores"; import { PLATFORM } from "./config"; import { joinAndNormalize } from "."; +import { app, nativeImage } from "electron"; +import path from "path"; const generateUniqGameId = (limit = 10): string | null => { let result = null; @@ -137,10 +139,6 @@ const createCustomGame = async ( } const name = payload.gamePath.files[0] || "Unknown"; - const gamePath = joinAndNormalize( - payload.gamePath.path, - payload.gamePath.files[0] - ); const newGame: TGame = { id, @@ -152,7 +150,7 @@ const createCustomGame = async ( savePointsFolderName: name.replace(".exe", ""), savesStats: { total: 0, auto: 0, manual: 0 }, imageUrl: undefined, - gamePath: { [PLATFORM]: { path: gamePath } }, + gamePath: { [PLATFORM]: payload.gamePath }, }; console.log(newGame); @@ -180,11 +178,46 @@ const updateRunningGames = async () => { } }; +const updateGamesIcons = async () => { + const games = Object.values(Stores.Games.store.games); + const gamesWithPathToExe = games.filter((g) => + g.gamePath?.[PLATFORM]?.files?.[0]?.endsWith(".exe") + ); + console.log(gamesWithPathToExe); + for (const game of gamesWithPathToExe) { + try { + console.log("game", game.name); + const gamePath = game.gamePath?.[PLATFORM]; + if (gamePath?.path && gamePath?.files?.[0]) { + const pathToExe = joinAndNormalize( + gamePath?.path, + gamePath?.files?.[0] + ); + const pathToExeNormalized = path.normalize(pathToExe); + console.log({ pathToExe, pathToExeNormalized }); + const icon = await nativeImage.createThumbnailFromPath( + pathToExeNormalized, + { width: 512, height: 512 } + ); + if (icon) { + console.log(icon.isEmpty()); + Stores.Games.set( + `games.${game.id}.iconImg`, + icon.toPNG().toString("base64") + ); + } + } + } catch (err) { + console.log(err); + } + } +}; + const Games = { - // create, createCustomGame, fillSteamGames, updateRunningGames, + updateGamesIcons, // TODO: // getValidAndRunningGames }; diff --git a/src/renderer/components/GameHeader.tsx b/src/renderer/components/GameHeader.tsx index b82ec74..e8eab91 100644 --- a/src/renderer/components/GameHeader.tsx +++ b/src/renderer/components/GameHeader.tsx @@ -13,7 +13,7 @@ const GameHeader = (props: TProps) => { const { game } = props; const name = game?.name || "Unknown game"; - const imgSrc = game.imageUrl; + const imgSrc = game.imageUrl || `data:image/png;base64,${game.iconImg}`; const onSave = async () => { await window.electron.makeSavePoint(game.id); diff --git a/src/types/games.d.ts b/src/types/games.d.ts index bb0fb7c..0b0f377 100644 --- a/src/types/games.d.ts +++ b/src/types/games.d.ts @@ -45,6 +45,8 @@ declare global { gamePath?: TPlatformSpecific; savesConfig?: TPlatformSpecific; + + iconImg?: string; }; type TSavesConfigType = "simple" | "advanced";