mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: use power toast
This commit is contained in:
parent
0a86ec89aa
commit
9fa9f6d85a
7 changed files with 85 additions and 5 deletions
|
@ -12,6 +12,8 @@ import { UserPreferences } from "./entity";
|
|||
import { RealDebridClient } from "./services/real-debrid";
|
||||
import { HydraApi } from "./services/hydra-api";
|
||||
import { uploadGamesBatch } from "./services/library-sync";
|
||||
import { Toast } from "powertoast";
|
||||
import { publishNewAchievementNotification } from "./services/notifications";
|
||||
|
||||
const loadState = async (userPreferences: UserPreferences | null) => {
|
||||
import("./events");
|
||||
|
@ -49,5 +51,10 @@ userPreferencesRepository
|
|||
where: { id: 1 },
|
||||
})
|
||||
.then((userPreferences) => {
|
||||
publishNewAchievementNotification({
|
||||
icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/72850/c3a604f698d247b53d20f212e9f31a9ec707a180.jpg",
|
||||
displayName: "Hydra has started",
|
||||
});
|
||||
|
||||
loadState(userPreferences);
|
||||
});
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import { Notification, nativeImage } from "electron";
|
||||
import { Notification, app, nativeImage } from "electron";
|
||||
import { t } from "i18next";
|
||||
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 fs from "node:fs";
|
||||
import axios from "axios";
|
||||
import path from "node:path";
|
||||
|
||||
const getGameIconNativeImage = async (gameId: number) => {
|
||||
try {
|
||||
|
@ -65,3 +69,42 @@ export const publishNotificationUpdateReadyToInstall = async (
|
|||
};
|
||||
|
||||
export const publishNewFriendRequestNotification = async () => {};
|
||||
|
||||
async function downloadImage(url: string) {
|
||||
const fileName = url.split("/").pop()!;
|
||||
const outputPath = path.join(app.getPath("temp"), fileName);
|
||||
const writer = fs.createWriteStream(outputPath);
|
||||
|
||||
const response = await axios.get(url, {
|
||||
responseType: "stream",
|
||||
});
|
||||
|
||||
response.data.pipe(writer);
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
writer.on("finish", () => {
|
||||
resolve(outputPath);
|
||||
});
|
||||
writer.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
export const publishNewAchievementNotification = async (achievement: {
|
||||
displayName: string;
|
||||
icon: string;
|
||||
}) => {
|
||||
const iconPath = await downloadImage(achievement.icon);
|
||||
|
||||
new Toast({
|
||||
aumid: "gg.hydralauncher.hydra",
|
||||
title: "New achievement unlocked",
|
||||
message: achievement.displayName,
|
||||
icon: iconPath,
|
||||
sound: true,
|
||||
audio: "ms-appx:///resources/achievement.wav",
|
||||
progress: {
|
||||
value: 30,
|
||||
valueOverride: "30/100 achievements",
|
||||
},
|
||||
}).show();
|
||||
};
|
||||
|
|
|
@ -94,8 +94,6 @@ export interface UserGame {
|
|||
cover: string;
|
||||
playTimeInSeconds: number;
|
||||
lastTimePlayed: Date | null;
|
||||
unlockedAchievementCount: number;
|
||||
achievementCount: number;
|
||||
}
|
||||
|
||||
export interface DownloadQueue {
|
||||
|
@ -258,7 +256,10 @@ export interface UserProfile {
|
|||
profileImageUrl: string | null;
|
||||
backgroundImageUrl: string | null;
|
||||
profileVisibility: ProfileVisibility;
|
||||
libraryGames: UserGame[];
|
||||
libraryGames: (UserGame & {
|
||||
unlockedAchievementCount: number;
|
||||
achievementCount: number;
|
||||
})[];
|
||||
recentGames: UserGame[];
|
||||
friends: UserFriend[];
|
||||
totalFriends: number;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue