feat: combined notification when add game to library

This commit is contained in:
Zamitto
2025-06-03 16:04:29 -03:00
parent 8e6f9fdb00
commit 0c379d6c49
2 changed files with 46 additions and 29 deletions

View File

@@ -192,7 +192,15 @@ export class AchievementWatcherManager {
this.alreadySyncedGames.set(gameKey, true);
return mergeAchievements(game, unlockedAchievements, false);
const newAchievements = await mergeAchievements(
game,
unlockedAchievements,
false
);
if (newAchievements > 0) {
this.notifyCombinedAchievementsUnlocked(1, newAchievements);
}
}
public static watchAchievements() {
@@ -288,6 +296,32 @@ export class AchievementWatcherManager {
);
}
private static async notifyCombinedAchievementsUnlocked(
totalNewGamesWithAchievements: number,
totalNewAchievements: number
) {
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,
{
valueEncoding: "json",
}
);
if (userPreferences.achievementCustomNotificationsEnabled !== false) {
WindowManager.notificationWindow?.webContents.send(
"on-combined-achievements-unlocked",
totalNewGamesWithAchievements,
totalNewAchievements,
userPreferences.achievementCustomNotificationPosition ?? "top-left"
);
} else {
publishCombinedNewAchievementNotification(
totalNewAchievements,
totalNewGamesWithAchievements
);
}
}
public static async preSearchAchievements() {
try {
const gameAchievementFiles =
@@ -311,31 +345,11 @@ export class AchievementWatcherManager {
);
if (totalNewAchievements > 0) {
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,
{
valueEncoding: "json",
}
await setTimeout(4000);
this.notifyCombinedAchievementsUnlocked(
totalNewGamesWithAchievements,
totalNewAchievements
);
if (userPreferences.achievementNotificationsEnabled !== false) {
await setTimeout(4000);
if (userPreferences.achievementCustomNotificationsEnabled !== false) {
WindowManager.notificationWindow?.webContents.send(
"on-combined-achievements-unlocked",
totalNewGamesWithAchievements,
totalNewAchievements,
userPreferences.achievementCustomNotificationPosition ??
"top-left"
);
} else {
publishCombinedNewAchievementNotification(
totalNewAchievements,
totalNewGamesWithAchievements
);
}
}
}
} catch (err) {
achievementsLogger.error("Error on preSearchAchievements", err);

View File

@@ -183,10 +183,13 @@ export function GameDetailsContextProvider({
.catch(() => {});
}
window.electron.syncGameByObjectId(shop, objectId).then(() => {
if (abortController.signal.aborted) return;
updateGame();
});
window.electron
.syncGameByObjectId(shop, objectId)
.then(() => {
if (abortController.signal.aborted) return;
updateGame();
})
.catch(() => {});
}, [
updateGame,
dispatch,