diff --git a/package.json b/package.json index 8f6612fe..402d45cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydralauncher", - "version": "3.1.0", + "version": "3.1.1", "description": "Hydra", "main": "./out/main/index.js", "author": "Los Broxas", diff --git a/python_rpc/main.py b/python_rpc/main.py index 36c0a922..c1f410d1 100644 --- a/python_rpc/main.py +++ b/python_rpc/main.py @@ -36,7 +36,7 @@ if start_download_payload: if start_seeding_payload: initial_seeding = json.loads(urllib.parse.unquote(start_seeding_payload)) for seed in initial_seeding: - torrent_downloader = TorrentDownloader(torrent_session) + torrent_downloader = TorrentDownloader(torrent_session, lt.torrent_flags.upload_mode) downloads[seed['game_id']] = torrent_downloader torrent_downloader.start_download(seed['url'], seed['save_path'], "") @@ -156,7 +156,7 @@ def action(): if downloader: downloader.cancel_download() elif action == 'resume_seeding': - torrent_downloader = TorrentDownloader(torrent_session) + torrent_downloader = TorrentDownloader(torrent_session, lt.torrent_flags.upload_mode) downloads[game_id] = torrent_downloader torrent_downloader.start_download(data['url'], data['save_path'], "") elif action == 'pause_seeding': diff --git a/python_rpc/torrent_downloader.py b/python_rpc/torrent_downloader.py index 46ee4e33..ca4c2fa8 100644 --- a/python_rpc/torrent_downloader.py +++ b/python_rpc/torrent_downloader.py @@ -1,9 +1,10 @@ import libtorrent as lt class TorrentDownloader: - def __init__(self, torrent_session): + def __init__(self, torrent_session, flags = lt.torrent_flags.auto_managed): self.torrent_handle = None self.session = torrent_session + self.flags = flags self.trackers = [ "udp://tracker.opentrackr.org:1337/announce", "http://tracker.opentrackr.org:1337/announce", @@ -102,9 +103,8 @@ class TorrentDownloader: ] def start_download(self, magnet: str, save_path: str, header: str): - params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers} + params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers, 'flags': self.flags} self.torrent_handle = self.session.add_torrent(params) - self.torrent_handle.set_flags(lt.torrent_flags.auto_managed) self.torrent_handle.resume() def pause_download(self): diff --git a/src/main/events/torrenting/resume-game-seed.ts b/src/main/events/torrenting/resume-game-seed.ts index 6310f5b8..9f79e53a 100644 --- a/src/main/events/torrenting/resume-game-seed.ts +++ b/src/main/events/torrenting/resume-game-seed.ts @@ -1,6 +1,7 @@ import { registerEvent } from "../register-event"; import { gameRepository } from "../../repository"; import { DownloadManager } from "@main/services"; +import { Downloader } from "@shared"; const resumeGameSeed = async ( _event: Electron.IpcMainInvokeEvent, @@ -10,7 +11,7 @@ const resumeGameSeed = async ( where: { id: gameId, isDeleted: false, - downloader: 1, + downloader: Downloader.Torrent, progress: 1, }, }); diff --git a/src/main/main.ts b/src/main/main.ts index 5522becb..9e00ff6a 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -9,6 +9,7 @@ import { RealDebridClient } from "./services/download/real-debrid"; import { HydraApi } from "./services/hydra-api"; import { uploadGamesBatch } from "./services/library-sync"; import { Aria2 } from "./services/aria2"; +import { Downloader } from "@shared"; const loadState = async (userPreferences: UserPreferences | null) => { import("./events"); @@ -37,7 +38,7 @@ const loadState = async (userPreferences: UserPreferences | null) => { const seedList = await gameRepository.find({ where: { shouldSeed: true, - downloader: 1, + downloader: Downloader.Torrent, progress: 1, }, }); diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 29b117fd..80a3f6fb 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -100,8 +100,6 @@ export class DownloadManager { public static async watchDownloads() { const status = await this.getDownloadStatus(); - // status = await RealDebridDownloader.getStatus(); - if (status) { const { gameId, progress } = status; const game = await gameRepository.findOne({ diff --git a/src/main/services/logger.ts b/src/main/services/logger.ts index e3e52290..95a399ea 100644 --- a/src/main/services/logger.ts +++ b/src/main/services/logger.ts @@ -31,6 +31,6 @@ log.errorHandler.startCatching({ log.initialize(); -export const pythonInstanceLogger = log.scope("python-instance"); +export const pythonRpcLogger = log.scope("python-rpc"); export const logger = log.scope("main"); export const achievementsLogger = log.scope("achievements"); diff --git a/src/main/services/python-rpc.ts b/src/main/services/python-rpc.ts index 19622a99..1384a1be 100644 --- a/src/main/services/python-rpc.ts +++ b/src/main/services/python-rpc.ts @@ -5,7 +5,7 @@ import fs from "node:fs"; import path from "node:path"; import crypto from "node:crypto"; -import { logger } from "./logger"; +import { pythonRpcLogger } from "./logger"; import { Readable } from "node:stream"; import { app, dialog } from "electron"; @@ -39,7 +39,7 @@ export class PythonRPC { if (!readable) return; readable.setEncoding("utf-8"); - readable.on("data", logger.log); + readable.on("data", pythonRpcLogger.log); } public static spawn( @@ -100,7 +100,7 @@ export class PythonRPC { public static kill() { if (this.pythonProcess) { - logger.log("Killing python process"); + pythonRpcLogger.log("Killing python process"); this.pythonProcess.kill(); this.pythonProcess = null; } diff --git a/src/renderer/src/pages/catalogue/catalogue.tsx b/src/renderer/src/pages/catalogue/catalogue.tsx index 524b3c25..14a9f4d6 100644 --- a/src/renderer/src/pages/catalogue/catalogue.tsx +++ b/src/renderer/src/pages/catalogue/catalogue.tsx @@ -20,6 +20,7 @@ import { Pagination } from "./pagination"; import { useCatalogue } from "@renderer/hooks/use-catalogue"; import { GameItem } from "./game-item"; import { FilterItem } from "./filter-item"; +import { debounce } from "lodash-es"; const filterCategoryColors = { genres: "hsl(262deg 50% 47%)", @@ -58,26 +59,36 @@ export default function Catalogue() { const { getRepacksForObjectId } = useRepacks(); + const debouncedSearch = useRef( + debounce(async (filters, pageSize, offset) => { + const abortController = new AbortController(); + abortControllerRef.current = abortController; + + const response = await window.electron.searchGames( + filters, + pageSize, + offset + ); + + if (abortController.signal.aborted) return; + + setResults(response.edges); + setItemsCount(response.count); + setIsLoading(false); + }, 500) + ).current; + useEffect(() => { setResults([]); setIsLoading(true); abortControllerRef.current?.abort(); - const abortController = new AbortController(); - abortControllerRef.current = abortController; + debouncedSearch(filters, PAGE_SIZE, (page - 1) * PAGE_SIZE); - window.electron - .searchGames(filters, PAGE_SIZE, (page - 1) * PAGE_SIZE) - .then((response) => { - if (abortController.signal.aborted) { - return; - } - - setResults(response.edges); - setItemsCount(response.count); - setIsLoading(false); - }); - }, [filters, page, dispatch]); + return () => { + debouncedSearch.cancel(); + }; + }, [filters, page, debouncedSearch]); useEffect(() => { downloadSourcesTable.toArray().then((sources) => {