From 44db5f9813c541eb97eb57168d328122d3094980 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 3 Jun 2025 15:32:30 -0300 Subject: [PATCH] feat: use promise all on pre search achievement --- .../achievement-watcher-manager.ts | 19 ++++------- .../library-sync/merge-with-remote-games.ts | 34 ++++++++----------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/main/services/achievements/achievement-watcher-manager.ts b/src/main/services/achievements/achievement-watcher-manager.ts index ca150ad6..6f835a1b 100644 --- a/src/main/services/achievements/achievement-watcher-manager.ts +++ b/src/main/services/achievements/achievement-watcher-manager.ts @@ -289,24 +289,17 @@ export class AchievementWatcherManager { } public static async preSearchAchievements() { - await setTimeout(4000); - try { const gameAchievementFiles = process.platform === "win32" ? await this.getGameAchievementFilesWindows() : await this.getGameAchievementFilesLinux(); - const newAchievementsCount: number[] = []; - - for (const { game, achievementFiles } of gameAchievementFiles) { - const result = await this.preProcessGameAchievementFiles( - game, - achievementFiles - ); - - newAchievementsCount.push(result); - } + const newAchievementsCount = await Promise.all( + gameAchievementFiles.map(({ game, achievementFiles }) => { + return this.preProcessGameAchievementFiles(game, achievementFiles); + }) + ); const totalNewGamesWithAchievements = newAchievementsCount.filter( (achievements) => achievements @@ -326,6 +319,8 @@ export class AchievementWatcherManager { ); if (userPreferences.achievementNotificationsEnabled !== false) { + await setTimeout(4000); + if (userPreferences.achievementCustomNotificationsEnabled !== false) { WindowManager.notificationWindow?.webContents.send( "on-combined-achievements-unlocked", 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 74ef9c77..b9d10f52 100644 --- a/src/main/services/library-sync/merge-with-remote-games.ts +++ b/src/main/services/library-sync/merge-with-remote-games.ts @@ -13,9 +13,8 @@ export const mergeWithRemoteGames = async () => { return HydraApi.get("/profile/games") .then(async (response) => { for (const game of response) { - const localGame = await gamesSublevel.get( - levelKeys.game(game.shop, game.objectId) - ); + const gameKey = levelKeys.game(game.shop, game.objectId); + const localGame = await gamesSublevel.get(gameKey); if (localGame) { const updatedLastTimePlayed = @@ -30,7 +29,7 @@ export const mergeWithRemoteGames = async () => { ? game.playTimeInMilliseconds : localGame.playTimeInMilliseconds; - await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), { + await gamesSublevel.put(gameKey, { ...localGame, remoteId: game.id, lastTimePlayed: updatedLastTimePlayed, @@ -38,7 +37,7 @@ export const mergeWithRemoteGames = async () => { favorite: game.isFavorite ?? localGame.favorite, }); } else { - await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), { + await gamesSublevel.put(gameKey, { objectId: game.objectId, title: game.title, remoteId: game.id, @@ -51,20 +50,17 @@ export const mergeWithRemoteGames = async () => { }); } - await gamesShopAssetsSublevel.put( - levelKeys.game(game.shop, game.objectId), - { - shop: game.shop, - objectId: game.objectId, - title: game.title, - coverImageUrl: game.coverImageUrl, - libraryHeroImageUrl: game.libraryHeroImageUrl, - libraryImageUrl: game.libraryImageUrl, - logoImageUrl: game.logoImageUrl, - iconUrl: game.iconUrl, - logoPosition: game.logoPosition, - } - ); + await gamesShopAssetsSublevel.put(gameKey, { + shop: game.shop, + objectId: game.objectId, + title: game.title, + coverImageUrl: game.coverImageUrl, + libraryHeroImageUrl: game.libraryHeroImageUrl, + libraryImageUrl: game.libraryImageUrl, + logoImageUrl: game.logoImageUrl, + iconUrl: game.iconUrl, + logoPosition: game.logoPosition, + }); } }) .catch(() => {});