feat: use electron native notification with xml

This commit is contained in:
Zamitto 2024-10-29 23:10:30 -03:00
parent e7292eb75e
commit a45e06efa3
4 changed files with 27 additions and 12 deletions

View File

@ -7,6 +7,7 @@ extraResources:
- hydra-download-manager
- seeds
- from: node_modules/create-desktop-shortcuts/src/windows.vbs
- from: resources/achievement.wav
files:
- "!**/.vscode/*"
- "!src/*"

View File

@ -19,6 +19,10 @@ export const seedsPath = app.isPackaged
? path.join(process.resourcesPath, "seeds")
: path.join(__dirname, "..", "..", "seeds");
export const achievementSoundPath = app.isPackaged
? path.join(process.resourcesPath, "resources", "achievement.wav")
: path.join(__dirname, "..", "..", "resources", "achievement.wav");
export const backupsPath = path.join(app.getPath("userData"), "Backups");
export const appVersion = app.getVersion();

View File

@ -54,6 +54,8 @@ userPreferencesRepository
publishNewAchievementNotification({
icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/72850/c3a604f698d247b53d20f212e9f31a9ec707a180.jpg",
displayName: "Hydra has started",
totalAchievementCount: 75,
unlockedAchievementCount: 23,
});
loadState(userPreferences);

View File

@ -4,11 +4,12 @@ import { parseICO } from "icojs";
import trayIcon from "@resources/tray-icon.png?asset";
import { Game } from "@main/entity";
import { gameRepository, userPreferencesRepository } from "@main/repository";
import { Toast } from "powertoast";
import { toXmlString } from "powertoast";
import fs from "node:fs";
import axios from "axios";
import path from "node:path";
import sound from "sound-play";
import { achievementSoundPath } from "@main/constants";
const getGameIconNativeImage = async (gameId: number) => {
try {
@ -93,23 +94,30 @@ async function downloadImage(url: string) {
export const publishNewAchievementNotification = async (achievement: {
displayName: string;
icon: string;
unlockedAchievementCount: number;
totalAchievementCount: number;
}) => {
const iconPath = await downloadImage(achievement.icon);
new Toast({
aumid: "gg.hydralauncher.hydra",
new Notification({
title: "New achievement unlocked",
message: achievement.displayName,
body: achievement.displayName,
icon: iconPath,
silent: true,
progress: {
value: 30,
valueOverride: "30/100 achievements",
},
toastXml: toXmlString({
title: "New achievement unlocked",
message: achievement.displayName,
icon: iconPath,
silent: true,
progress: {
value: Math.round(
(achievement.unlockedAchievementCount * 100) /
achievement.totalAchievementCount
),
valueOverride: `${achievement.unlockedAchievementCount}/${achievement.totalAchievementCount} achievements`,
},
}),
}).show();
const audioPath = path.join(app.getAppPath(), "resources", "achievement.wav");
console.log(audioPath);
sound.play(audioPath);
sound.play(achievementSoundPath);
};