From db01980eb81136d4c3feb9fa4eaa1ed541a02494 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Sun, 22 Dec 2024 20:20:46 -0300 Subject: [PATCH] refactor: clean up code --- .gitignore | 1 - src/main/events/auth/sign-out.ts | 4 ++-- .../events/profile/process-profile-image.ts | 7 ++++-- src/main/events/torrenting/pause-game-seed.ts | 8 +++---- .../events/torrenting/resume-game-seed.ts | 8 +++---- src/main/main.ts | 22 +------------------ src/main/services/hydra-api.ts | 2 +- 7 files changed, 15 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 24bf56f8..84771ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .vscode/ node_modules/ -fastlist.exe __pycache__ dist out diff --git a/src/main/events/auth/sign-out.ts b/src/main/events/auth/sign-out.ts index 67692707..6b720015 100644 --- a/src/main/events/auth/sign-out.ts +++ b/src/main/events/auth/sign-out.ts @@ -2,6 +2,7 @@ import { registerEvent } from "../register-event"; import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services"; import { dataSource } from "@main/data-source"; import { DownloadQueue, Game, UserAuth, UserSubscription } from "@main/entity"; +import { PythonRPC } from "@main/services/python-rpc"; const signOut = async (_event: Electron.IpcMainInvokeEvent) => { const databaseOperations = dataSource @@ -27,8 +28,7 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => { DownloadManager.cancelDownload(); /* Disconnects libtorrent */ - // TODO - // TorrentDownloader.killTorrent(); + PythonRPC.kill(); HydraApi.handleSignOut(); diff --git a/src/main/events/profile/process-profile-image.ts b/src/main/events/profile/process-profile-image.ts index 485635dc..c426a5e6 100644 --- a/src/main/events/profile/process-profile-image.ts +++ b/src/main/events/profile/process-profile-image.ts @@ -1,11 +1,14 @@ import { registerEvent } from "../register-event"; +import { PythonRPC } from "@main/services/python-rpc"; const processProfileImage = async ( _event: Electron.IpcMainInvokeEvent, path: string ) => { - return path; - // return PythonInstance.processProfileImage(path); + return PythonRPC.rpc.post<{ imagePath: string; mimeType: string }>( + "/profile_image_processor/process_image", + { path }, + ); }; registerEvent("processProfileImage", processProfileImage); diff --git a/src/main/events/torrenting/pause-game-seed.ts b/src/main/events/torrenting/pause-game-seed.ts index 3b38c626..9daa4d7b 100644 --- a/src/main/events/torrenting/pause-game-seed.ts +++ b/src/main/events/torrenting/pause-game-seed.ts @@ -8,11 +8,9 @@ const pauseGameSeed = async ( _event: Electron.IpcMainInvokeEvent, gameId: number ) => { - await dataSource.transaction(async (transactionalEntityManager) => { - await transactionalEntityManager - .getRepository(Game) - .update({ id: gameId }, { status: "complete", shouldSeed: false }); - }); + await dataSource + .getRepository(Game) + .update({ id: gameId }, { status: "complete", shouldSeed: false }); await DownloadManager.cancelDownload(gameId); }; diff --git a/src/main/events/torrenting/resume-game-seed.ts b/src/main/events/torrenting/resume-game-seed.ts index 93308f94..59a56012 100644 --- a/src/main/events/torrenting/resume-game-seed.ts +++ b/src/main/events/torrenting/resume-game-seed.ts @@ -20,11 +20,9 @@ const resumeGameSeed = async ( if (!game) return; - await dataSource.transaction(async (transactionalEntityManager) => { - await transactionalEntityManager - .getRepository(Game) - .update({ id: gameId }, { status: "seeding", shouldSeed: true }); - }); + await dataSource + .getRepository(Game) + .update({ id: gameId }, { status: "seeding", shouldSeed: true }); await DownloadManager.startDownload(game); }; diff --git a/src/main/main.ts b/src/main/main.ts index 3996996c..18b61c37 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -1,8 +1,5 @@ import { Ludusavi, startMainLoop } from "./services"; -import { - // downloadQueueRepository, - userPreferencesRepository, -} from "./repository"; +import { userPreferencesRepository } from "./repository"; import { UserPreferences } from "./entity"; import { RealDebridClient } from "./services/download/real-debrid"; import { HydraApi } from "./services/hydra-api"; @@ -25,24 +22,7 @@ const loadState = async (userPreferences: UserPreferences | null) => { uploadGamesBatch(); }); - // const [nextQueueItem] = await downloadQueueRepository.find({ - // order: { - // id: "DESC", - // }, - // relations: { - // game: true, - // }, - // }); - PythonRPC.spawn(); - // start download - - // if (nextQueueItem?.game.status === "active") { - // DownloadManager.startDownload(nextQueueItem.game); - // } else { - // PythonInstance.spawn(); - // } - startMainLoop(); }; diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index 22c2c950..bac1486a 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -30,7 +30,7 @@ export class HydraApi { private static instance: AxiosInstance; private static readonly EXPIRATION_OFFSET_IN_MS = 1000 * 60 * 5; // 5 minutes - private static readonly ADD_LOG_INTERCEPTOR = false; + private static readonly ADD_LOG_INTERCEPTOR = true; private static secondsToMilliseconds = (seconds: number) => seconds * 1000;