mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: use electron native notification with xml
This commit is contained in:
parent
e7292eb75e
commit
a45e06efa3
@ -7,6 +7,7 @@ extraResources:
|
|||||||
- hydra-download-manager
|
- hydra-download-manager
|
||||||
- seeds
|
- seeds
|
||||||
- from: node_modules/create-desktop-shortcuts/src/windows.vbs
|
- from: node_modules/create-desktop-shortcuts/src/windows.vbs
|
||||||
|
- from: resources/achievement.wav
|
||||||
files:
|
files:
|
||||||
- "!**/.vscode/*"
|
- "!**/.vscode/*"
|
||||||
- "!src/*"
|
- "!src/*"
|
||||||
|
@ -19,6 +19,10 @@ export const seedsPath = app.isPackaged
|
|||||||
? path.join(process.resourcesPath, "seeds")
|
? path.join(process.resourcesPath, "seeds")
|
||||||
: path.join(__dirname, "..", "..", "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 backupsPath = path.join(app.getPath("userData"), "Backups");
|
||||||
|
|
||||||
export const appVersion = app.getVersion();
|
export const appVersion = app.getVersion();
|
||||||
|
@ -54,6 +54,8 @@ userPreferencesRepository
|
|||||||
publishNewAchievementNotification({
|
publishNewAchievementNotification({
|
||||||
icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/72850/c3a604f698d247b53d20f212e9f31a9ec707a180.jpg",
|
icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/72850/c3a604f698d247b53d20f212e9f31a9ec707a180.jpg",
|
||||||
displayName: "Hydra has started",
|
displayName: "Hydra has started",
|
||||||
|
totalAchievementCount: 75,
|
||||||
|
unlockedAchievementCount: 23,
|
||||||
});
|
});
|
||||||
|
|
||||||
loadState(userPreferences);
|
loadState(userPreferences);
|
||||||
|
@ -4,11 +4,12 @@ import { parseICO } from "icojs";
|
|||||||
import trayIcon from "@resources/tray-icon.png?asset";
|
import trayIcon from "@resources/tray-icon.png?asset";
|
||||||
import { Game } from "@main/entity";
|
import { Game } from "@main/entity";
|
||||||
import { gameRepository, userPreferencesRepository } from "@main/repository";
|
import { gameRepository, userPreferencesRepository } from "@main/repository";
|
||||||
import { Toast } from "powertoast";
|
import { toXmlString } from "powertoast";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import sound from "sound-play";
|
import sound from "sound-play";
|
||||||
|
import { achievementSoundPath } from "@main/constants";
|
||||||
|
|
||||||
const getGameIconNativeImage = async (gameId: number) => {
|
const getGameIconNativeImage = async (gameId: number) => {
|
||||||
try {
|
try {
|
||||||
@ -93,23 +94,30 @@ async function downloadImage(url: string) {
|
|||||||
export const publishNewAchievementNotification = async (achievement: {
|
export const publishNewAchievementNotification = async (achievement: {
|
||||||
displayName: string;
|
displayName: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
|
unlockedAchievementCount: number;
|
||||||
|
totalAchievementCount: number;
|
||||||
}) => {
|
}) => {
|
||||||
const iconPath = await downloadImage(achievement.icon);
|
const iconPath = await downloadImage(achievement.icon);
|
||||||
|
|
||||||
new Toast({
|
new Notification({
|
||||||
aumid: "gg.hydralauncher.hydra",
|
title: "New achievement unlocked",
|
||||||
|
body: achievement.displayName,
|
||||||
|
icon: iconPath,
|
||||||
|
silent: true,
|
||||||
|
toastXml: toXmlString({
|
||||||
title: "New achievement unlocked",
|
title: "New achievement unlocked",
|
||||||
message: achievement.displayName,
|
message: achievement.displayName,
|
||||||
icon: iconPath,
|
icon: iconPath,
|
||||||
silent: true,
|
silent: true,
|
||||||
progress: {
|
progress: {
|
||||||
value: 30,
|
value: Math.round(
|
||||||
valueOverride: "30/100 achievements",
|
(achievement.unlockedAchievementCount * 100) /
|
||||||
|
achievement.totalAchievementCount
|
||||||
|
),
|
||||||
|
valueOverride: `${achievement.unlockedAchievementCount}/${achievement.totalAchievementCount} achievements`,
|
||||||
},
|
},
|
||||||
|
}),
|
||||||
}).show();
|
}).show();
|
||||||
|
|
||||||
const audioPath = path.join(app.getAppPath(), "resources", "achievement.wav");
|
sound.play(achievementSoundPath);
|
||||||
|
|
||||||
console.log(audioPath);
|
|
||||||
sound.play(audioPath);
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user