mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
Merge branch 'feature/seed-completed-downloads' into feat/achievements-points
This commit is contained in:
commit
ea3d922242
5 changed files with 66 additions and 12 deletions
|
@ -1,11 +1,15 @@
|
|||
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 { PythonRPC } from "./services/python-rpc";
|
||||
|
||||
const loadState = async (userPreferences: UserPreferences | null) => {
|
||||
import("./events");
|
||||
|
@ -22,7 +26,23 @@ const loadState = async (userPreferences: UserPreferences | null) => {
|
|||
uploadGamesBatch();
|
||||
});
|
||||
|
||||
PythonRPC.spawn();
|
||||
const [nextQueueItem] = await downloadQueueRepository.find({
|
||||
order: {
|
||||
id: "DESC",
|
||||
},
|
||||
relations: {
|
||||
game: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (nextQueueItem?.game.status === "active") {
|
||||
DownloadManager.startRPC(nextQueueItem.game);
|
||||
} else {
|
||||
PythonRPC.spawn();
|
||||
}
|
||||
|
||||
await startSeedProcess();
|
||||
|
||||
startMainLoop();
|
||||
};
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -8,7 +8,12 @@ import crypto from "node:crypto";
|
|||
import { logger } from "./logger";
|
||||
import { Readable } from "node:stream";
|
||||
import { app, dialog } from "electron";
|
||||
import { startSeedProcess } from "./seed";
|
||||
|
||||
interface StartDownloadPayload {
|
||||
game_id: number;
|
||||
url: string;
|
||||
save_path: string;
|
||||
}
|
||||
|
||||
const binaryNameByPlatform: Partial<Record<NodeJS.Platform, string>> = {
|
||||
darwin: "hydra-python-rpc",
|
||||
|
@ -37,9 +42,15 @@ export class PythonRPC {
|
|||
readable.on("data", logger.log);
|
||||
}
|
||||
|
||||
public static spawn() {
|
||||
public static spawn(initialDownload?: StartDownloadPayload) {
|
||||
console.log([this.BITTORRENT_PORT, this.RPC_PORT, this.RPC_PASSWORD]);
|
||||
const commonArgs = [this.BITTORRENT_PORT, this.RPC_PORT, this.RPC_PASSWORD];
|
||||
|
||||
const commonArgs = [
|
||||
this.BITTORRENT_PORT,
|
||||
this.RPC_PORT,
|
||||
this.RPC_PASSWORD,
|
||||
initialDownload ? JSON.stringify(initialDownload) : "",
|
||||
];
|
||||
|
||||
if (app.isPackaged) {
|
||||
const binaryName = binaryNameByPlatform[process.platform]!;
|
||||
|
@ -84,8 +95,6 @@ export class PythonRPC {
|
|||
this.logStderr(childProcess.stderr);
|
||||
|
||||
this.pythonProcess = childProcess;
|
||||
|
||||
startSeedProcess();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,10 @@ 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);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue