Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zamitto authored Aug 15, 2024
2 parents 51e8681 + c549d53 commit baf4eaf
Show file tree
Hide file tree
Showing 39 changed files with 561 additions and 407 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.vscode
node_modules
hydra-download-manager/
aria2/
fastlist.exe
__pycache__
dist
Expand Down
1 change: 0 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ productName: Hydra
directories:
buildResources: build
extraResources:
- aria2
- hydra-download-manager
- seeds
- from: node_modules/create-desktop-shortcuts/src/windows.vbs
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"start": "electron-vite preview",
"dev": "electron-vite dev",
"build": "npm run typecheck && electron-vite build",
"postinstall": "electron-builder install-app-deps && node ./postinstall.cjs",
"postinstall": "electron-builder install-app-deps",
"build:unpack": "npm run build && electron-builder --dir",
"build:win": "electron-vite build && electron-builder --win",
"build:mac": "electron-vite build && electron-builder --mac",
Expand All @@ -34,15 +34,13 @@
"dependencies": {
"@electron-toolkit/preload": "^3.0.0",
"@electron-toolkit/utils": "^3.0.0",
"@fontsource/fira-mono": "^5.0.13",
"@fontsource/fira-sans": "^5.0.20",
"@fontsource/noto-sans": "^5.0.22",
"@primer/octicons-react": "^19.9.0",
"@reduxjs/toolkit": "^2.2.3",
"@sentry/electron": "^5.1.0",
"@vanilla-extract/css": "^1.14.2",
"@vanilla-extract/dynamic": "^2.1.1",
"@vanilla-extract/recipes": "^0.5.2",
"aria2": "^4.1.2",
"auto-launch": "^5.0.6",
"axios": "^1.6.8",
"better-sqlite3": "^9.5.0",
Expand Down Expand Up @@ -97,7 +95,7 @@
"@types/user-agents": "^1.0.4",
"@vanilla-extract/vite-plugin": "^4.0.7",
"@vitejs/plugin-react": "^4.2.1",
"electron": "^30.0.9",
"electron": "^30.3.0",
"electron-builder": "^24.9.1",
"electron-vite": "^2.0.0",
"eslint": "^8.56.0",
Expand Down
50 changes: 0 additions & 50 deletions postinstall.cjs

This file was deleted.

80 changes: 0 additions & 80 deletions src/main/declaration.d.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/events/auth/sign-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
/* Disconnects libtorrent */
PythonInstance.killTorrent();

HydraApi.handleSignOut();

await Promise.all([
databaseOperations,
HydraApi.post("/auth/logout").catch(() => {}),
Expand Down
3 changes: 2 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const loadState = async (userPreferences: UserPreferences | null) => {

import("./events");

if (userPreferences?.realDebridApiToken)
if (userPreferences?.realDebridApiToken) {
RealDebridClient.authorize(userPreferences?.realDebridApiToken);
}

HydraApi.setupApi().then(() => {
uploadGamesBatch();
Expand Down
20 changes: 0 additions & 20 deletions src/main/services/aria2c.ts

This file was deleted.

54 changes: 36 additions & 18 deletions src/main/services/download/download-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import { downloadQueueRepository, gameRepository } from "@main/repository";
import { publishDownloadCompleteNotification } from "../notifications";
import { RealDebridDownloader } from "./real-debrid-downloader";
import type { DownloadProgress } from "@types";
import { GofileApi } from "../hosters";
import { GenericHTTPDownloader } from "./generic-http-downloader";

export class DownloadManager {
private static currentDownloader: Downloader | null = null;

public static async watchDownloads() {
let status: DownloadProgress | null = null;

if (this.currentDownloader === Downloader.RealDebrid) {
if (this.currentDownloader === Downloader.Torrent) {
status = await PythonInstance.getStatus();
} else if (this.currentDownloader === Downloader.RealDebrid) {
status = await RealDebridDownloader.getStatus();
} else {
status = await PythonInstance.getStatus();
status = await GenericHTTPDownloader.getStatus();
}

if (status) {
Expand Down Expand Up @@ -62,44 +66,58 @@ export class DownloadManager {
}

static async pauseDownload() {
if (this.currentDownloader === Downloader.RealDebrid) {
if (this.currentDownloader === Downloader.Torrent) {
await PythonInstance.pauseDownload();
} else if (this.currentDownloader === Downloader.RealDebrid) {
await RealDebridDownloader.pauseDownload();
} else {
await PythonInstance.pauseDownload();
await GenericHTTPDownloader.pauseDownload();
}

WindowManager.mainWindow?.setProgressBar(-1);
this.currentDownloader = null;
}

static async resumeDownload(game: Game) {
if (game.downloader === Downloader.RealDebrid) {
RealDebridDownloader.startDownload(game);
this.currentDownloader = Downloader.RealDebrid;
} else {
PythonInstance.startDownload(game);
this.currentDownloader = Downloader.Torrent;
}
return this.startDownload(game);
}

static async cancelDownload(gameId: number) {
if (this.currentDownloader === Downloader.RealDebrid) {
if (this.currentDownloader === Downloader.Torrent) {
PythonInstance.cancelDownload(gameId);
} else if (this.currentDownloader === Downloader.RealDebrid) {
RealDebridDownloader.cancelDownload(gameId);
} else {
PythonInstance.cancelDownload(gameId);
GenericHTTPDownloader.cancelDownload(gameId);
}

WindowManager.mainWindow?.setProgressBar(-1);
this.currentDownloader = null;
}

static async startDownload(game: Game) {
if (game.downloader === Downloader.RealDebrid) {
RealDebridDownloader.startDownload(game);
this.currentDownloader = Downloader.RealDebrid;
} else {
if (game.downloader === Downloader.Gofile) {
const id = game!.uri!.split("/").pop();

const token = await GofileApi.authorize();
const downloadLink = await GofileApi.getDownloadLink(id!);

GenericHTTPDownloader.startDownload(game, downloadLink, {
Cookie: `accountToken=${token}`,
});
} else if (game.downloader === Downloader.PixelDrain) {
const id = game!.uri!.split("/").pop();

await GenericHTTPDownloader.startDownload(
game,
`https://pixeldrain.com/api/file/${id}?download`
);
} else if (game.downloader === Downloader.Torrent) {
PythonInstance.startDownload(game);
this.currentDownloader = Downloader.Torrent;
} else if (game.downloader === Downloader.RealDebrid) {
RealDebridDownloader.startDownload(game);
}

this.currentDownloader = game.downloader;
}
}
Loading

0 comments on commit baf4eaf

Please sign in to comment.