feat: apply suggestions

This commit is contained in:
Zamitto
2024-07-03 16:10:23 -03:00
parent ae3daa4c79
commit 153291f89f
10 changed files with 32 additions and 30 deletions

View File

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

View File

@@ -1,2 +1,2 @@
export * from "./download-manager";
export * from "./rpc-manager";
export * from "./python-instance";

View File

@@ -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!,

View File

@@ -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!;