mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
fix: fixing downloads screen
This commit is contained in:
parent
4941709296
commit
da607fe741
5 changed files with 48 additions and 48 deletions
|
@ -20,7 +20,7 @@ const resumeGameDownload = async (
|
|||
if (game.status === "paused") {
|
||||
await DownloadManager.pauseDownload();
|
||||
|
||||
await gameRepository.update({ status: "active" }, { status: "paused" });
|
||||
await gameRepository.update({ id: gameId }, { status: "active" });
|
||||
|
||||
await DownloadManager.resumeDownload(gameId);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import { getFileBase64, getSteamAppAsset } from "@main/helpers";
|
|||
import { DownloadManager } from "@main/services";
|
||||
import { Downloader } from "@shared";
|
||||
import { stateManager } from "@main/state-manager";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
const startGameDownload = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
|
@ -43,7 +44,10 @@ const startGameDownload = async (
|
|||
|
||||
if (!repack || game?.status === "active") return;
|
||||
|
||||
await gameRepository.update({ status: "active" }, { status: "paused" });
|
||||
await gameRepository.update(
|
||||
{ status: "active", progress: Not(1) },
|
||||
{ status: "paused" }
|
||||
);
|
||||
|
||||
if (game) {
|
||||
await gameRepository.update(
|
||||
|
|
|
@ -10,6 +10,8 @@ import { Notification } from "electron";
|
|||
import { t } from "i18next";
|
||||
import { Downloader } from "@shared";
|
||||
import { DownloadProgress } from "@types";
|
||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||
import { Game } from "@main/entity";
|
||||
|
||||
export class DownloadManager {
|
||||
private static downloads = new Map<number, string>();
|
||||
|
@ -94,17 +96,24 @@ export class DownloadManager {
|
|||
const progress =
|
||||
Number(status.completedLength) / Number(status.totalLength);
|
||||
|
||||
if (!downloadingMetadata) {
|
||||
const update: QueryDeepPartialEntity<Game> = {
|
||||
bytesDownloaded: Number(status.completedLength),
|
||||
fileSize: Number(status.totalLength),
|
||||
status: status.status,
|
||||
};
|
||||
|
||||
if (!isNaN(progress)) update.progress = progress;
|
||||
|
||||
await gameRepository.update(
|
||||
{ id: this.gameId },
|
||||
{
|
||||
progress:
|
||||
isNaN(progress) || downloadingMetadata ? undefined : progress,
|
||||
bytesDownloaded: Number(status.completedLength),
|
||||
fileSize: Number(status.totalLength),
|
||||
...update,
|
||||
status: status.status,
|
||||
folderName: this.getFolderName(status),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const game = await gameRepository.findOne({
|
||||
where: { id: this.gameId, isDeleted: false },
|
||||
|
|
|
@ -10,7 +10,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
|||
import { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal";
|
||||
import * as styles from "./downloads.css";
|
||||
import { DeleteModal } from "./delete-modal";
|
||||
import { Downloader, GameStatus, GameStatusHelper, formatBytes } from "@shared";
|
||||
import { Downloader, formatBytes } from "@shared";
|
||||
|
||||
export function Downloads() {
|
||||
const { library, updateLibrary } = useLibrary();
|
||||
|
@ -26,6 +26,7 @@ export function Downloads() {
|
|||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||
|
||||
const {
|
||||
lastPacket,
|
||||
progress,
|
||||
pauseDownload,
|
||||
resumeDownload,
|
||||
|
@ -50,13 +51,13 @@ export function Downloads() {
|
|||
});
|
||||
|
||||
const getFinalDownloadSize = (game: Game) => {
|
||||
const isGameDownloading = gameDownloading?.id === game?.id;
|
||||
const isGameDownloading = lastPacket?.game.id === game?.id;
|
||||
|
||||
if (!game) return "N/A";
|
||||
if (game.fileSize) return formatBytes(game.fileSize);
|
||||
|
||||
if (gameDownloading?.fileSize && isGameDownloading)
|
||||
return formatBytes(gameDownloading.fileSize);
|
||||
if (lastPacket?.game.fileSize && isGameDownloading)
|
||||
return formatBytes(lastPacket?.game.fileSize);
|
||||
|
||||
return game.repack?.fileSize ?? "N/A";
|
||||
};
|
||||
|
@ -67,7 +68,7 @@ export function Downloads() {
|
|||
};
|
||||
|
||||
const getGameInfo = (game: Game) => {
|
||||
const isGameDownloading = gameDownloading?.id === game?.id;
|
||||
const isGameDownloading = lastPacket?.game.id === game?.id;
|
||||
const finalDownloadSize = getFinalDownloadSize(game);
|
||||
|
||||
if (isGameDeleting(game?.id)) {
|
||||
|
@ -79,27 +80,21 @@ export function Downloads() {
|
|||
<>
|
||||
<p>{progress}</p>
|
||||
|
||||
{gameDownloading?.status &&
|
||||
gameDownloading?.status !== GameStatus.Downloading ? (
|
||||
<p>{t(gameDownloading?.status)}</p>
|
||||
) : (
|
||||
<>
|
||||
<p>
|
||||
{formatBytes(gameDownloading?.bytesDownloaded)} /{" "}
|
||||
{formatBytes(lastPacket?.game.bytesDownloaded)} /{" "}
|
||||
{finalDownloadSize}
|
||||
</p>
|
||||
|
||||
{game.downloader === Downloader.Torrent && (
|
||||
<p>
|
||||
{numPeers} peers / {numSeeds} seeds
|
||||
{lastPacket?.numPeers} peers / {lastPacket?.numSeeds} seeds
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (GameStatusHelper.isReady(game?.status)) {
|
||||
if (game?.progress === 1) {
|
||||
return (
|
||||
<>
|
||||
<p>{game?.repack?.title}</p>
|
||||
|
@ -107,11 +102,9 @@ export function Downloads() {
|
|||
</>
|
||||
);
|
||||
}
|
||||
if (game?.status === GameStatus.Cancelled) return <p>{t("cancelled")}</p>;
|
||||
if (game?.status === GameStatus.DownloadingMetadata)
|
||||
return <p>{t("starting_download")}</p>;
|
||||
if (game?.status === "removed") return <p>{t("cancelled")}</p>;
|
||||
|
||||
if (game?.status === GameStatus.Paused) {
|
||||
if (game?.status === "paused") {
|
||||
return (
|
||||
<>
|
||||
<p>{formatDownloadProgress(game.progress)}</p>
|
||||
|
@ -129,7 +122,7 @@ export function Downloads() {
|
|||
};
|
||||
|
||||
const getGameActions = (game: Game) => {
|
||||
const isGameDownloading = gameDownloading?.id === game?.id;
|
||||
const isGameDownloading = lastPacket?.game.id === game?.id;
|
||||
|
||||
const deleting = isGameDeleting(game.id);
|
||||
|
||||
|
@ -146,7 +139,7 @@ export function Downloads() {
|
|||
);
|
||||
}
|
||||
|
||||
if (game?.status === GameStatus.Paused) {
|
||||
if (game?.status === "paused") {
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => resumeDownload(game.id)} theme="outline">
|
||||
|
@ -159,7 +152,7 @@ export function Downloads() {
|
|||
);
|
||||
}
|
||||
|
||||
if (GameStatusHelper.isReady(game?.status)) {
|
||||
if (game?.progress === 1) {
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
|
@ -177,14 +170,6 @@ export function Downloads() {
|
|||
);
|
||||
}
|
||||
|
||||
if (game?.status === GameStatus.DownloadingMetadata) {
|
||||
return (
|
||||
<Button onClick={() => cancelDownload(game.id)} theme="outline">
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
|
@ -242,7 +227,7 @@ export function Downloads() {
|
|||
<li
|
||||
key={game.id}
|
||||
className={styles.download({
|
||||
cancelled: game.status === GameStatus.Cancelled,
|
||||
cancelled: game.status === "removed",
|
||||
})}
|
||||
>
|
||||
<img
|
||||
|
|
|
@ -38,7 +38,9 @@ export function HeroPanel() {
|
|||
|
||||
if (game?.progress === 1) return <HeroPanelPlaytime />;
|
||||
|
||||
if (game?.status === "active") {
|
||||
console.log(lastPacket?.game.id, game?.id);
|
||||
|
||||
if (game?.status === "active" && lastPacket?.game.id === game?.id) {
|
||||
if (lastPacket?.downloadingMetadata) {
|
||||
return <p>{t("downloading_metadata")}</p>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue