feat: moving notifications

This commit is contained in:
Chubby Granny Chaser
2024-06-05 14:18:40 +01:00
parent d6e57c20c7
commit ef036d6f57
17 changed files with 179 additions and 87 deletions

View File

@@ -1,15 +1,10 @@
import Aria2, { StatusResponse } from "aria2";
import {
downloadQueueRepository,
gameRepository,
userPreferencesRepository,
} from "@main/repository";
import { downloadQueueRepository, gameRepository } from "@main/repository";
import { WindowManager } from "./window-manager";
import { RealDebridClient } from "./real-debrid";
import { Notification } from "electron";
import { t } from "i18next";
import { Downloader } from "@shared";
import { DownloadProgress } from "@types";
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
@@ -18,6 +13,7 @@ import { startAria2 } from "./aria2c";
import { sleep } from "@main/helpers";
import { logger } from "./logger";
import type { ChildProcess } from "node:child_process";
import { publishDownloadCompleteNotification } from "./notifications";
export class DownloadManager {
private static downloads = new Map<number, string>();
@@ -69,26 +65,6 @@ export class DownloadManager {
return -1;
}
static async publishNotification() {
const userPreferences = await userPreferencesRepository.findOne({
where: { id: 1 },
});
if (userPreferences?.downloadNotificationsEnabled && this.game) {
new Notification({
title: t("download_complete", {
ns: "notifications",
lng: userPreferences.language,
}),
body: t("game_ready_to_install", {
ns: "notifications",
lng: userPreferences.language,
title: this.game.title,
}),
}).show();
}
}
private static getFolderName(status: StatusResponse) {
if (status.bittorrent?.info) return status.bittorrent.info.name;
return "";
@@ -222,7 +198,7 @@ export class DownloadManager {
}
if (progress === 1 && this.game && !isDownloadingMetadata) {
await this.publishNotification();
await publishDownloadCompleteNotification(this.game);
await downloadQueueRepository.delete({ game: this.game });

View File

@@ -0,0 +1,24 @@
import { Notification } from "electron";
import { t } from "i18next";
import { Game } from "@main/entity";
import { userPreferencesRepository } from "@main/repository";
export const publishDownloadCompleteNotification = async (game: Game) => {
const userPreferences = await userPreferencesRepository.findOne({
where: { id: 1 },
});
if (userPreferences?.downloadNotificationsEnabled) {
new Notification({
title: t("download_complete", {
ns: "notifications",
lng: userPreferences.language,
}),
body: t("game_ready_to_install", {
ns: "notifications",
lng: userPreferences.language,
title: game.title,
}),
}).show();
}
};