feat: i18n and refactor

This commit is contained in:
Zamitto
2025-05-16 05:19:33 -03:00
parent 6f43da8d28
commit 0a4bdf160c
10 changed files with 94 additions and 97 deletions

View File

@@ -1,4 +1,5 @@
import type {
AchievementNotificationInfo,
Game,
GameShop,
UnlockedAchievement,
@@ -86,7 +87,7 @@ export const mergeAchievements = async (
publishNotification &&
userPreferences?.achievementNotificationsEnabled
) {
const achievementsInfo = newAchievements
const achievementsInfo: AchievementNotificationInfo[] = newAchievements
.toSorted((a, b) => {
return a.unlockTime - b.unlockTime;
})
@@ -101,7 +102,12 @@ export const mergeAchievements = async (
.filter((achievement) => Boolean(achievement))
.map((achievement) => {
return {
displayName: achievement!.displayName,
title: achievement!.displayName,
description: achievement!.description,
points: achievement!.points,
isHidden: achievement!.hidden,
isRare: false,
isPlatinum: false,
iconUrl: achievement!.icon,
};
});
@@ -109,8 +115,6 @@ export const mergeAchievements = async (
if (userPreferences?.achievementCustomNotificationsEnabled !== false) {
WindowManager.notificationWindow?.webContents.send(
"on-achievement-unlocked",
game.objectId,
game.shop,
userPreferences.achievementCustomNotificationPosition ?? "top_left",
achievementsInfo
);

View File

@@ -162,7 +162,7 @@ export const publishExtractionCompleteNotification = async (game: Game) => {
};
export const publishNewAchievementNotification = async (info: {
achievements: { displayName: string; iconUrl: string }[];
achievements: { title: string; iconUrl: string }[];
unlockedAchievementCount: number;
totalAchievementCount: number;
gameTitle: string;
@@ -176,12 +176,12 @@ export const publishNewAchievementNotification = async (info: {
gameTitle: info.gameTitle,
achievementCount: info.achievements.length,
}),
body: info.achievements.map((a) => a.displayName).join(", "),
body: info.achievements.map((a) => a.title).join(", "),
icon: (await downloadImage(info.gameIcon)) ?? icon,
}
: {
title: t("achievement_unlocked", { ns: "achievement" }),
body: info.achievements[0].displayName,
body: info.achievements[0].title,
icon: (await downloadImage(info.achievements[0].iconUrl)) ?? icon,
};

View File

@@ -20,6 +20,7 @@ import { db, gamesSublevel, levelKeys } from "@main/level";
import { orderBy, slice } from "lodash-es";
import type {
AchievementCustomNotificationPosition,
AchievementNotificationInfo,
ScreenState,
UserPreferences,
} from "@types";
@@ -371,10 +372,28 @@ export class WindowManager {
}
if (showTestNotification) {
const language = userPreferences.language ?? "en";
setTimeout(() => {
this.notificationWindow?.webContents.send(
"on-test-achievement-notification",
userPreferences.achievementCustomNotificationPosition ?? "top_left"
"on-achievement-unlocked",
userPreferences.achievementCustomNotificationPosition ?? "top_left",
[
{
title: t("test_achievement_notification_title", {
ns: "notifications",
lng: language,
}),
description: t("test_achievement_notification_description", {
ns: "notifications",
lng: language,
}),
iconUrl: "https://cdn.losbroxas.org/favicon.svg",
points: 100,
isHidden: false,
isRare: false,
isPlatinum: false,
},
] as AchievementNotificationInfo[]
);
}, 1000);
}