Skip to content

exe icons for custom games #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/handlers/fileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const FileSystemHandlers: TFileSystemHandlers = {
return { path, files };
},
revealInFileExplorer: async (_, path) => {
shell.showItemInFolder(path);
shell.openPath(path);
},
};

Expand Down
3 changes: 3 additions & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
45 changes: 39 additions & 6 deletions src/main/utils/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/GameHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/types/games.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ declare global {
gamePath?: TPlatformSpecific<TFolderOrFilesRaw>;

savesConfig?: TPlatformSpecific<TSavesConfig>;

iconImg?: string;
};

type TSavesConfigType = "simple" | "advanced";
Expand Down