mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { gameRepository } from "@main/repository";
|
|
|
|
import { registerEvent } from "../register-event";
|
|
|
|
import type { GameShop } from "@types";
|
|
import { getFileBase64, getSteamAppAsset } from "@main/helpers";
|
|
import { stateManager } from "@main/state-manager";
|
|
|
|
const addGameToLibrary = async (
|
|
_event: Electron.IpcMainInvokeEvent,
|
|
objectID: string,
|
|
title: string,
|
|
shop: GameShop,
|
|
executablePath: string | null
|
|
) => {
|
|
return gameRepository
|
|
.update(
|
|
{
|
|
objectID,
|
|
},
|
|
{
|
|
shop,
|
|
status: null,
|
|
executablePath,
|
|
isDeleted: false,
|
|
}
|
|
)
|
|
.then(async ({ affected }) => {
|
|
if (!affected) {
|
|
const steamGame = stateManager
|
|
.getValue("steamGames")
|
|
.find((game) => game.id === Number(objectID));
|
|
|
|
const iconUrl = steamGame?.clientIcon
|
|
? getSteamAppAsset("icon", objectID, steamGame.clientIcon)
|
|
: null;
|
|
|
|
await gameRepository
|
|
.insert({
|
|
title,
|
|
iconUrl,
|
|
objectID,
|
|
shop,
|
|
executablePath,
|
|
})
|
|
.then(() => {
|
|
if (iconUrl) {
|
|
getFileBase64(iconUrl).then((base64) =>
|
|
gameRepository.update({ objectID }, { iconUrl: base64 })
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
registerEvent("addGameToLibrary", addGameToLibrary);
|