diff --git a/src/main/events/library/add-game-to-favorites.ts b/src/main/events/library/add-game-to-favorites.ts index 8371b366..68c81abb 100644 --- a/src/main/events/library/add-game-to-favorites.ts +++ b/src/main/events/library/add-game-to-favorites.ts @@ -1,5 +1,6 @@ import { registerEvent } from "../register-event"; import { gamesSublevel, levelKeys } from "@main/level"; +import { HydraApi } from "@main/services"; import type { GameShop } from "@types"; const addGameToFavorites = async ( @@ -12,6 +13,8 @@ const addGameToFavorites = async ( const game = await gamesSublevel.get(gameKey); if (!game) return; + HydraApi.put(`/profile/games/${shop}/${objectId}/favorite`).catch(() => {}); + try { await gamesSublevel.put(gameKey, { ...game, diff --git a/src/main/events/library/remove-game-from-favorites.ts b/src/main/events/library/remove-game-from-favorites.ts index c802ab0b..f06f55ce 100644 --- a/src/main/events/library/remove-game-from-favorites.ts +++ b/src/main/events/library/remove-game-from-favorites.ts @@ -1,5 +1,6 @@ import { registerEvent } from "../register-event"; import { gamesSublevel, levelKeys } from "@main/level"; +import { HydraApi } from "@main/services"; import type { GameShop } from "@types"; const removeGameFromFavorites = async ( @@ -12,6 +13,8 @@ const removeGameFromFavorites = async ( const game = await gamesSublevel.get(gameKey); if (!game) return; + HydraApi.put(`/profile/games/${shop}/${objectId}/unfavorite`).catch(() => {}); + try { await gamesSublevel.put(gameKey, { ...game, diff --git a/src/main/events/library/sync-game-by-object-id.ts b/src/main/events/library/sync-game-by-object-id.ts index 6235a09c..960a51d7 100644 --- a/src/main/events/library/sync-game-by-object-id.ts +++ b/src/main/events/library/sync-game-by-object-id.ts @@ -11,14 +11,17 @@ const syncGameByObjectId = async ( return HydraApi.get( `/profile/games/${shop}/${objectId}` ).then(async (res) => { - const { id, playTimeInSeconds, ...rest } = res; + const { id, playTimeInSeconds, isFavorite, ...rest } = res; const gameKey = levelKeys.game(shop, objectId); + const currentData = await gamesSublevel.get(gameKey); + await gamesSublevel.put(gameKey, { ...rest, remoteId: id, playTimeInMilliseconds: playTimeInSeconds * 1000, + favorite: isFavorite ?? currentData?.favorite, }); return res; diff --git a/src/main/services/library-sync/merge-with-remote-games.ts b/src/main/services/library-sync/merge-with-remote-games.ts index ff052506..74ef9c77 100644 --- a/src/main/services/library-sync/merge-with-remote-games.ts +++ b/src/main/services/library-sync/merge-with-remote-games.ts @@ -6,6 +6,7 @@ type ProfileGame = { id: string; lastTimePlayed: Date | null; playTimeInMilliseconds: number; + isFavorite?: boolean; } & ShopAssets; export const mergeWithRemoteGames = async () => { @@ -34,6 +35,7 @@ export const mergeWithRemoteGames = async () => { remoteId: game.id, lastTimePlayed: updatedLastTimePlayed, playTimeInMilliseconds: updatedPlayTime, + favorite: game.isFavorite ?? localGame.favorite, }); } else { await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), { @@ -45,6 +47,7 @@ export const mergeWithRemoteGames = async () => { lastTimePlayed: game.lastTimePlayed, playTimeInMilliseconds: game.playTimeInMilliseconds, isDeleted: false, + favorite: game.isFavorite ?? false, }); } diff --git a/src/main/services/library-sync/upload-games-batch.ts b/src/main/services/library-sync/upload-games-batch.ts index 4294e389..984521db 100644 --- a/src/main/services/library-sync/upload-games-batch.ts +++ b/src/main/services/library-sync/upload-games-batch.ts @@ -26,6 +26,7 @@ export const uploadGamesBatch = async () => { playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds), shop: game.shop, lastTimePlayed: game.lastTimePlayed, + isFavorite: game.favorite, }; }) ).catch(() => {});