feat: integrate DownloadManager for active game downloads and streamline RPC handling

This commit is contained in:
Hachi-R 2024-12-23 02:07:37 -03:00
parent e463ee569a
commit af2b422154
2 changed files with 17 additions and 14 deletions

View File

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

View File

@ -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<LibtorrentPayload | null>(
"/status"
@ -188,7 +200,7 @@ export class DownloadManager {
action: "pause",
game_id: this.downloadingGameId,
} as PauseDownloadPayload)
.catch(() => {});
.catch(() => { });
WindowManager.mainWindow?.setProgressBar(-1);