From a45e06efa3ba0e3e02f65502517a9c52b311a4f5 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 29 Oct 2024 23:10:30 -0300 Subject: [PATCH] feat: use electron native notification with xml --- electron-builder.yml | 1 + src/main/constants.ts | 4 ++++ src/main/main.ts | 2 ++ src/main/services/notifications.ts | 32 +++++++++++++++++++----------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/electron-builder.yml b/electron-builder.yml index a7151ed3..8d31d913 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -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/*" diff --git a/src/main/constants.ts b/src/main/constants.ts index fd5c279a..9ab63f93 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -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(); diff --git a/src/main/main.ts b/src/main/main.ts index ae96ca37..2d38ae5c 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -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); diff --git a/src/main/services/notifications.ts b/src/main/services/notifications.ts index 3ff53ca0..d5ecc756 100644 --- a/src/main/services/notifications.ts +++ b/src/main/services/notifications.ts @@ -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); };