From 3aa8230e17a1785ac99671163b031c3a594da134 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Sun, 22 Dec 2024 22:40:18 -0300 Subject: [PATCH] feat: restart downloads and move seed process initiation to main.ts --- src/main/main.ts | 25 +++++++++++++++++++++++-- src/main/services/python-rpc.ts | 3 --- src/main/services/seed.ts | 5 +---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 18b61c37..b8436c48 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -1,11 +1,13 @@ -import { Ludusavi, startMainLoop } from "./services"; -import { userPreferencesRepository } from "./repository"; +import { DownloadManager, Ludusavi, startMainLoop } from "./services"; +import { downloadQueueRepository, userPreferencesRepository } from "./repository"; 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 { sleep } from "./helpers"; const loadState = async (userPreferences: UserPreferences | null) => { import("./events"); @@ -22,7 +24,26 @@ const loadState = async (userPreferences: UserPreferences | null) => { uploadGamesBatch(); }); + + const [nextQueueItem] = await downloadQueueRepository.find({ + order: { + id: "DESC", + }, + relations: { + game: true, + }, + }); + PythonRPC.spawn(); + await sleep(1000); + // wait for python process to start + + if (nextQueueItem?.game.status === "active") { + DownloadManager.startDownload(nextQueueItem.game); + } + + await startSeedProcess(); + startMainLoop(); }; diff --git a/src/main/services/python-rpc.ts b/src/main/services/python-rpc.ts index d8e09911..55e3845b 100644 --- a/src/main/services/python-rpc.ts +++ b/src/main/services/python-rpc.ts @@ -8,7 +8,6 @@ import crypto from "node:crypto"; import { logger } from "./logger"; import { Readable } from "node:stream"; import { app, dialog } from "electron"; -import { startSeedProcess } from "./seed"; const binaryNameByPlatform: Partial> = { darwin: "hydra-python-rpc", @@ -84,8 +83,6 @@ export class PythonRPC { this.logStderr(childProcess.stderr); this.pythonProcess = childProcess; - - startSeedProcess(); } } diff --git a/src/main/services/seed.ts b/src/main/services/seed.ts index 26ac7fc6..b1147eca 100644 --- a/src/main/services/seed.ts +++ b/src/main/services/seed.ts @@ -13,11 +13,8 @@ export const startSeedProcess = async () => { if (seedList.length === 0) return; - await sleep(1000); - // wait for python process to start - seedList.map(async (game) => { await DownloadManager.startDownload(game); - await sleep(100); + await sleep(300); }); };