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") {
|
if (game.status === "paused") {
|
||||||
await DownloadManager.pauseDownload();
|
await DownloadManager.pauseDownload();
|
||||||
|
|
||||||
await gameRepository.update({ status: "active" }, { status: "paused" });
|
await gameRepository.update({ id: gameId }, { status: "active" });
|
||||||
|
|
||||||
await DownloadManager.resumeDownload(gameId);
|
await DownloadManager.resumeDownload(gameId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { getFileBase64, getSteamAppAsset } from "@main/helpers";
|
||||||
import { DownloadManager } from "@main/services";
|
import { DownloadManager } from "@main/services";
|
||||||
import { Downloader } from "@shared";
|
import { Downloader } from "@shared";
|
||||||
import { stateManager } from "@main/state-manager";
|
import { stateManager } from "@main/state-manager";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
|
||||||
const startGameDownload = async (
|
const startGameDownload = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
@ -43,7 +44,10 @@ const startGameDownload = async (
|
||||||
|
|
||||||
if (!repack || game?.status === "active") return;
|
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) {
|
if (game) {
|
||||||
await gameRepository.update(
|
await gameRepository.update(
|
||||||
|
|
|
@ -10,6 +10,8 @@ import { Notification } from "electron";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import { Downloader } from "@shared";
|
import { Downloader } from "@shared";
|
||||||
import { DownloadProgress } from "@types";
|
import { DownloadProgress } from "@types";
|
||||||
|
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||||
|
import { Game } from "@main/entity";
|
||||||
|
|
||||||
export class DownloadManager {
|
export class DownloadManager {
|
||||||
private static downloads = new Map<number, string>();
|
private static downloads = new Map<number, string>();
|
||||||
|
@ -94,17 +96,24 @@ export class DownloadManager {
|
||||||
const progress =
|
const progress =
|
||||||
Number(status.completedLength) / Number(status.totalLength);
|
Number(status.completedLength) / Number(status.totalLength);
|
||||||
|
|
||||||
await gameRepository.update(
|
if (!downloadingMetadata) {
|
||||||
{ id: this.gameId },
|
const update: QueryDeepPartialEntity<Game> = {
|
||||||
{
|
|
||||||
progress:
|
|
||||||
isNaN(progress) || downloadingMetadata ? undefined : progress,
|
|
||||||
bytesDownloaded: Number(status.completedLength),
|
bytesDownloaded: Number(status.completedLength),
|
||||||
fileSize: Number(status.totalLength),
|
fileSize: Number(status.totalLength),
|
||||||
status: status.status,
|
status: status.status,
|
||||||
folderName: this.getFolderName(status),
|
};
|
||||||
}
|
|
||||||
);
|
if (!isNaN(progress)) update.progress = progress;
|
||||||
|
|
||||||
|
await gameRepository.update(
|
||||||
|
{ id: this.gameId },
|
||||||
|
{
|
||||||
|
...update,
|
||||||
|
status: status.status,
|
||||||
|
folderName: this.getFolderName(status),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const game = await gameRepository.findOne({
|
const game = await gameRepository.findOne({
|
||||||
where: { id: this.gameId, isDeleted: false },
|
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 { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal";
|
||||||
import * as styles from "./downloads.css";
|
import * as styles from "./downloads.css";
|
||||||
import { DeleteModal } from "./delete-modal";
|
import { DeleteModal } from "./delete-modal";
|
||||||
import { Downloader, GameStatus, GameStatusHelper, formatBytes } from "@shared";
|
import { Downloader, formatBytes } from "@shared";
|
||||||
|
|
||||||
export function Downloads() {
|
export function Downloads() {
|
||||||
const { library, updateLibrary } = useLibrary();
|
const { library, updateLibrary } = useLibrary();
|
||||||
|
@ -26,6 +26,7 @@ export function Downloads() {
|
||||||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
lastPacket,
|
||||||
progress,
|
progress,
|
||||||
pauseDownload,
|
pauseDownload,
|
||||||
resumeDownload,
|
resumeDownload,
|
||||||
|
@ -50,13 +51,13 @@ export function Downloads() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const getFinalDownloadSize = (game: Game) => {
|
const getFinalDownloadSize = (game: Game) => {
|
||||||
const isGameDownloading = gameDownloading?.id === game?.id;
|
const isGameDownloading = lastPacket?.game.id === game?.id;
|
||||||
|
|
||||||
if (!game) return "N/A";
|
if (!game) return "N/A";
|
||||||
if (game.fileSize) return formatBytes(game.fileSize);
|
if (game.fileSize) return formatBytes(game.fileSize);
|
||||||
|
|
||||||
if (gameDownloading?.fileSize && isGameDownloading)
|
if (lastPacket?.game.fileSize && isGameDownloading)
|
||||||
return formatBytes(gameDownloading.fileSize);
|
return formatBytes(lastPacket?.game.fileSize);
|
||||||
|
|
||||||
return game.repack?.fileSize ?? "N/A";
|
return game.repack?.fileSize ?? "N/A";
|
||||||
};
|
};
|
||||||
|
@ -67,7 +68,7 @@ export function Downloads() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGameInfo = (game: Game) => {
|
const getGameInfo = (game: Game) => {
|
||||||
const isGameDownloading = gameDownloading?.id === game?.id;
|
const isGameDownloading = lastPacket?.game.id === game?.id;
|
||||||
const finalDownloadSize = getFinalDownloadSize(game);
|
const finalDownloadSize = getFinalDownloadSize(game);
|
||||||
|
|
||||||
if (isGameDeleting(game?.id)) {
|
if (isGameDeleting(game?.id)) {
|
||||||
|
@ -79,27 +80,21 @@ export function Downloads() {
|
||||||
<>
|
<>
|
||||||
<p>{progress}</p>
|
<p>{progress}</p>
|
||||||
|
|
||||||
{gameDownloading?.status &&
|
<p>
|
||||||
gameDownloading?.status !== GameStatus.Downloading ? (
|
{formatBytes(lastPacket?.game.bytesDownloaded)} /{" "}
|
||||||
<p>{t(gameDownloading?.status)}</p>
|
{finalDownloadSize}
|
||||||
) : (
|
</p>
|
||||||
<>
|
|
||||||
<p>
|
{game.downloader === Downloader.Torrent && (
|
||||||
{formatBytes(gameDownloading?.bytesDownloaded)} /{" "}
|
<p>
|
||||||
{finalDownloadSize}
|
{lastPacket?.numPeers} peers / {lastPacket?.numSeeds} seeds
|
||||||
</p>
|
</p>
|
||||||
{game.downloader === Downloader.Torrent && (
|
|
||||||
<p>
|
|
||||||
{numPeers} peers / {numSeeds} seeds
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameStatusHelper.isReady(game?.status)) {
|
if (game?.progress === 1) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>{game?.repack?.title}</p>
|
<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 === "removed") return <p>{t("cancelled")}</p>;
|
||||||
if (game?.status === GameStatus.DownloadingMetadata)
|
|
||||||
return <p>{t("starting_download")}</p>;
|
|
||||||
|
|
||||||
if (game?.status === GameStatus.Paused) {
|
if (game?.status === "paused") {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>{formatDownloadProgress(game.progress)}</p>
|
<p>{formatDownloadProgress(game.progress)}</p>
|
||||||
|
@ -129,7 +122,7 @@ export function Downloads() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGameActions = (game: Game) => {
|
const getGameActions = (game: Game) => {
|
||||||
const isGameDownloading = gameDownloading?.id === game?.id;
|
const isGameDownloading = lastPacket?.game.id === game?.id;
|
||||||
|
|
||||||
const deleting = isGameDeleting(game.id);
|
const deleting = isGameDeleting(game.id);
|
||||||
|
|
||||||
|
@ -146,7 +139,7 @@ export function Downloads() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === GameStatus.Paused) {
|
if (game?.status === "paused") {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button onClick={() => resumeDownload(game.id)} theme="outline">
|
<Button onClick={() => resumeDownload(game.id)} theme="outline">
|
||||||
|
@ -159,7 +152,7 @@ export function Downloads() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameStatusHelper.isReady(game?.status)) {
|
if (game?.progress === 1) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
|
@ -242,7 +227,7 @@ export function Downloads() {
|
||||||
<li
|
<li
|
||||||
key={game.id}
|
key={game.id}
|
||||||
className={styles.download({
|
className={styles.download({
|
||||||
cancelled: game.status === GameStatus.Cancelled,
|
cancelled: game.status === "removed",
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
|
|
|
@ -38,7 +38,9 @@ export function HeroPanel() {
|
||||||
|
|
||||||
if (game?.progress === 1) return <HeroPanelPlaytime />;
|
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) {
|
if (lastPacket?.downloadingMetadata) {
|
||||||
return <p>{t("downloading_metadata")}</p>;
|
return <p>{t("downloading_metadata")}</p>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue