mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-31 23:01:02 +00:00
fix: fixing errors with electron dl manager
This commit is contained in:
@@ -16,6 +16,7 @@ const addGameToLibrary = async (
|
||||
const game = await gameRepository.findOne({
|
||||
where: {
|
||||
objectID,
|
||||
isDeleted: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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";
|
||||
@@ -16,6 +16,7 @@ const deleteGameFolder = async (
|
||||
where: {
|
||||
id: gameId,
|
||||
status: GameStatus.Cancelled,
|
||||
isDeleted: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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 () =>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
@@ -14,6 +14,7 @@ const cancelGameDownload = async (
|
||||
const game = await gameRepository.findOne({
|
||||
where: {
|
||||
id: gameId,
|
||||
isDeleted: false,
|
||||
status: In([
|
||||
GameStatus.Downloading,
|
||||
GameStatus.DownloadingMetadata,
|
||||
@@ -21,12 +22,12 @@ const cancelGameDownload = async (
|
||||
GameStatus.Paused,
|
||||
GameStatus.Seeding,
|
||||
GameStatus.Finished,
|
||||
GameStatus.Decompressing,
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
if (!game) return;
|
||||
DownloadManager.cancelDownload();
|
||||
|
||||
await gameRepository
|
||||
.update(
|
||||
@@ -44,7 +45,6 @@ const cancelGameDownload = async (
|
||||
game.status !== GameStatus.Paused &&
|
||||
game.status !== GameStatus.Seeding
|
||||
) {
|
||||
Downloader.cancelDownload();
|
||||
if (result.affected) WindowManager.mainWindow?.setProgressBar(-1);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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(
|
||||
{
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -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(
|
||||
{
|
||||
@@ -39,7 +39,7 @@ const resumeGameDownload = async (
|
||||
await gameRepository.update(
|
||||
{ id: game.id },
|
||||
{
|
||||
status: GameStatus.DownloadingMetadata,
|
||||
status: GameStatus.Downloading,
|
||||
downloadPath: downloadsPath,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
@@ -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: {
|
||||
@@ -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(
|
||||
{
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user