This commit is contained in:
lilezek
2024-05-04 19:35:49 +02:00
31 changed files with 1447 additions and 1484 deletions

View File

@@ -18,7 +18,6 @@ import "./library/open-game";
import "./library/open-game-installer";
import "./library/remove-game";
import "./library/remove-game-from-library";
import "./misc/get-or-cache-image";
import "./misc/open-external";
import "./misc/show-open-dialog";
import "./torrenting/cancel-game-download";

View File

@@ -3,7 +3,7 @@ import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import type { GameShop } from "@types";
import { getImageBase64 } from "@main/helpers";
import { getFileBase64 } from "@main/helpers";
import { getSteamGameIconUrl } from "@main/services";
const addGameToLibrary = async (
@@ -11,7 +11,7 @@ const addGameToLibrary = async (
objectID: string,
title: string,
gameShop: GameShop,
executablePath: string
executablePath: string | null
) => {
const game = await gameRepository.findOne({
where: {
@@ -31,7 +31,7 @@ const addGameToLibrary = async (
}
);
} else {
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
const iconUrl = await getFileBase64(await getSteamGameIconUrl(objectID));
return gameRepository.insert({
title,

View File

@@ -1,40 +0,0 @@
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { registerEvent } from "../register-event";
import { getFileBuffer } from "@main/helpers";
import { logger } from "@main/services";
import { imageCachePath } from "@main/constants";
const getOrCacheImage = async (
_event: Electron.IpcMainInvokeEvent,
url: string
) => {
if (!fs.existsSync(imageCachePath)) fs.mkdirSync(imageCachePath);
const extname = path.extname(url);
const checksum = crypto.createHash("sha256").update(url).digest("hex");
const cachePath = path.join(imageCachePath, `${checksum}${extname}`);
const cache = fs.existsSync(cachePath);
if (cache) return `hydra://${cachePath}`;
getFileBuffer(url).then((buffer) =>
fs.writeFile(cachePath, buffer, (err) => {
if (err) {
logger.error(`Failed to cache image`, err, {
method: "getOrCacheImage",
});
}
})
);
return url;
};
registerEvent(getOrCacheImage, {
name: "getOrCacheImage",
});

View File

@@ -5,7 +5,11 @@ import { registerEvent } from "../register-event";
const showOpenDialog = async (
_event: Electron.IpcMainInvokeEvent,
options: Electron.OpenDialogOptions
) => dialog.showOpenDialog(WindowManager.mainWindow, options);
) => {
if (WindowManager.mainWindow) {
dialog.showOpenDialog(WindowManager.mainWindow, options);
}
};
registerEvent(showOpenDialog, {
name: "showOpenDialog",

View File

@@ -4,7 +4,7 @@ import { gameRepository, repackRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import type { GameShop } from "@types";
import { getImageBase64 } from "@main/helpers";
import { getFileBase64 } from "@main/helpers";
import { In } from "typeorm";
import { Downloader } from "@main/services/downloaders/downloader";
import { GameStatus } from "@globals";
@@ -68,7 +68,7 @@ const startGameDownload = async (
return game;
} else {
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
const iconUrl = await getFileBase64(await getSteamGameIconUrl(objectID));
const createdGame = await gameRepository.save({
title,