feat: achievement notification custom position and animations

This commit is contained in:
Zamitto
2025-05-15 19:42:23 -03:00
parent 42e8a68c08
commit 6f43da8d28
13 changed files with 502 additions and 152 deletions

View File

@@ -7,11 +7,16 @@ import {
findAllAchievementFiles,
getAlternativeObjectIds,
} from "./find-achivement-files";
import type { AchievementFile, Game, UnlockedAchievement } from "@types";
import type {
AchievementFile,
Game,
UnlockedAchievement,
UserPreferences,
} from "@types";
import { achievementsLogger } from "../logger";
import { Cracker } from "@shared";
import { publishCombinedNewAchievementNotification } from "../notifications";
import { gamesSublevel } from "@main/level";
import { db, gamesSublevel, levelKeys } from "@main/level";
import { WindowManager } from "../window-manager";
import { sleep } from "@main/helpers";
@@ -186,7 +191,7 @@ export class AchievementWatcherManager {
return mergeAchievements(game, unlockedAchievements, false);
}
private static preSearchAchievementsWindows = async () => {
private static async getGameAchievementFilesWindows() {
const games = await gamesSublevel
.values()
.all()
@@ -196,24 +201,24 @@ export class AchievementWatcherManager {
return Promise.all(
games.map((game) => {
const gameAchievementFiles: AchievementFile[] = [];
const achievementFiles: AchievementFile[] = [];
for (const objectId of getAlternativeObjectIds(game.objectId)) {
gameAchievementFiles.push(
achievementFiles.push(
...(gameAchievementFilesMap.get(objectId) || [])
);
gameAchievementFiles.push(
achievementFiles.push(
...findAchievementFileInExecutableDirectory(game)
);
}
return this.preProcessGameAchievementFiles(game, gameAchievementFiles);
return { game, achievementFiles };
})
);
};
}
private static preSearchAchievementsWithWine = async () => {
private static async getGameAchievementFilesLinux() {
const games = await gamesSublevel
.values()
.all()
@@ -221,45 +226,70 @@ export class AchievementWatcherManager {
return Promise.all(
games.map((game) => {
const gameAchievementFiles = findAchievementFiles(game);
const achievementFiles = findAchievementFiles(game);
const achievementFileInsideDirectory =
findAchievementFileInExecutableDirectory(game);
gameAchievementFiles.push(...achievementFileInsideDirectory);
achievementFiles.push(...achievementFileInsideDirectory);
return this.preProcessGameAchievementFiles(game, gameAchievementFiles);
return { game, achievementFiles };
})
);
};
}
public static async preSearchAchievements() {
await sleep(5000);
await sleep(2000);
try {
const newAchievementsCount =
const gameAchievementFiles =
process.platform === "win32"
? await this.preSearchAchievementsWindows()
: await this.preSearchAchievementsWithWine();
? 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 totalNewGamesWithAchievements = newAchievementsCount.filter(
(achievements) => achievements
).length;
const totalNewAchievements = newAchievementsCount.reduce(
(acc, val) => acc + val,
0
);
if (totalNewAchievements > 0) {
WindowManager.notificationWindow?.webContents.send(
"on-combined-achievements-unlocked",
totalNewGamesWithAchievements,
totalNewAchievements
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,
{
valueEncoding: "json",
}
);
publishCombinedNewAchievementNotification(
totalNewAchievements,
totalNewGamesWithAchievements
);
if (userPreferences.achievementNotificationsEnabled) {
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

@@ -106,20 +106,23 @@ export const mergeAchievements = async (
};
});
WindowManager.notificationWindow?.webContents.send(
"on-achievement-unlocked",
game.objectId,
game.shop,
achievementsInfo
);
publishNewAchievementNotification({
achievements: achievementsInfo,
unlockedAchievementCount: mergedLocalAchievements.length,
totalAchievementCount: achievementsData.length,
gameTitle: game.title,
gameIcon: game.iconUrl,
});
if (userPreferences?.achievementCustomNotificationsEnabled !== false) {
WindowManager.notificationWindow?.webContents.send(
"on-achievement-unlocked",
game.objectId,
game.shop,
userPreferences.achievementCustomNotificationPosition ?? "top_left",
achievementsInfo
);
} else {
publishNewAchievementNotification({
achievements: achievementsInfo,
unlockedAchievementCount: mergedLocalAchievements.length,
totalAchievementCount: achievementsData.length,
gameTitle: game.title,
gameIcon: game.iconUrl,
});
}
}
if (game.remoteId) {