feat: use promise all on pre search achievement

This commit is contained in:
Zamitto
2025-06-03 15:32:30 -03:00
parent 7d0fbbd960
commit 44db5f9813
2 changed files with 22 additions and 31 deletions

View File

@@ -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",

View File

@@ -13,9 +13,8 @@ export const mergeWithRemoteGames = async () => {
return HydraApi.get<ProfileGame[]>("/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(() => {});