mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 13:34:54 +03:00
feat: apply suggestions
This commit is contained in:
parent
ae3daa4c79
commit
153291f89f
@ -1,6 +1,6 @@
|
||||
import { registerEvent } from "../register-event";
|
||||
import * as Sentry from "@sentry/electron/main";
|
||||
import { HydraApi, RPCManager, gamesPlaytime } from "@main/services";
|
||||
import { HydraApi, PythonInstance, gamesPlaytime } from "@main/services";
|
||||
import { dataSource } from "@main/data-source";
|
||||
import { DownloadQueue, Game, UserAuth } from "@main/entity";
|
||||
|
||||
@ -24,7 +24,7 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
Sentry.setUser(null);
|
||||
|
||||
/* Disconnects libtorrent */
|
||||
RPCManager.killTorrent();
|
||||
PythonInstance.killTorrent();
|
||||
|
||||
await Promise.all([
|
||||
databaseOperations,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { gameRepository } from "@main/repository";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { RPCManager, logger } from "@main/services";
|
||||
import { PythonInstance, logger } from "@main/services";
|
||||
import sudo from "sudo-prompt";
|
||||
import { app } from "electron";
|
||||
|
||||
@ -16,7 +16,7 @@ const closeGame = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
gameId: number
|
||||
) => {
|
||||
const processes = await RPCManager.getProcessList();
|
||||
const processes = await PythonInstance.getProcessList();
|
||||
const game = await gameRepository.findOne({
|
||||
where: { id: gameId, isDeleted: false },
|
||||
});
|
||||
|
@ -5,7 +5,7 @@ import i18n from "i18next";
|
||||
import path from "node:path";
|
||||
import url from "node:url";
|
||||
import { electronApp, optimizer } from "@electron-toolkit/utils";
|
||||
import { logger, RPCManager, WindowManager } from "@main/services";
|
||||
import { logger, PythonInstance, WindowManager } from "@main/services";
|
||||
import { dataSource } from "@main/data-source";
|
||||
import * as resources from "@locales";
|
||||
import { userPreferencesRepository } from "@main/repository";
|
||||
@ -116,7 +116,7 @@ app.on("window-all-closed", () => {
|
||||
|
||||
app.on("before-quit", () => {
|
||||
/* Disconnects libtorrent */
|
||||
RPCManager.kill();
|
||||
PythonInstance.kill();
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {
|
||||
DownloadManager,
|
||||
RepacksManager,
|
||||
RPCManager,
|
||||
PythonInstance,
|
||||
startMainLoop,
|
||||
} from "./services";
|
||||
import {
|
||||
@ -41,7 +41,7 @@ const loadState = async (userPreferences: UserPreferences | null) => {
|
||||
if (nextQueueItem?.game.status === "active") {
|
||||
DownloadManager.startDownload(nextQueueItem.game);
|
||||
} else {
|
||||
RPCManager.spawn();
|
||||
PythonInstance.spawn();
|
||||
}
|
||||
|
||||
startMainLoop();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Game } from "@main/entity";
|
||||
import { Downloader } from "@shared";
|
||||
import { RPCManager } from "./rpc-manager";
|
||||
import { PythonInstance } from "./python-instance";
|
||||
import { WindowManager } from "../window-manager";
|
||||
import { downloadQueueRepository, gameRepository } from "@main/repository";
|
||||
import { publishDownloadCompleteNotification } from "../notifications";
|
||||
@ -16,7 +16,7 @@ export class DownloadManager {
|
||||
if (this.currentDownloader === Downloader.RealDebrid) {
|
||||
status = await RealDebridDownloader.getStatus();
|
||||
} else {
|
||||
status = await RPCManager.getStatus();
|
||||
status = await PythonInstance.getStatus();
|
||||
}
|
||||
|
||||
if (status) {
|
||||
@ -65,7 +65,7 @@ export class DownloadManager {
|
||||
if (this.currentDownloader === Downloader.RealDebrid) {
|
||||
RealDebridDownloader.pauseDownload();
|
||||
} else {
|
||||
await RPCManager.pauseDownload();
|
||||
await PythonInstance.pauseDownload();
|
||||
}
|
||||
|
||||
WindowManager.mainWindow?.setProgressBar(-1);
|
||||
@ -77,7 +77,7 @@ export class DownloadManager {
|
||||
RealDebridDownloader.startDownload(game);
|
||||
this.currentDownloader = Downloader.RealDebrid;
|
||||
} else {
|
||||
RPCManager.startDownload(game);
|
||||
PythonInstance.startDownload(game);
|
||||
this.currentDownloader = Downloader.Torrent;
|
||||
}
|
||||
}
|
||||
@ -86,7 +86,7 @@ export class DownloadManager {
|
||||
if (this.currentDownloader === Downloader.RealDebrid) {
|
||||
RealDebridDownloader.cancelDownload();
|
||||
} else {
|
||||
RPCManager.cancelDownload(gameId);
|
||||
PythonInstance.cancelDownload(gameId);
|
||||
}
|
||||
|
||||
WindowManager.mainWindow?.setProgressBar(-1);
|
||||
@ -98,7 +98,7 @@ export class DownloadManager {
|
||||
RealDebridDownloader.startDownload(game);
|
||||
this.currentDownloader = Downloader.RealDebrid;
|
||||
} else {
|
||||
RPCManager.startDownload(game);
|
||||
PythonInstance.startDownload(game);
|
||||
this.currentDownloader = Downloader.Torrent;
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
export * from "./download-manager";
|
||||
export * from "./rpc-manager";
|
||||
export * from "./python-instance";
|
||||
|
@ -20,8 +20,8 @@ import {
|
||||
ProcessPayload,
|
||||
} from "./types";
|
||||
|
||||
export class RPCManager {
|
||||
private static rpcProcess: cp.ChildProcess | null = null;
|
||||
export class PythonInstance {
|
||||
private static pythonProcess: cp.ChildProcess | null = null;
|
||||
private static downloadingGameId = -1;
|
||||
|
||||
private static rpc = axios.create({
|
||||
@ -32,19 +32,19 @@ export class RPCManager {
|
||||
});
|
||||
|
||||
public static spawn(args?: StartDownloadPayload) {
|
||||
this.rpcProcess = startRPCClient(args);
|
||||
this.pythonProcess = startRPCClient(args);
|
||||
}
|
||||
|
||||
public static kill() {
|
||||
if (this.rpcProcess) {
|
||||
this.rpcProcess.kill();
|
||||
this.rpcProcess = null;
|
||||
if (this.pythonProcess) {
|
||||
this.pythonProcess.kill();
|
||||
this.pythonProcess = null;
|
||||
this.downloadingGameId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static killTorrent() {
|
||||
if (this.rpcProcess) {
|
||||
if (this.pythonProcess) {
|
||||
this.rpc.post("/action", { action: "kill-torrent" });
|
||||
this.downloadingGameId = -1;
|
||||
}
|
||||
@ -131,7 +131,7 @@ export class RPCManager {
|
||||
}
|
||||
|
||||
static async startDownload(game: Game) {
|
||||
if (!this.rpcProcess) {
|
||||
if (!this.pythonProcess) {
|
||||
this.spawn({
|
||||
game_id: game.id,
|
||||
magnet: game.uri!,
|
@ -3,7 +3,7 @@ import { gameRepository } from "@main/repository";
|
||||
import { WindowManager } from "./window-manager";
|
||||
import { createGame, updateGamePlaytime } from "./library-sync";
|
||||
import { GameRunning } from "@types";
|
||||
import { RPCManager } from "./download";
|
||||
import { PythonInstance } from "./download";
|
||||
|
||||
export const gamesPlaytime = new Map<
|
||||
number,
|
||||
@ -19,7 +19,7 @@ export const watchProcesses = async () => {
|
||||
});
|
||||
|
||||
if (games.length === 0) return;
|
||||
const processes = await RPCManager.getProcessList();
|
||||
const processes = await PythonInstance.getProcessList();
|
||||
|
||||
for (const game of games) {
|
||||
const executablePath = game.executablePath!;
|
||||
|
@ -30,12 +30,13 @@ class Downloader:
|
||||
self.torrent_handles[game_id] = None
|
||||
self.downloading_game_id = -1
|
||||
|
||||
def cancel_all_downloads(self):
|
||||
def abort_session(self):
|
||||
for game_id in self.torrent_handles:
|
||||
torrent_handle = self.torrent_handles[game_id]
|
||||
torrent_handle.pause()
|
||||
self.session.remove_torrent(torrent_handle)
|
||||
|
||||
|
||||
self.session.abort()
|
||||
self.torrent_handles = {}
|
||||
self.downloading_game_id = -1
|
||||
|
||||
|
@ -8,11 +8,12 @@ from downloader import Downloader
|
||||
torrent_port = sys.argv[1]
|
||||
http_port = sys.argv[2]
|
||||
rpc_password = sys.argv[3]
|
||||
start_download_payload = sys.argv[4]
|
||||
|
||||
downloader = None
|
||||
|
||||
if sys.argv[4]:
|
||||
initial_download = json.loads(urllib.parse.unquote(sys.argv[4]))
|
||||
if start_download_payload:
|
||||
initial_download = json.loads(urllib.parse.unquote(start_download_payload))
|
||||
downloader = Downloader(torrent_port)
|
||||
downloader.start_download(initial_download['game_id'], initial_download['magnet'], initial_download['save_path'])
|
||||
|
||||
@ -75,7 +76,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
elif data['action'] == 'cancel':
|
||||
downloader.cancel_download(data['game_id'])
|
||||
elif data['action'] == 'kill-torrent':
|
||||
downloader.cancel_all_downloads()
|
||||
downloader.abort_session()
|
||||
downloader = None
|
||||
|
||||
self.send_response(200)
|
||||
|
Loading…
Reference in New Issue
Block a user