feat: fix notification icons

This commit is contained in:
Zamitto 2024-09-26 16:09:36 -03:00
parent 780ab5f909
commit 08fbd4c8d8
3 changed files with 32 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import { getFileBase64 } from "@main/helpers";
import { steamGamesWorker } from "@main/workers"; import { steamGamesWorker } from "@main/workers";
import { createGame } from "@main/services/library-sync"; import { createGame } from "@main/services/library-sync";
import { steamUrlBuilder } from "@shared"; import { steamUrlBuilder } from "@shared";
import { saveAllLocalSteamAchivements } from "@main/services/achievements/save-all-local-steam-achivements";
const addGameToLibrary = async ( const addGameToLibrary = async (
_event: Electron.IpcMainInvokeEvent, _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 } }); const game = await gameRepository.findOne({ where: { objectID } });
createGame(game!).catch(() => {}); createGame(game!).catch(() => {});

View File

@ -17,7 +17,7 @@ export const saveAllLocalSteamAchivements = async () => {
const gameAchievementFiles = findSteamGameAchievementFiles(); const gameAchievementFiles = findSteamGameAchievementFiles();
for (const objectId of Object.keys(gameAchievementFiles)) { for (const objectId of gameAchievementFiles.keys()) {
const [game, localAchievements] = await Promise.all([ const [game, localAchievements] = await Promise.all([
gameRepository.findOne({ gameRepository.findOne({
where: { objectID: objectId, shop: "steam", isDeleted: false }, where: { objectID: objectId, shop: "steam", isDeleted: false },
@ -29,6 +29,12 @@ export const saveAllLocalSteamAchivements = async () => {
if (!game) continue; if (!game) continue;
console.log(
"Achievements files for",
game.title,
gameAchievementFiles.get(objectId)
);
if (!localAchievements || !localAchievements.achievements) { if (!localAchievements || !localAchievements.achievements) {
await HydraApi.get( await HydraApi.get(
"/games/achievements", "/games/achievements",
@ -54,7 +60,7 @@ export const saveAllLocalSteamAchivements = async () => {
const unlockedAchievements: UnlockedAchievement[] = []; const unlockedAchievements: UnlockedAchievement[] = [];
for (const achievementFile of gameAchievementFiles[objectId]) { for (const achievementFile of gameAchievementFiles.get(objectId)!) {
const localAchievementFile = await parseAchievementFile( const localAchievementFile = await parseAchievementFile(
achievementFile.filePath achievementFile.filePath
); );

View File

@ -85,17 +85,28 @@ export const publishNotificationUpdateReadyToInstall = async (
}).show(); }).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 ( export const publishNewAchievementNotification = async (
game: string, game: string,
name: string, name: string,
icon: string iconUrl: string
) => { ) => {
const iconName = icon.split("/").pop() || "icon.png"; const iconPath = path.join(
await axios.get(icon, { responseType: "stream" }).then((response) => { app.getPath("temp"),
return response.data.pipe( iconUrl.split("/").pop() || "image.jpg"
fs.createWriteStream(path.join(app.getPath("temp"), iconName)) );
);
}); await downloadImage(iconUrl, iconPath);
new Notification({ new Notification({
title: t("game_achievement_unlocked", { title: t("game_achievement_unlocked", {
@ -103,7 +114,7 @@ export const publishNewAchievementNotification = async (
game, game,
}), }),
body: name, body: name,
icon: path.join(app.getPath("temp"), iconName), icon: iconPath,
}).show(); }).show();
}; };