From cf84bf56b385c0e37a7f4536197b2ebb9f4112b6 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 18 Jun 2024 21:46:20 -0300 Subject: [PATCH 1/4] missing parse to int in put /games/:gameId --- src/main/services/library-sync/create-game.ts | 2 +- src/main/services/library-sync/update-game-playtime.ts | 2 +- src/main/services/library-sync/upload-batch-games.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/services/library-sync/create-game.ts b/src/main/services/library-sync/create-game.ts index 823f56a6..6e56a3de 100644 --- a/src/main/services/library-sync/create-game.ts +++ b/src/main/services/library-sync/create-game.ts @@ -4,7 +4,7 @@ import { HydraApi } from "../hydra-api"; export const createGame = async (game: Game) => { return HydraApi.post(`/games`, { objectId: game.objectID, - playTimeInMilliseconds: Math.round(game.playTimeInMilliseconds), + playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds), shop: game.shop, lastTimePlayed: game.lastTimePlayed, }); diff --git a/src/main/services/library-sync/update-game-playtime.ts b/src/main/services/library-sync/update-game-playtime.ts index 271dc6a5..efedf47c 100644 --- a/src/main/services/library-sync/update-game-playtime.ts +++ b/src/main/services/library-sync/update-game-playtime.ts @@ -7,7 +7,7 @@ export const updateGamePlaytime = async ( lastTimePlayed: Date ) => { return HydraApi.put(`/games/${game.remoteId}`, { - playTimeDeltaInSeconds: delta, + playTimeDeltaInSeconds: Math.trunc(delta), lastTimePlayed, }); }; diff --git a/src/main/services/library-sync/upload-batch-games.ts b/src/main/services/library-sync/upload-batch-games.ts index cfea9d39..5f12522b 100644 --- a/src/main/services/library-sync/upload-batch-games.ts +++ b/src/main/services/library-sync/upload-batch-games.ts @@ -18,7 +18,7 @@ export const uploadBatchGames = async () => { chunk.map((game) => { return { objectId: game.objectID, - playTimeInMilliseconds: Math.round(game.playTimeInMilliseconds), + playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds), shop: game.shop, lastTimePlayed: game.lastTimePlayed, }; From 6179fb9cf66e9491ff7d96c4f31cee717209e700 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 18 Jun 2024 21:49:41 -0300 Subject: [PATCH 2/4] call batch games on hydra start up --- src/main/main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/main.ts b/src/main/main.ts index f1a365fc..6c82fe34 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -10,7 +10,7 @@ import { fetchDownloadSourcesAndUpdate } from "./helpers"; import { publishNewRepacksNotifications } from "./services/notifications"; import { MoreThan } from "typeorm"; import { HydraApi } from "./services/hydra-api"; -import { getRemoteGames } from "./services/library-sync"; +import { getRemoteGames, uploadBatchGames } from "./services/library-sync"; startMainLoop(); @@ -24,6 +24,7 @@ const loadState = async (userPreferences: UserPreferences | null) => { HydraApi.setupApi().then(async () => { if (HydraApi.isLoggedIn()) { + await uploadBatchGames(); getRemoteGames(); } }); From ab4cf23f97dd729a4ca62e1f4de474c7d02c431e Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 18 Jun 2024 21:53:20 -0300 Subject: [PATCH 3/4] post to /games on startGameDownload --- src/main/events/torrenting/start-game-download.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/events/torrenting/start-game-download.ts b/src/main/events/torrenting/start-game-download.ts index e2115349..0aa01fc9 100644 --- a/src/main/events/torrenting/start-game-download.ts +++ b/src/main/events/torrenting/start-game-download.ts @@ -12,6 +12,7 @@ import { DownloadManager } from "@main/services"; import { Not } from "typeorm"; import { steamGamesWorker } from "@main/workers"; +import { createGame } from "@main/services/library-sync"; const startGameDownload = async ( _event: Electron.IpcMainInvokeEvent, @@ -94,6 +95,19 @@ const startGameDownload = async ( }, }); + createGame(updatedGame!).then((response) => { + const { + id: remoteId, + playTimeInMilliseconds, + lastTimePlayed, + } = response.data; + + gameRepository.update( + { objectID }, + { remoteId, playTimeInMilliseconds, lastTimePlayed } + ); + }); + await downloadQueueRepository.delete({ game: { id: updatedGame!.id } }); await downloadQueueRepository.insert({ game: { id: updatedGame!.id } }); From b07451e91d40a1303481b19bb5c438e8f8bf81b1 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 18 Jun 2024 21:58:11 -0300 Subject: [PATCH 4/4] refactor removeGameFromLibrary to handle error --- src/main/events/library/remove-game-from-library.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/events/library/remove-game-from-library.ts b/src/main/events/library/remove-game-from-library.ts index 8bbd83e3..5d154aae 100644 --- a/src/main/events/library/remove-game-from-library.ts +++ b/src/main/events/library/remove-game-from-library.ts @@ -1,6 +1,7 @@ import { registerEvent } from "../register-event"; import { gameRepository } from "../../repository"; import { HydraApi } from "@main/services/hydra-api"; +import { logger } from "@main/services"; const removeGameFromLibrary = async ( _event: Electron.IpcMainInvokeEvent, @@ -11,6 +12,12 @@ const removeGameFromLibrary = async ( { isDeleted: true, executablePath: null } ); + removeRemoveGameFromLibrary(gameId).catch((err) => { + logger.error("removeRemoveGameFromLibrary", err); + }); +}; + +const removeRemoveGameFromLibrary = async (gameId: number) => { const game = await gameRepository.findOne({ where: { id: gameId } }); if (game?.remoteId) {