Skip to content

Commit

Permalink
fix: fixing errors with electron dl manager
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrannychaseroperation committed May 5, 2024
1 parent 11f1785 commit 74a99f5
Show file tree
Hide file tree
Showing 51 changed files with 718 additions and 766 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
node_modules
hydra-download-manager
fastlist.exe
unrar.wasm
__pycache__
dist
out
Expand Down
1 change: 0 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extraResources:
- hydra-download-manager
- hydra.db
- fastlist.exe
- unrar.wasm
files:
- "!**/.vscode/*"
- "!src/*"
Expand Down
4 changes: 2 additions & 2 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineConfig(({ mode }) => {
"@main": resolve("src/main"),
"@locales": resolve("src/locales"),
"@resources": resolve("resources"),
"@globals": resolve("src/globals"),
"@shared": resolve("src/shared"),
},
},
plugins: [externalizeDepsPlugin(), swcPlugin(), sentryPlugin],
Expand All @@ -47,7 +47,7 @@ export default defineConfig(({ mode }) => {
alias: {
"@renderer": resolve("src/renderer/src"),
"@locales": resolve("src/locales"),
"@globals": resolve("src/globals"),
"@shared": resolve("src/shared"),
},
},
plugins: [svgr(), react(), vanillaExtractPlugin(), sentryPlugin],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"classnames": "^2.5.1",
"color.js": "^1.2.0",
"date-fns": "^3.6.0",
"electron-dl-manager": "^3.0.0",
"easydl": "^1.1.1",
"fetch-cookie": "^3.0.1",
"flexsearch": "^0.7.43",
"i18next": "^23.11.2",
Expand Down
2 changes: 0 additions & 2 deletions postinstall.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ if (process.platform === "win32") {
"fastlist.exe"
);
}

fs.copyFileSync("node_modules/node-unrar-js/esm/js/unrar.wasm", "unrar.wasm");
25 changes: 0 additions & 25 deletions src/globals.ts

This file was deleted.

14 changes: 6 additions & 8 deletions src/main/entity/game.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
OneToOne,
JoinColumn,
} from "typeorm";
import type { GameShop } from "@types";
import { Repack } from "./repack.entity";
import { GameStatus } from "@globals";

import type { GameShop } from "@types";
import { Downloader, GameStatus } from "@shared";

