feat: prefer to play achievement sound in browser window if available

This commit is contained in:
Zamitto
2025-01-05 13:31:06 -03:00
parent 39572702a0
commit 6d86002977
7 changed files with 42 additions and 19 deletions

View File

@@ -144,7 +144,7 @@ const processAchievementFileDiff = async (
export class AchievementWatcherManager {
private static hasFinishedMergingWithRemote = false;
public static watchAchievements = () => {
public static watchAchievements() {
if (!this.hasFinishedMergingWithRemote) return;
if (process.platform === "win32") {
@@ -152,12 +152,12 @@ export class AchievementWatcherManager {
}
return watchAchievementsWithWine();
};
}
private static preProcessGameAchievementFiles = (
private static preProcessGameAchievementFiles(
game: Game,
gameAchievementFiles: AchievementFile[]
) => {
) {
const unlockedAchievements: UnlockedAchievement[] = [];
for (const achievementFile of gameAchievementFiles) {
const parsedAchievements = parseAchievementFile(
@@ -185,9 +185,9 @@ export class AchievementWatcherManager {
}
return mergeAchievements(game, unlockedAchievements, false);
};
}
private static preSearchAchievementsWindows = async () => {
private static async preSearchAchievementsWindows() {
const games = await gameRepository.find({
where: {
isDeleted: false,
@@ -213,9 +213,9 @@ export class AchievementWatcherManager {
return this.preProcessGameAchievementFiles(game, gameAchievementFiles);
})
);
};
}
private static preSearchAchievementsWithWine = async () => {
private static async preSearchAchievementsWithWine() {
const games = await gameRepository.find({
where: {
isDeleted: false,
@@ -233,9 +233,9 @@ export class AchievementWatcherManager {
return this.preProcessGameAchievementFiles(game, gameAchievementFiles);
})
);
};
}
public static preSearchAchievements = async () => {
public static async preSearchAchievements() {
try {
const newAchievementsCount =
process.platform === "win32"
@@ -261,5 +261,5 @@ export class AchievementWatcherManager {
}
this.hasFinishedMergingWithRemote = true;
};
}
}

View File

@@ -11,6 +11,7 @@ import { achievementSoundPath } from "@main/constants";
import icon from "@resources/icon.png?asset";
import { NotificationOptions, toXmlString } from "./xml";
import { logger } from "../logger";
import { WindowManager } from "../window-manager";
async function downloadImage(url: string | null) {
if (!url) return undefined;
@@ -93,7 +94,9 @@ export const publishCombinedNewAchievementNotification = async (
toastXml: toXmlString(options),
}).show();
if (process.platform !== "linux") {
if (WindowManager.mainWindow) {
WindowManager.mainWindow.webContents.send("on-achievement-unlocked");
} else if (process.platform !== "linux") {
sound.play(achievementSoundPath);
}
};
@@ -140,7 +143,9 @@ export const publishNewAchievementNotification = async (info: {
toastXml: toXmlString(options),
}).show();
if (process.platform !== "linux") {
if (WindowManager.mainWindow) {
WindowManager.mainWindow.webContents.send("on-achievement-unlocked");
} else if (process.platform !== "linux") {
sound.play(achievementSoundPath);
}
};