mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-25 20:01:03 +00:00
refactor: remove unnecessary download key deletion in game installer actions and simplify file size handling in download manager
This commit is contained in:
@@ -22,7 +22,6 @@ const getGameInstallerActionType = async (
|
||||
);
|
||||
|
||||
if (!fs.existsSync(gamePath)) {
|
||||
await downloadsSublevel.del(downloadKey);
|
||||
return "open-folder";
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ const openGameInstaller = async (
|
||||
);
|
||||
|
||||
if (!fs.existsSync(gamePath)) {
|
||||
await downloadsSublevel.del(downloadKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import { registerEvent } from "../register-event";
|
||||
import type { Download, StartGameDownloadPayload } from "@types";
|
||||
import { DownloadManager, HydraApi, logger } from "@main/services";
|
||||
import { createGame } from "@main/services/library-sync";
|
||||
import { parseBytes } from "@shared";
|
||||
import { downloadsSublevel, gamesSublevel, levelKeys } from "@main/level";
|
||||
import { handleDownloadError, prepareGameEntry } from "@main/helpers";
|
||||
|
||||
@@ -18,7 +17,6 @@ const startGameDownload = async (
|
||||
downloader,
|
||||
uri,
|
||||
automaticallyExtract,
|
||||
fileSize,
|
||||
} = payload;
|
||||
|
||||
const gameKey = levelKeys.game(shop, objectId);
|
||||
@@ -48,7 +46,7 @@ const startGameDownload = async (
|
||||
downloader,
|
||||
uri,
|
||||
folderName: null,
|
||||
fileSize: parseBytes(fileSize ?? null),
|
||||
fileSize: null,
|
||||
shouldSeed: false,
|
||||
timestamp: Date.now(),
|
||||
queued: true,
|
||||
|
||||
@@ -21,7 +21,7 @@ import { RealDebridClient } from "./real-debrid";
|
||||
import path from "node:path";
|
||||
import { logger } from "../logger";
|
||||
import { db, downloadsSublevel, gamesSublevel, levelKeys } from "@main/level";
|
||||
import { sortBy } from "lodash-es";
|
||||
import { orderBy } from "lodash-es";
|
||||
import { TorBoxClient } from "./torbox";
|
||||
import { GameFilesManager } from "../game-files-manager";
|
||||
import { HydraDebridClient } from "./hydra-debrid";
|
||||
@@ -323,7 +323,8 @@ export class DownloadManager {
|
||||
|
||||
this.sendProgressUpdate(progress, status, game);
|
||||
|
||||
if (progress === 1) {
|
||||
const isComplete = progress === 1 || download.status === "complete";
|
||||
if (isComplete) {
|
||||
await this.handleDownloadCompletion(download, game, gameId);
|
||||
}
|
||||
}
|
||||
@@ -422,10 +423,10 @@ export class DownloadManager {
|
||||
.values()
|
||||
.all()
|
||||
.then((games) =>
|
||||
sortBy(
|
||||
orderBy(
|
||||
games.filter((game) => game.status === "paused" && game.queued),
|
||||
"timestamp",
|
||||
"DESC"
|
||||
["timestamp"],
|
||||
["desc"]
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -320,10 +320,17 @@ export class JsHttpDownloader {
|
||||
return null;
|
||||
}
|
||||
|
||||
let progress = 0;
|
||||
if (this.status === "complete") {
|
||||
progress = 1;
|
||||
} else if (this.fileSize > 0) {
|
||||
progress = this.bytesDownloaded / this.fileSize;
|
||||
}
|
||||
|
||||
return {
|
||||
folderName: this.folderName,
|
||||
fileSize: this.fileSize,
|
||||
progress: this.fileSize > 0 ? this.bytesDownloaded / this.fileSize : 0,
|
||||
progress,
|
||||
downloadSpeed: this.downloadSpeed,
|
||||
numPeers: 0,
|
||||
numSeeds: 0,
|
||||
|
||||
@@ -47,9 +47,9 @@ function hexToRgb(hex: string): [number, number, number] {
|
||||
if (h.length === 3) {
|
||||
h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
||||
}
|
||||
const r = parseInt(h.substring(0, 2), 16) || 0;
|
||||
const g = parseInt(h.substring(2, 4), 16) || 0;
|
||||
const b = parseInt(h.substring(4, 6), 16) || 0;
|
||||
const r = Number.parseInt(h.substring(0, 2), 16) || 0;
|
||||
const g = Number.parseInt(h.substring(2, 4), 16) || 0;
|
||||
const b = Number.parseInt(h.substring(4, 6), 16) || 0;
|
||||
return [r, g, b];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user