feat: adding icon parser to download notification

This commit is contained in:
Chubby Granny Chaser
2024-06-05 20:15:59 +01:00
parent 6b8ab895e3
commit 4a4a800b07
17 changed files with 343 additions and 146 deletions

View File

@@ -1,13 +1,40 @@
import { Notification } from "electron";
import { Notification, nativeImage } from "electron";
import { t } from "i18next";
import { parseICO } from "icojs";
import { Game } from "@main/entity";
import { userPreferencesRepository } from "@main/repository";
import { gameRepository, userPreferencesRepository } from "@main/repository";
const getGameIconNativeImage = async (gameId: number) => {
try {
const game = await gameRepository.findOne({
where: {
id: gameId,
},
});
if (!game?.iconUrl) return undefined;
const images = await parseICO(
Buffer.from(game.iconUrl.split("base64,")[1], "base64")
);
const highResIcon = images.find((image) => image.width >= 128);
if (!highResIcon) return undefined;
return nativeImage.createFromBuffer(Buffer.from(highResIcon.buffer));
} catch (err) {
return undefined;
}
};
export const publishDownloadCompleteNotification = async (game: Game) => {
const userPreferences = await userPreferencesRepository.findOne({
where: { id: 1 },
});
const icon = await getGameIconNativeImage(game.id);
if (userPreferences?.downloadNotificationsEnabled) {
new Notification({
title: t("download_complete", {
@@ -19,6 +46,7 @@ export const publishDownloadCompleteNotification = async (game: Game) => {
lng: userPreferences.language,
title: game.title,
}),
icon,
}).show();
}
};
@@ -28,7 +56,7 @@ export const publishNewRepacksNotifications = async (count: number) => {
where: { id: 1 },
});
if (count > 0 && userPreferences?.repackUpdatesNotificationsEnabled) {
if (userPreferences?.repackUpdatesNotificationsEnabled) {
new Notification({
title: t("repack_list_updated", {
ns: "notifications",