@Entity("game")
export class Game {
Expand All @@ -34,9 +35,6 @@ export class Game {
@Column("text", { nullable: true })
executablePath: string | null;

@Column("text", { nullable: true })
rarPath: string | null;

@Column("int", { default: 0 })
playTimeInMilliseconds: number;

Expand All @@ -46,6 +44,9 @@ export class Game {
@Column("text", { nullable: true })
status: GameStatus | null;

@Column("int", { default: Downloader.Torrent })
downloader: Downloader;

/**
* Progress is a float between 0 and 1
*/
Expand All @@ -55,9 +56,6 @@ export class Game {
@Column("float", { default: 0 })
fileVerificationProgress: number;

@Column("float", { default: 0 })
decompressionProgress: number;

@Column("int", { default: 0 })
bytesDownloaded: number;

Expand Down
1 change: 1 addition & 0 deletions src/main/events/library/add-game-to-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const addGameToLibrary = async (
const game = await gameRepository.findOne({
where: {
objectID,
isDeleted: false,
},
});

Expand Down
4 changes: 3 additions & 1 deletion src/main/events/library/close-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const closeGame = async (
gameId: number
) => {
const processes = await getProcesses();
const game = await gameRepository.findOne({ where: { id: gameId } });
const game = await gameRepository.findOne({
where: { id: gameId, isDeleted: false },
});

if (!game) return false;

Expand Down
3 changes: 2 additions & 1 deletion src/main/events/library/delete-game-folder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import fs from "node:fs";

import { GameStatus } from "@globals";
import { GameStatus } from "@shared";
import { gameRepository } from "@main/repository";

import { getDownloadsPath } from "../helpers/get-downloads-path";
Expand All @@ -16,6 +16,7 @@ const deleteGameFolder = async (
where: {
id: gameId,
status: GameStatus.Cancelled,
isDeleted: false,
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/main/events/library/get-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { gameRepository } from "@main/repository";

import { searchRepacks } from "../helpers/search-games";
import { registerEvent } from "../register-event";
import { GameStatus } from "@globals";
import { GameStatus } from "@shared";
import { sortBy } from "lodash-es";

const getLibrary = async () =>
Expand Down
4 changes: 3 additions & 1 deletion src/main/events/library/open-game-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const openGameInstaller = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number
) => {
const game = await gameRepository.findOne({ where: { id: gameId } });
const game = await gameRepository.findOne({
where: { id: gameId, isDeleted: false },
});

if (!game) return true;

Expand Down
2 changes: 1 addition & 1 deletion src/main/events/library/remove-game.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerEvent } from "../register-event";
import { gameRepository } from "../../repository";
import { GameStatus } from "@globals";
import { GameStatus } from "@shared";

const removeGame = async (
_event: Electron.IpcMainInvokeEvent,
Expand Down
8 changes: 4 additions & 4 deletions src/main/events/torrenting/cancel-game-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { registerEvent } from "../register-event";
import { WindowManager } from "@main/services";

import { In } from "typeorm";
import { Downloader } from "@main/services/downloaders/downloader";
import { GameStatus } from "@globals";
import { DownloadManager } from "@main/services";
import { GameStatus } from "@shared";

const cancelGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -14,19 +14,20 @@ const cancelGameDownload = async (
const game = await gameRepository.findOne({
where: {
id: gameId,
isDeleted: false,
status: In([
GameStatus.Downloading,
GameStatus.DownloadingMetadata,
GameStatus.CheckingFiles,
GameStatus.Paused,
GameStatus.Seeding,
GameStatus.Finished,
GameStatus.Decompressing,
]),
},
});

if (!game) return;
DownloadManager.cancelDownload();

await gameRepository
.update(
Expand All @@ -44,7 +45,6 @@ const cancelGameDownload = async (
game.status !== GameStatus.Paused &&
game.status !== GameStatus.Seeding
) {
Downloader.cancelDownload();
if (result.affected) WindowManager.mainWindow?.setProgressBar(-1);
}
});
Expand Down
13 changes: 5 additions & 8 deletions src/main/events/torrenting/pause-game-download.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { WindowManager } from "@main/services";

import { registerEvent } from "../register-event";
import { gameRepository } from "../../repository";
import { In } from "typeorm";
import { Downloader } from "@main/services/downloaders/downloader";
import { GameStatus } from "@globals";
import { DownloadManager, WindowManager } from "@main/services";
import { GameStatus } from "@shared";

const pauseGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number
) => {
DownloadManager.pauseDownload();

await gameRepository
.update(
{
Expand All @@ -23,10 +23,7 @@ const pauseGameDownload = async (
{ status: GameStatus.Paused }
)
.then((result) => {
if (result.affected) {
Downloader.pauseDownload();
WindowManager.mainWindow?.setProgressBar(-1);
}
if (result.affected) WindowManager.mainWindow?.setProgressBar(-1);
});
};

Expand Down
12 changes: 6 additions & 6 deletions src/main/events/torrenting/resume-game-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { registerEvent } from "../register-event";
import { gameRepository } from "../../repository";
import { getDownloadsPath } from "../helpers/get-downloads-path";
import { In } from "typeorm";
import { Downloader } from "@main/services/downloaders/downloader";
import { GameStatus } from "@globals";
import { DownloadManager } from "@main/services";
import { GameStatus } from "@shared";

const resumeGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -12,18 +12,18 @@ const resumeGameDownload = async (
const game = await gameRepository.findOne({
where: {
id: gameId,
isDeleted: false,
},
relations: { repack: true },
});

if (!game) return;

Downloader.resumeDownload();
DownloadManager.pauseDownload();

if (game.status === GameStatus.Paused) {
const downloadsPath = game.downloadPath ?? (await getDownloadsPath());

Downloader.downloadGame(game, game.repack);
DownloadManager.resumeDownload(gameId);

await gameRepository.update(
{
Expand All @@ -39,7 +39,7 @@ const resumeGameDownload = async (
await gameRepository.update(
{ id: game.id },
{
status: GameStatus.DownloadingMetadata,
status: GameStatus.Downloading,
downloadPath: downloadsPath,
}
);
Expand Down
37 changes: 23 additions & 14 deletions src/main/events/torrenting/start-game-download.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { getSteamGameIconUrl } from "@main/services";
import { gameRepository, repackRepository } from "@main/repository";
import {
gameRepository,
repackRepository,
userPreferencesRepository,
} from "@main/repository";

import { registerEvent } from "../register-event";

import type { GameShop } from "@types";
import { getFileBase64 } from "@main/helpers";
import { In } from "typeorm";
import { Downloader } from "@main/services/downloaders/downloader";
import { GameStatus } from "@globals";
import { DownloadManager } from "@main/services";
import { Downloader, GameStatus } from "@shared";

const startGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -17,6 +21,14 @@ const startGameDownload = async (
gameShop: GameShop,
downloadPath: string
) => {
const userPreferences = await userPreferencesRepository.findOne({
where: { id: 1 },
});

const downloader = userPreferences?.realDebridApiToken
? Downloader.Http
: Downloader.Torrent;

const [game, repack] = await Promise.all([
gameRepository.findOne({
where: {
Expand All @@ -30,13 +42,8 @@ const startGameDownload = async (
}),
]);

if (!repack) return;

if (game?.status === GameStatus.Downloading) {
return;
}

Downloader.pauseDownload();
if (!repack || game?.status === GameStatus.Downloading) return;
DownloadManager.pauseDownload();

await gameRepository.update(
{
Expand All @@ -57,12 +64,13 @@ const startGameDownload = async (
{
status: GameStatus.DownloadingMetadata,
downloadPath: downloadPath,
downloader,
repack: { id: repackId },
isDeleted: false,
}
);

Downloader.downloadGame(game, repack);
DownloadManager.downloadGame(game.id);

game.status = GameStatus.DownloadingMetadata;

Expand All @@ -74,13 +82,14 @@ const startGameDownload = async (
title,
iconUrl,
objectID,
downloader,
shop: gameShop,
status: GameStatus.DownloadingMetadata,
downloadPath: downloadPath,
status: GameStatus.Downloading,
downloadPath,
repack: { id: repackId },
});

Downloader.downloadGame(createdGame, repack);
DownloadManager.downloadGame(createdGame.id);

const { repack: _, ...rest } = createdGame;

Expand Down
5 changes: 5 additions & 0 deletions src/main/events/user-preferences/update-user-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import { userPreferencesRepository } from "@main/repository";
import { registerEvent } from "../register-event";

import type { UserPreferences } from "@types";
import { RealDebridClient } from "@main/services/real-debrid";

const updateUserPreferences = async (
_event: Electron.IpcMainInvokeEvent,
preferences: Partial<UserPreferences>
) => {
if (preferences.realDebridApiToken) {
RealDebridClient.authorize(preferences.realDebridApiToken);
}

await userPreferencesRepository.upsert(
{
id: 1,
Expand Down
Loading

0 comments on commit 74a99f5

Please sign in to comment.