From 4c5c602775f48a167c515bf46de9dde524caf33e Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Wed, 22 Jan 2025 09:43:28 +0000 Subject: [PATCH] fix: adding bit validation to is deleted --- .../events/torrenting/pause-game-download.ts | 2 +- src/main/main.ts | 2 +- .../services/download/download-manager.ts | 4 +-- src/main/services/process-watcher.ts | 27 ++++++++++--------- ...ng-game-slice.ts => game-running.slice.ts} | 2 +- src/renderer/src/features/index.ts | 2 +- .../src/pages/downloads/download-group.tsx | 6 ++--- src/types/index.ts | 1 + 8 files changed, 23 insertions(+), 23 deletions(-) rename src/renderer/src/features/{running-game-slice.ts => game-running.slice.ts} (95%) diff --git a/src/main/events/torrenting/pause-game-download.ts b/src/main/events/torrenting/pause-game-download.ts index 6c621e90..e3e14dec 100644 --- a/src/main/events/torrenting/pause-game-download.ts +++ b/src/main/events/torrenting/pause-game-download.ts @@ -14,7 +14,7 @@ const pauseGameDownload = async ( const download = await downloadsSublevel.get(gameKey); if (download) { - await DownloadManager.pauseDownload(); + await DownloadManager.pauseDownload(gameKey); await downloadsSublevel.put(gameKey, { ...download, diff --git a/src/main/main.ts b/src/main/main.ts index 988e84b3..2de58f91 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -86,7 +86,7 @@ const migrateFromSqlite = async () => { playTimeInMilliseconds: game.playTimeInMilliseconds, lastTimePlayed: game.lastTimePlayed, remoteId: game.remoteId, - isDeleted: game.isDeleted, + isDeleted: game.isDeleted === 1, }, })) ); diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index a32263b6..184cc80d 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -207,11 +207,11 @@ export class DownloadManager { WindowManager.mainWindow?.webContents.send("on-seeding-status", seedStatus); } - static async pauseDownload() { + static async pauseDownload(downloadKey = this.downloadingGameId) { await PythonRPC.rpc .post("/action", { action: "pause", - game_id: this.downloadingGameId, + game_id: downloadKey, } as PauseDownloadPayload) .catch(() => {}); diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index a9bf9b92..0b04defe 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -190,12 +190,12 @@ export const watchProcesses = async () => { const hasProcess = processMap.get(executable)?.has(executablePath); if (hasProcess) { - if (gamesPlaytime.has(`${game.shop}-${game.objectId}`)) { + if (gamesPlaytime.has(levelKeys.game(game.shop, game.objectId))) { onTickGame(game); } else { onOpenGame(game); } - } else if (gamesPlaytime.has(`${game.shop}-${game.objectId}`)) { + } else if (gamesPlaytime.has(levelKeys.game(game.shop, game.objectId))) { onCloseGame(game); } } @@ -207,20 +207,17 @@ export const watchProcesses = async () => { return { id: entry[0], sessionDurationInMillis: performance.now() - entry[1].firstTick, - }; + } as Pick; }); - WindowManager.mainWindow.webContents.send( - "on-games-running", - gamesRunning as Pick[] - ); + WindowManager.mainWindow.webContents.send("on-games-running", gamesRunning); } }; function onOpenGame(game: Game) { const now = performance.now(); - gamesPlaytime.set(`${game.shop}-${game.objectId}`, { + gamesPlaytime.set(levelKeys.game(game.shop, game.objectId), { lastTick: now, firstTick: now, lastSyncTick: now, @@ -235,7 +232,9 @@ function onOpenGame(game: Game) { function onTickGame(game: Game) { const now = performance.now(); - const gamePlaytime = gamesPlaytime.get(`${game.shop}-${game.objectId}`)!; + const gamePlaytime = gamesPlaytime.get( + levelKeys.game(game.shop, game.objectId) + )!; const delta = now - gamePlaytime.lastTick; @@ -251,7 +250,7 @@ function onTickGame(game: Game) { lastTimePlayed: new Date(), }); - gamesPlaytime.set(`${game.shop}-${game.objectId}`, { + gamesPlaytime.set(levelKeys.game(game.shop, game.objectId), { ...gamePlaytime, lastTick: now, }); @@ -267,7 +266,7 @@ function onTickGame(game: Game) { gamePromise .then(() => { - gamesPlaytime.set(`${game.shop}-${game.objectId}`, { + gamesPlaytime.set(levelKeys.game(game.shop, game.objectId), { ...gamePlaytime, lastSyncTick: now, }); @@ -277,8 +276,10 @@ function onTickGame(game: Game) { } const onCloseGame = (game: Game) => { - const gamePlaytime = gamesPlaytime.get(`${game.shop}-${game.objectId}`)!; - gamesPlaytime.delete(`${game.shop}-${game.objectId}`); + const gamePlaytime = gamesPlaytime.get( + levelKeys.game(game.shop, game.objectId) + )!; + gamesPlaytime.delete(levelKeys.game(game.shop, game.objectId)); if (game.remoteId) { updateGamePlaytime( diff --git a/src/renderer/src/features/running-game-slice.ts b/src/renderer/src/features/game-running.slice.ts similarity index 95% rename from src/renderer/src/features/running-game-slice.ts rename to src/renderer/src/features/game-running.slice.ts index e1dd609f..18718785 100644 --- a/src/renderer/src/features/running-game-slice.ts +++ b/src/renderer/src/features/game-running.slice.ts @@ -10,7 +10,7 @@ const initialState: GameRunningState = { }; export const gameRunningSlice = createSlice({ - name: "running-game", + name: "game-running", initialState, reducers: { setGameRunning: (state, action: PayloadAction) => { diff --git a/src/renderer/src/features/index.ts b/src/renderer/src/features/index.ts index c0b8753d..9d48c0df 100644 --- a/src/renderer/src/features/index.ts +++ b/src/renderer/src/features/index.ts @@ -4,7 +4,7 @@ export * from "./download-slice"; export * from "./window-slice"; export * from "./toast-slice"; export * from "./user-details-slice"; -export * from "./running-game-slice"; +export * from "./game-running.slice"; export * from "./subscription-slice"; export * from "./repacks-slice"; export * from "./catalogue-search"; diff --git a/src/renderer/src/pages/downloads/download-group.tsx b/src/renderer/src/pages/downloads/download-group.tsx index 36d3395b..87440856 100644 --- a/src/renderer/src/pages/downloads/download-group.tsx +++ b/src/renderer/src/pages/downloads/download-group.tsx @@ -71,8 +71,8 @@ export function DownloadGroup({ if (download.fileSize) return formatBytes(download.fileSize); - if (download.fileSize && isGameDownloading) - return formatBytes(download?.fileSize); + if (lastPacket?.download.fileSize && isGameDownloading) + return formatBytes(lastPacket.download.fileSize); return "N/A"; }; @@ -90,8 +90,6 @@ export function DownloadGroup({ const getGameInfo = (game: LibraryGame) => { const download = game.download!; - console.log(game); - const isGameDownloading = lastPacket?.gameId === game.id; const finalDownloadSize = getFinalDownloadSize(game); const seedingStatus = seedingMap.get(game.id); diff --git a/src/types/index.ts b/src/types/index.ts index 5ce0f480..fdca8009 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -45,6 +45,7 @@ export interface UserGame { } export interface GameRunning { + id: string; title: string; iconUrl: string | null; objectId: string;