From 4f4dd29e5f002ead6f020ca0db134ec348a3a68f Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:57:46 -0300 Subject: [PATCH] feat: refactor --- src/locales/en/translation.json | 3 +- src/locales/pt-BR/translation.json | 3 +- src/main/main.ts | 12 +++++-- .../achievements/merge-achievements.ts | 21 ++++------- src/main/services/notifications/index.ts | 36 ++++++++++++------- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 0adb47e5..755b1408 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -363,7 +363,8 @@ "unlocked_at": "Unlocked at:", "subscription_needed": "A Hydra Cloud subscription is required to see this content", "new_achievements_unlocked": "Unlocked {{achievementCount}} new achievements from {{gameCount}} games", - "achievement_progress": "{{unlockedCount}}/{{totalCount}} achievements" + "achievement_progress": "{{unlockedCount}}/{{totalCount}} achievements", + "achievements_unlocked_for_game": "Unlocked {{achievementCount}} new achievements for {{gameTitle}}" }, "tour": { "subscription_tour_title": "Hydra Cloud Subscription", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 717f9acb..41e60338 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -361,7 +361,8 @@ "unlocked_at": "Desbloqueado em:", "subscription_needed": "Você precisa de uma assinatura Hydra Cloud para visualizar este conteúdo", "new_achievements_unlocked": "{{achievementCount}} novas conquistas de {{gameCount}} jogos", - "achievement_progress": "{{unlockedCount}}/{{totalCount}} conquistas" + "achievement_progress": "{{unlockedCount}}/{{totalCount}} conquistas", + "achievements_unlocked_for_game": "Desbloqueadas {{achievementCount}} novas conquistas em {{gameTitle}}" }, "tour": { "subscription_tour_title": "Assinatura Hydra Cloud", diff --git a/src/main/main.ts b/src/main/main.ts index f108feb7..abf3072f 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -56,11 +56,17 @@ userPreferencesRepository publishCombinedNewAchievementNotification(1000, 999); publishNewAchievementNotification({ - displayName: "Teste 1", - achievementIcon: - "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/105600/0fbb33098c9da39d1d4771d8209afface9c46e81.jpg", + achievements: [ + { + displayName: "Teste 1", + iconUrl: + "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/105600/0fbb33098c9da39d1d4771d8209afface9c46e81.jpg", + }, + ], unlockedAchievementCount: 10, totalAchievementCount: 34, + gameTitle: "Teste", + gameIcon: null, }); loadState(userPreferences); diff --git a/src/main/services/achievements/merge-achievements.ts b/src/main/services/achievements/merge-achievements.ts index 196574d9..2b3b21d5 100644 --- a/src/main/services/achievements/merge-achievements.ts +++ b/src/main/services/achievements/merge-achievements.ts @@ -113,20 +113,13 @@ export const mergeAchievements = async ( }; }); - if (achievementsInfo.length > 1) { - publishCombinedNewAchievementNotification( - newAchievements.length, - 1, - achievementsInfo[0].iconUrl - ); - } else { - publishNewAchievementNotification({ - displayName: achievementsInfo[0].displayName, - achievementIcon: achievementsInfo[0].iconUrl, - unlockedAchievementCount: mergedLocalAchievements.length, - totalAchievementCount: achievementsData.length, - }); - } + publishNewAchievementNotification({ + achievements: achievementsInfo, + unlockedAchievementCount: mergedLocalAchievements.length, + totalAchievementCount: achievementsData.length, + gameTitle: game.title, + gameIcon: game.iconUrl, + }); } if (game.remoteId) { diff --git a/src/main/services/notifications/index.ts b/src/main/services/notifications/index.ts index 4d6fe302..4f598868 100644 --- a/src/main/services/notifications/index.ts +++ b/src/main/services/notifications/index.ts @@ -120,27 +120,39 @@ export const publishCombinedNewAchievementNotification = async ( sound.play(achievementSoundPath); }; -export const publishNewAchievementNotification = async (achievement: { - displayName: string; - achievementIcon: string; +export const publishNewAchievementNotification = async (info: { + achievements: { displayName: string; iconUrl: string }[]; unlockedAchievementCount: number; totalAchievementCount: number; + gameTitle: string; + gameIcon: string | null; }) => { - const iconPath = await downloadImage(achievement.achievementIcon); + const partialOptions = + info.achievements.length > 1 + ? { + title: t("achievements_unlocked_for_game", { + ns: "achievement", + gameTitle: info.gameTitle, + achievementCount: info.achievements.length, + }), + body: info.achievements.map((a) => a.displayName).join(", "), + icon: info.gameIcon ? await downloadImage(info.gameIcon) : icon, + } + : { + title: t("achievement_unlocked", { ns: "achievement" }), + body: info.achievements[0].displayName, + icon: await downloadImage(info.achievements[0].iconUrl), + }; const options: NotificationOptions = { - title: t("achievement_unlocked", { ns: "achievement" }), - body: achievement.displayName, - icon: iconPath, + ...partialOptions, silent: true, progress: { - value: - achievement.unlockedAchievementCount / - achievement.totalAchievementCount, + value: info.unlockedAchievementCount / info.totalAchievementCount, valueOverride: t("achievement_progress", { ns: "achievement", - unlockedCount: achievement.unlockedAchievementCount, - totalCount: achievement.totalAchievementCount, + unlockedCount: info.unlockedAchievementCount, + totalCount: info.totalAchievementCount, }), }, };