diff --git a/package.json b/package.json index abfaf6b7..8f6612fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydralauncher", - "version": "3.0.8", + "version": "3.1.0", "description": "Hydra", "main": "./out/main/index.js", "author": "Los Broxas", diff --git a/python_rpc/http_downloader.py b/python_rpc/http_downloader.py index 855d5ef4..40e30ccd 100644 --- a/python_rpc/http_downloader.py +++ b/python_rpc/http_downloader.py @@ -34,7 +34,7 @@ class HttpDownloader: download = self.aria2.get_download(self.download.gid) response = { - 'folderName': str(download.dir) + "/" + download.name, + 'folderName': download.name, 'fileSize': download.total_length, 'progress': download.completed_length / download.total_length if download.total_length else 0, 'downloadSpeed': download.download_speed, diff --git a/python_rpc/main.py b/python_rpc/main.py index 54e5038f..36c0a922 100644 --- a/python_rpc/main.py +++ b/python_rpc/main.py @@ -124,8 +124,6 @@ def action(): action = data.get('action') game_id = data.get('game_id') - print(data) - if action == 'start': url = data.get('url') diff --git a/resources/tray-icon.png b/resources/tray-icon.png index ee90c026..b3b53789 100644 Binary files a/resources/tray-icon.png and b/resources/tray-icon.png differ diff --git a/src/main/events/cloud-save/get-game-artifacts.ts b/src/main/events/cloud-save/get-game-artifacts.ts index fc47076a..dbdcb853 100644 --- a/src/main/events/cloud-save/get-game-artifacts.ts +++ b/src/main/events/cloud-save/get-game-artifacts.ts @@ -1,6 +1,7 @@ import { HydraApi } from "@main/services"; import { registerEvent } from "../register-event"; import type { GameArtifact, GameShop } from "@types"; +import { SubscriptionRequiredError } from "@shared"; const getGameArtifacts = async ( _event: Electron.IpcMainInvokeEvent, @@ -13,8 +14,16 @@ const getGameArtifacts = async ( }); return HydraApi.get( - `/profile/games/artifacts?${params.toString()}` - ); + `/profile/games/artifacts?${params.toString()}`, + {}, + { needsSubscription: true } + ).catch((err) => { + if (err instanceof SubscriptionRequiredError) { + return []; + } + + throw err; + }); }; registerEvent("getGameArtifacts", getGameArtifacts); diff --git a/src/main/main.ts b/src/main/main.ts index 8c566123..5522becb 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -9,7 +9,6 @@ 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 { PythonRPC } from "./services/python-rpc"; const loadState = async (userPreferences: UserPreferences | null) => { import("./events"); @@ -43,11 +42,7 @@ const loadState = async (userPreferences: UserPreferences | null) => { }, }); - if (nextQueueItem?.game.status === "active") { - DownloadManager.startRPC(nextQueueItem.game, seedList); - } else { - PythonRPC.spawn(); - } + await DownloadManager.startRPC(nextQueueItem?.game, seedList); startMainLoop(); }; diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 3a8da5b4..29b117fd 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -24,23 +24,19 @@ import { logger } from "../logger"; export class DownloadManager { private static downloadingGameId: number | null = null; - public static startRPC(game: Game, initialSeeding?: Game[]) { - if (game && game.status === "active") { - PythonRPC.spawn( - { - game_id: game.id, - url: game.uri!, - save_path: game.downloadPath!, - }, - initialSeeding?.map((game) => ({ - game_id: game.id, - url: game.uri!, - save_path: game.downloadPath!, - })) - ); + public static async startRPC(game?: Game, initialSeeding?: Game[]) { + PythonRPC.spawn( + game?.status === "active" + ? await this.getDownloadPayload(game).catch(() => undefined) + : undefined, + initialSeeding?.map((game) => ({ + game_id: game.id, + url: game.uri!, + save_path: game.downloadPath!, + })) + ); - this.downloadingGameId = game.id; - } + this.downloadingGameId = game?.id ?? null; } private static async getDownloadStatus() { @@ -226,7 +222,9 @@ export class DownloadManager { WindowManager.mainWindow?.setProgressBar(-1); - this.downloadingGameId = null; + if (gameId === this.downloadingGameId) { + this.downloadingGameId = null; + } } static async resumeSeeding(game: Game) { @@ -245,7 +243,7 @@ export class DownloadManager { }); } - static async startDownload(game: Game) { + private static async getDownloadPayload(game: Game) { switch (game.downloader) { case Downloader.Gofile: { const id = game!.uri!.split("/").pop(); @@ -253,56 +251,58 @@ export class DownloadManager { const token = await GofileApi.authorize(); const downloadLink = await GofileApi.getDownloadLink(id!); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, url: downloadLink, - save_path: game.downloadPath, + save_path: game.downloadPath!, header: `Cookie: accountToken=${token}`, - }); - break; + }; } case Downloader.PixelDrain: { const id = game!.uri!.split("/").pop(); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, url: `https://pixeldrain.com/api/file/${id}?download`, - save_path: game.downloadPath, - }); - break; + save_path: game.downloadPath!, + }; } case Downloader.Qiwi: { const downloadUrl = await QiwiApi.getDownloadUrl(game.uri!); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, url: downloadUrl, - save_path: game.downloadPath, - }); - break; + save_path: game.downloadPath!, + }; } case Downloader.Torrent: - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, - url: game.uri, - save_path: game.downloadPath, - }); - break; + url: game.uri!, + save_path: game.downloadPath!, + }; case Downloader.RealDebrid: { const downloadUrl = await RealDebridClient.getDownloadUrl(game.uri!); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, - url: downloadUrl, - save_path: game.downloadPath, - }); + url: downloadUrl!, + save_path: game.downloadPath!, + }; } } + } + + static async startDownload(game: Game) { + const payload = await this.getDownloadPayload(game); + + await PythonRPC.rpc.post("/action", payload); this.downloadingGameId = game.id; } diff --git a/src/renderer/src/pages/achievements/achievement-list.tsx b/src/renderer/src/pages/achievements/achievement-list.tsx index 6e6944de..ef178b50 100644 --- a/src/renderer/src/pages/achievements/achievement-list.tsx +++ b/src/renderer/src/pages/achievements/achievement-list.tsx @@ -18,8 +18,12 @@ export function AchievementList({ achievements }: AchievementListProps) { return (