mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: fix notification icons
This commit is contained in:
parent
780ab5f909
commit
08fbd4c8d8
@ -8,6 +8,7 @@ import { getFileBase64 } from "@main/helpers";
|
||||
import { steamGamesWorker } from "@main/workers";
|
||||
import { createGame } from "@main/services/library-sync";
|
||||
import { steamUrlBuilder } from "@shared";
|
||||
import { saveAllLocalSteamAchivements } from "@main/services/achievements/save-all-local-steam-achivements";
|
||||
|
||||
const addGameToLibrary = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
@ -52,6 +53,10 @@ const addGameToLibrary = async (
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: search for achievements only from this game
|
||||
console.log("Searching for achievements", title);
|
||||
saveAllLocalSteamAchivements();
|
||||
|
||||
const game = await gameRepository.findOne({ where: { objectID } });
|
||||
|
||||
createGame(game!).catch(() => {});
|
||||
|
@ -17,7 +17,7 @@ export const saveAllLocalSteamAchivements = async () => {
|
||||
|
||||
const gameAchievementFiles = findSteamGameAchievementFiles();
|
||||
|
||||
for (const objectId of Object.keys(gameAchievementFiles)) {
|
||||
for (const objectId of gameAchievementFiles.keys()) {
|
||||
const [game, localAchievements] = await Promise.all([
|
||||
gameRepository.findOne({
|
||||
where: { objectID: objectId, shop: "steam", isDeleted: false },
|
||||
@ -29,6 +29,12 @@ export const saveAllLocalSteamAchivements = async () => {
|
||||
|
||||
if (!game) continue;
|
||||
|
||||
console.log(
|
||||
"Achievements files for",
|
||||
game.title,
|
||||
gameAchievementFiles.get(objectId)
|
||||
);
|
||||
|
||||
if (!localAchievements || !localAchievements.achievements) {
|
||||
await HydraApi.get(
|
||||
"/games/achievements",
|
||||
@ -54,7 +60,7 @@ export const saveAllLocalSteamAchivements = async () => {
|
||||
|
||||
const unlockedAchievements: UnlockedAchievement[] = [];
|
||||
|
||||
for (const achievementFile of gameAchievementFiles[objectId]) {
|
||||
for (const achievementFile of gameAchievementFiles.get(objectId)!) {
|
||||
const localAchievementFile = await parseAchievementFile(
|
||||
achievementFile.filePath
|
||||
);
|
||||
|
@ -85,17 +85,28 @@ export const publishNotificationUpdateReadyToInstall = async (
|
||||
}).show();
|
||||
};
|
||||
|
||||
const downloadImage = async (url: string, iconPath: string) => {
|
||||
const response = await axios.get(url, { responseType: "stream" });
|
||||
const writer = fs.createWriteStream(iconPath);
|
||||
response.data.pipe(writer);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on("finish", resolve);
|
||||
writer.on("error", reject);
|
||||
});
|
||||
};
|
||||
|
||||
export const publishNewAchievementNotification = async (
|
||||
game: string,
|
||||
name: string,
|
||||
icon: string
|
||||
iconUrl: string
|
||||
) => {
|
||||
const iconName = icon.split("/").pop() || "icon.png";
|
||||
await axios.get(icon, { responseType: "stream" }).then((response) => {
|
||||
return response.data.pipe(
|
||||
fs.createWriteStream(path.join(app.getPath("temp"), iconName))
|
||||
);
|
||||
});
|
||||
const iconPath = path.join(
|
||||
app.getPath("temp"),
|
||||
iconUrl.split("/").pop() || "image.jpg"
|
||||
);
|
||||
|
||||
await downloadImage(iconUrl, iconPath);
|
||||
|
||||
new Notification({
|
||||
title: t("game_achievement_unlocked", {
|
||||
@ -103,7 +114,7 @@ export const publishNewAchievementNotification = async (
|
||||
game,
|
||||
}),
|
||||
body: name,
|
||||
icon: path.join(app.getPath("temp"), iconName),
|
||||
icon: iconPath,
|
||||
}).show();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user