feat: refactor

This commit is contained in:
Zamitto 2024-10-31 16:57:46 -03:00
parent 9189541c3a
commit 4f4dd29e5f
5 changed files with 44 additions and 31 deletions

View File

@ -363,7 +363,8 @@
"unlocked_at": "Unlocked at:", "unlocked_at": "Unlocked at:",
"subscription_needed": "A Hydra Cloud subscription is required to see this content", "subscription_needed": "A Hydra Cloud subscription is required to see this content",
"new_achievements_unlocked": "Unlocked {{achievementCount}} new achievements from {{gameCount}} games", "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": { "tour": {
"subscription_tour_title": "Hydra Cloud Subscription", "subscription_tour_title": "Hydra Cloud Subscription",

View File

@ -361,7 +361,8 @@
"unlocked_at": "Desbloqueado em:", "unlocked_at": "Desbloqueado em:",
"subscription_needed": "Você precisa de uma assinatura Hydra Cloud para visualizar este conteúdo", "subscription_needed": "Você precisa de uma assinatura Hydra Cloud para visualizar este conteúdo",
"new_achievements_unlocked": "{{achievementCount}} novas conquistas de {{gameCount}} jogos", "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": { "tour": {
"subscription_tour_title": "Assinatura Hydra Cloud", "subscription_tour_title": "Assinatura Hydra Cloud",

View File

@ -56,11 +56,17 @@ userPreferencesRepository
publishCombinedNewAchievementNotification(1000, 999); publishCombinedNewAchievementNotification(1000, 999);
publishNewAchievementNotification({ publishNewAchievementNotification({
displayName: "Teste 1", achievements: [
achievementIcon: {
"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/105600/0fbb33098c9da39d1d4771d8209afface9c46e81.jpg", displayName: "Teste 1",
iconUrl:
"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/105600/0fbb33098c9da39d1d4771d8209afface9c46e81.jpg",
},
],
unlockedAchievementCount: 10, unlockedAchievementCount: 10,
totalAchievementCount: 34, totalAchievementCount: 34,
gameTitle: "Teste",
gameIcon: null,
}); });
loadState(userPreferences); loadState(userPreferences);

View File

@ -113,20 +113,13 @@ export const mergeAchievements = async (
}; };
}); });
if (achievementsInfo.length > 1) { publishNewAchievementNotification({
publishCombinedNewAchievementNotification( achievements: achievementsInfo,
newAchievements.length, unlockedAchievementCount: mergedLocalAchievements.length,
1, totalAchievementCount: achievementsData.length,
achievementsInfo[0].iconUrl gameTitle: game.title,
); gameIcon: game.iconUrl,
} else { });
publishNewAchievementNotification({
displayName: achievementsInfo[0].displayName,
achievementIcon: achievementsInfo[0].iconUrl,
unlockedAchievementCount: mergedLocalAchievements.length,
totalAchievementCount: achievementsData.length,
});
}
} }
if (game.remoteId) { if (game.remoteId) {

View File

@ -120,27 +120,39 @@ export const publishCombinedNewAchievementNotification = async (
sound.play(achievementSoundPath); sound.play(achievementSoundPath);
}; };
export const publishNewAchievementNotification = async (achievement: { export const publishNewAchievementNotification = async (info: {
displayName: string; achievements: { displayName: string; iconUrl: string }[];
achievementIcon: string;
unlockedAchievementCount: number; unlockedAchievementCount: number;
totalAchievementCount: 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 = { const options: NotificationOptions = {
title: t("achievement_unlocked", { ns: "achievement" }), ...partialOptions,
body: achievement.displayName,
icon: iconPath,
silent: true, silent: true,
progress: { progress: {
value: value: info.unlockedAchievementCount / info.totalAchievementCount,
achievement.unlockedAchievementCount /
achievement.totalAchievementCount,
valueOverride: t("achievement_progress", { valueOverride: t("achievement_progress", {
ns: "achievement", ns: "achievement",
unlockedCount: achievement.unlockedAchievementCount, unlockedCount: info.unlockedAchievementCount,
totalCount: achievement.totalAchievementCount, totalCount: info.totalAchievementCount,
}), }),
}, },
}; };