From af2b42215414250e3a98167fc3fd5b59098c1184 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Mon, 23 Dec 2024 02:07:37 -0300 Subject: [PATCH] feat: integrate DownloadManager for active game downloads and streamline RPC handling --- src/main/main.ts | 17 ++++------------- src/main/services/download/download-manager.ts | 14 +++++++++++++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 63517ce2..c39a5196 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -1,4 +1,4 @@ -import { Ludusavi, startMainLoop } from "./services"; +import { DownloadManager, Ludusavi, startMainLoop } from "./services"; import { downloadQueueRepository, userPreferencesRepository, @@ -7,9 +7,9 @@ import { UserPreferences } from "./entity"; import { RealDebridClient } from "./services/download/real-debrid"; import { HydraApi } from "./services/hydra-api"; import { uploadGamesBatch } from "./services/library-sync"; -import { PythonRPC } from "./services/python-rpc"; import { Aria2 } from "./services/aria2"; import { startSeedProcess } from "./services/seed"; +import { PythonRPC } from "./services/python-rpc"; const loadState = async (userPreferences: UserPreferences | null) => { import("./events"); @@ -35,17 +35,8 @@ const loadState = async (userPreferences: UserPreferences | null) => { }, }); - if ( - nextQueueItem?.game.status === "active" && - nextQueueItem?.game.id && - nextQueueItem?.game.uri && - nextQueueItem?.game.downloadPath - ) { - PythonRPC.spawn({ - game_id: nextQueueItem.game.id, - url: nextQueueItem.game.uri, - save_path: nextQueueItem.game.downloadPath, - }); + if (nextQueueItem?.game.status === "active") { + DownloadManager.startRPC(nextQueueItem.game); } else { PythonRPC.spawn(); } diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index a4106fef..47822ec4 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -23,6 +23,18 @@ import path from "path"; export class DownloadManager { private static downloadingGameId: number | null = null; + public static startRPC(game: Game) { + if (game && game.status === "active") { + PythonRPC.spawn({ + game_id: game.id, + url: game.uri!, + save_path: game.downloadPath!, + }); + + this.downloadingGameId = game.id; + } + } + private static async getDownloadStatus() { const response = await PythonRPC.rpc.get( "/status" @@ -188,7 +200,7 @@ export class DownloadManager { action: "pause", game_id: this.downloadingGameId, } as PauseDownloadPayload) - .catch(() => {}); + .catch(() => { }); WindowManager.mainWindow?.setProgressBar(-1);