From 5714c230730ccd2387e723abc8542f756b223373 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Sat, 21 Dec 2024 15:34:29 -0300 Subject: [PATCH] feat: implement seed process initiation in PythonRPC --- src/main/services/python-rpc.ts | 3 +++ src/main/services/seed.ts | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/services/seed.ts diff --git a/src/main/services/python-rpc.ts b/src/main/services/python-rpc.ts index 55e3845b..d8e09911 100644 --- a/src/main/services/python-rpc.ts +++ b/src/main/services/python-rpc.ts @@ -8,6 +8,7 @@ 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", @@ -83,6 +84,8 @@ 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 new file mode 100644 index 00000000..a9d093f4 --- /dev/null +++ b/src/main/services/seed.ts @@ -0,0 +1,24 @@ +import { gameRepository } from "@main/repository"; +import { DownloadManager } from "./download/download-manager"; +import { sleep } from "@main/helpers"; + +export const startSeedProcess = async () => { + const seedList = await gameRepository.find({ + where: { + shouldSeed: true, + downloader: 1, + progress: 1, + }, + }); + + 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); + }); +}; +