From 34a44e7fa995e5587bcd8d038c5a773c9593807f Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Wed, 29 May 2024 22:14:07 +0100 Subject: [PATCH] feat: kill aria2c --- src/main/index.ts | 11 ++++++++++- src/main/services/download-manager.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index c56903dd..74481090 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -3,7 +3,12 @@ import updater from "electron-updater"; import i18n from "i18next"; import path from "node:path"; import { electronApp, optimizer } from "@electron-toolkit/utils"; -import { logger, resolveDatabaseUpdates, WindowManager } from "@main/services"; +import { + DownloadManager, + logger, + resolveDatabaseUpdates, + WindowManager, +} from "@main/services"; import { dataSource } from "@main/data-source"; import * as resources from "@locales"; import { userPreferencesRepository } from "@main/repository"; @@ -100,6 +105,10 @@ app.on("window-all-closed", () => { WindowManager.mainWindow = null; }); +app.on("before-quit", () => { + DownloadManager.disconnect(); +}); + app.on("activate", () => { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. diff --git a/src/main/services/download-manager.ts b/src/main/services/download-manager.ts index c1f39f74..60a796a6 100644 --- a/src/main/services/download-manager.ts +++ b/src/main/services/download-manager.ts @@ -13,6 +13,7 @@ import { Game } from "@main/entity"; import { startAria2 } from "./aria2c"; import { sleep } from "@main/helpers"; import { logger } from "./logger"; +import type { ChildProcess } from "node:child_process"; export class DownloadManager { private static downloads = new Map(); @@ -21,11 +22,12 @@ export class DownloadManager { private static gid: string | null = null; private static game: Game | null = null; private static realDebridTorrentId: string | null = null; + private static aria2c: ChildProcess | null = null; private static aria2 = new Aria2({}); private static async connect() { - startAria2(); + this.aria2c = startAria2(); let retries = 0; @@ -43,6 +45,12 @@ export class DownloadManager { } } + public static disconnect() { + if (this.aria2c) { + this.aria2c.kill(); + } + } + private static getETA( totalLength: number, completedLength: number,