diff --git a/src/main/events/library/add-game-to-library.ts b/src/main/events/library/add-game-to-library.ts index 2eba4a71..13a7e5e0 100644 --- a/src/main/events/library/add-game-to-library.ts +++ b/src/main/events/library/add-game-to-library.ts @@ -54,7 +54,7 @@ const addGameToLibrary = async ( const game = await gameRepository.findOne({ where: { objectID } }); - createGame(game!); + createGame(game!).catch(() => {}); }); }; diff --git a/src/main/events/torrenting/start-game-download.ts b/src/main/events/torrenting/start-game-download.ts index ada05a09..90350f4a 100644 --- a/src/main/events/torrenting/start-game-download.ts +++ b/src/main/events/torrenting/start-game-download.ts @@ -97,7 +97,7 @@ const startGameDownload = async ( }, }); - createGame(updatedGame!); + createGame(updatedGame!).catch(() => {}); await downloadQueueRepository.delete({ game: { id: updatedGame!.id } }); await downloadQueueRepository.insert({ game: { id: updatedGame!.id } }); diff --git a/src/main/services/library-sync/create-game.ts b/src/main/services/library-sync/create-game.ts index 0b991bed..396ddbdd 100644 --- a/src/main/services/library-sync/create-game.ts +++ b/src/main/services/library-sync/create-game.ts @@ -15,19 +15,17 @@ export const createGame = async (game: Game) => { logger.error("Failed to create game download", err); }); - HydraApi.post(`/profile/games`, { + return HydraApi.post(`/profile/games`, { objectId: game.objectID, playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds), shop: game.shop, lastTimePlayed: game.lastTimePlayed, - }) - .then((response) => { - const { id: remoteId, playTimeInMilliseconds, lastTimePlayed } = response; + }).then((response) => { + const { id: remoteId, playTimeInMilliseconds, lastTimePlayed } = response; - gameRepository.update( - { objectID: game.objectID }, - { remoteId, playTimeInMilliseconds, lastTimePlayed } - ); - }) - .catch(() => {}); + gameRepository.update( + { objectID: game.objectID }, + { remoteId, playTimeInMilliseconds, lastTimePlayed } + ); + }); }; diff --git a/src/main/services/library-sync/update-game-playtime.ts b/src/main/services/library-sync/update-game-playtime.ts index 5cfc4103..28c3bed3 100644 --- a/src/main/services/library-sync/update-game-playtime.ts +++ b/src/main/services/library-sync/update-game-playtime.ts @@ -6,8 +6,8 @@ export const updateGamePlaytime = async ( deltaInMillis: number, lastTimePlayed: Date ) => { - HydraApi.put(`/profile/games/${game.remoteId}`, { + return HydraApi.put(`/profile/games/${game.remoteId}`, { playTimeDeltaInSeconds: Math.trunc(deltaInMillis / 1000), lastTimePlayed, - }).catch(() => {}); + }); }; diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 080f1efc..64b14f4d 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -70,9 +70,9 @@ function onOpenGame(game: Game) { }); if (game.remoteId) { - updateGamePlaytime(game, 0, new Date()); + updateGamePlaytime(game, 0, new Date()).catch(() => {}); } else { - createGame({ ...game, lastTimePlayed: new Date() }); + createGame({ ...game, lastTimePlayed: new Date() }).catch(() => {}); } } @@ -93,20 +93,22 @@ function onTickGame(game: Game) { }); if (currentTick % TICKS_TO_UPDATE_API === 0) { - if (game.remoteId) { - updateGamePlaytime( - game, - now - gamePlaytime.lastSyncTick, - game.lastTimePlayed! - ); - } else { - createGame(game); - } + const gamePromise = game.remoteId + ? updateGamePlaytime( + game, + now - gamePlaytime.lastSyncTick, + game.lastTimePlayed! + ) + : createGame(game); - gamesPlaytime.set(game.id, { - ...gamePlaytime, - lastSyncTick: now, - }); + gamePromise + .then(() => { + gamesPlaytime.set(game.id, { + ...gamePlaytime, + lastSyncTick: now, + }); + }) + .catch(() => {}); } } @@ -119,8 +121,8 @@ const onCloseGame = (game: Game) => { game, performance.now() - gamePlaytime.firstTick, game.lastTimePlayed! - ); + ).catch(() => {}); } else { - createGame(game); + createGame(game).catch(() => {}); } };