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

@@ -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
);

View File

@@ -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();
};