mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: added helper functions to the game status to keep it simple to read.
This commit is contained in:
parent
666b1afcb6
commit
f1d2a88442
@ -7,4 +7,20 @@ export enum GameStatus {
|
|||||||
Cancelled = "cancelled",
|
Cancelled = "cancelled",
|
||||||
Finished = "finished",
|
Finished = "finished",
|
||||||
Decompressing = "decompressing",
|
Decompressing = "decompressing",
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace GameStatus {
|
||||||
|
export const isDownloading = (status: GameStatus | "") =>
|
||||||
|
status === GameStatus.Downloading ||
|
||||||
|
status === GameStatus.DownloadingMetadata ||
|
||||||
|
status === GameStatus.CheckingFiles;
|
||||||
|
|
||||||
|
export const isVerifying = (status: GameStatus | "") =>
|
||||||
|
GameStatus.DownloadingMetadata == status ||
|
||||||
|
GameStatus.CheckingFiles == status ||
|
||||||
|
GameStatus.Decompressing == status;
|
||||||
|
|
||||||
|
export const isReady = (status: GameStatus | "") =>
|
||||||
|
status === GameStatus.Finished ||
|
||||||
|
status === GameStatus.Seeding;
|
||||||
}
|
}
|
@ -20,6 +20,8 @@ const cancelGameDownload = async (
|
|||||||
GameStatus.CheckingFiles,
|
GameStatus.CheckingFiles,
|
||||||
GameStatus.Paused,
|
GameStatus.Paused,
|
||||||
GameStatus.Seeding,
|
GameStatus.Seeding,
|
||||||
|
GameStatus.Finished,
|
||||||
|
GameStatus.Decompressing,
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -7,6 +7,7 @@ import { vars } from "@renderer/theme.css";
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { VERSION_CODENAME } from "@renderer/constants";
|
import { VERSION_CODENAME } from "@renderer/constants";
|
||||||
|
import { GameStatus } from "@globals";
|
||||||
|
|
||||||
export function BottomPanel() {
|
export function BottomPanel() {
|
||||||
const { t } = useTranslation("bottom_panel");
|
const { t } = useTranslation("bottom_panel");
|
||||||
@ -23,10 +24,10 @@ export function BottomPanel() {
|
|||||||
|
|
||||||
const status = useMemo(() => {
|
const status = useMemo(() => {
|
||||||
if (isDownloading) {
|
if (isDownloading) {
|
||||||
if (game.status === "downloading_metadata")
|
if (game.status === GameStatus.DownloadingMetadata)
|
||||||
return t("downloading_metadata", { title: game.title });
|
return t("downloading_metadata", { title: game.title });
|
||||||
|
|
||||||
if (game.status === "checking_files")
|
if (game.status === GameStatus.CheckingFiles)
|
||||||
return t("checking_files", {
|
return t("checking_files", {
|
||||||
title: game.title,
|
title: game.title,
|
||||||
percentage: progress,
|
percentage: progress,
|
||||||
|
@ -14,6 +14,7 @@ import { MarkGithubIcon } from "@primer/octicons-react";
|
|||||||
import DiscordLogo from "@renderer/assets/discord-icon.svg";
|
import DiscordLogo from "@renderer/assets/discord-icon.svg";
|
||||||
import XLogo from "@renderer/assets/x-icon.svg";
|
import XLogo from "@renderer/assets/x-icon.svg";
|
||||||
import * as styles from "./sidebar.css";
|
import * as styles from "./sidebar.css";
|
||||||
|
import { GameStatus } from "@globals";
|
||||||
|
|
||||||
const socials = [
|
const socials = [
|
||||||
{
|
{
|
||||||
@ -57,9 +58,7 @@ export function Sidebar() {
|
|||||||
}, [gameDownloading?.id, updateLibrary]);
|
}, [gameDownloading?.id, updateLibrary]);
|
||||||
|
|
||||||
const isDownloading = library.some((game) =>
|
const isDownloading = library.some((game) =>
|
||||||
["downloading", "checking_files", "downloading_metadata"].includes(
|
GameStatus.isDownloading(game.status)
|
||||||
game.status
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const sidebarRef = useRef<HTMLElement>(null);
|
const sidebarRef = useRef<HTMLElement>(null);
|
||||||
@ -118,12 +117,10 @@ export function Sidebar() {
|
|||||||
}, [isResizing]);
|
}, [isResizing]);
|
||||||
|
|
||||||
const getGameTitle = (game: Game) => {
|
const getGameTitle = (game: Game) => {
|
||||||
if (game.status === "paused") return t("paused", { title: game.title });
|
if (game.status === GameStatus.Paused) return t("paused", { title: game.title });
|
||||||
|
|
||||||
if (gameDownloading?.id === game.id) {
|
if (gameDownloading?.id === game.id) {
|
||||||
const isVerifying = ["downloading_metadata", "checking_files"].includes(
|
const isVerifying = GameStatus.isVerifying(gameDownloading.status);
|
||||||
gameDownloading?.status
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isVerifying)
|
if (isVerifying)
|
||||||
return t(gameDownloading.status, {
|
return t(gameDownloading.status, {
|
||||||
@ -203,7 +200,7 @@ export function Sidebar() {
|
|||||||
className={styles.menuItem({
|
className={styles.menuItem({
|
||||||
active:
|
active:
|
||||||
location.pathname === `/game/${game.shop}/${game.objectID}`,
|
location.pathname === `/game/${game.shop}/${game.objectID}`,
|
||||||
muted: game.status === "cancelled",
|
muted: game.status === GameStatus.Cancelled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
@ -64,10 +64,7 @@ export function useDownload() {
|
|||||||
updateLibrary();
|
updateLibrary();
|
||||||
});
|
});
|
||||||
|
|
||||||
const isVerifying =
|
const isVerifying = GameStatus.isVerifying(lastPacket?.game.status);
|
||||||
GameStatus.DownloadingMetadata == lastPacket?.game.status ||
|
|
||||||
GameStatus.CheckingFiles == lastPacket?.game.status ||
|
|
||||||
GameStatus.Decompressing == lastPacket?.game.status;
|
|
||||||
|
|
||||||
const getETA = () => {
|
const getETA = () => {
|
||||||
if (isVerifying || !isFinite(lastPacket?.timeRemaining)) {
|
if (isVerifying || !isFinite(lastPacket?.timeRemaining)) {
|
||||||
|
@ -11,6 +11,7 @@ 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 { formatBytes } from "@renderer/utils";
|
import { formatBytes } from "@renderer/utils";
|
||||||
|
import { GameStatus } from "@globals";
|
||||||
|
|
||||||
export function Downloads() {
|
export function Downloads() {
|
||||||
const { library, updateLibrary } = useLibrary();
|
const { library, updateLibrary } = useLibrary();
|
||||||
@ -82,7 +83,7 @@ export function Downloads() {
|
|||||||
<>
|
<>
|
||||||
<p>{progress}</p>
|
<p>{progress}</p>
|
||||||
|
|
||||||
{gameDownloading?.status !== "downloading" ? (
|
{gameDownloading?.status !== GameStatus.Downloading ? (
|
||||||
<p>{t(gameDownloading?.status)}</p>
|
<p>{t(gameDownloading?.status)}</p>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
@ -99,7 +100,7 @@ export function Downloads() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "seeding") {
|
if (GameStatus.isReady(game?.status)) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>{game?.repack.title}</p>
|
<p>{game?.repack.title}</p>
|
||||||
@ -107,11 +108,11 @@ export function Downloads() {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (game?.status === "cancelled") return <p>{t("cancelled")}</p>;
|
if (game?.status === GameStatus.Cancelled) return <p>{t("cancelled")}</p>;
|
||||||
if (game?.status === "downloading_metadata")
|
if (game?.status === GameStatus.DownloadingMetadata)
|
||||||
return <p>{t("starting_download")}</p>;
|
return <p>{t("starting_download")}</p>;
|
||||||
|
|
||||||
if (game?.status === "paused") {
|
if (game?.status === GameStatus.Paused) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>{formatDownloadProgress(game.progress)}</p>
|
<p>{formatDownloadProgress(game.progress)}</p>
|
||||||
@ -144,7 +145,7 @@ export function Downloads() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "paused") {
|
if (game?.status === GameStatus.Paused) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button onClick={() => resumeDownload(game.id)} theme="outline">
|
<Button onClick={() => resumeDownload(game.id)} theme="outline">
|
||||||
@ -157,7 +158,7 @@ export function Downloads() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "seeding") {
|
if (GameStatus.isReady(game?.status)) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
@ -175,7 +176,7 @@ export function Downloads() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "downloading_metadata") {
|
if (game?.status === GameStatus.DownloadingMetadata) {
|
||||||
return (
|
return (
|
||||||
<Button onClick={() => cancelDownload(game.id)} theme="outline">
|
<Button onClick={() => cancelDownload(game.id)} theme="outline">
|
||||||
{t("cancel")}
|
{t("cancel")}
|
||||||
@ -236,7 +237,7 @@ export function Downloads() {
|
|||||||
<li
|
<li
|
||||||
key={game.id}
|
key={game.id}
|
||||||
className={styles.download({
|
className={styles.download({
|
||||||
cancelled: game.status === "cancelled",
|
cancelled: game.status === GameStatus.Cancelled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<AsyncImage
|
<AsyncImage
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { GameStatus } from "@globals";
|
||||||
import { NoEntryIcon, PlusCircleIcon } from "@primer/octicons-react";
|
import { NoEntryIcon, PlusCircleIcon } from "@primer/octicons-react";
|
||||||
|
|
||||||
import { Button } from "@renderer/components";
|
import { Button } from "@renderer/components";
|
||||||
@ -135,7 +136,7 @@ export function HeroPanelActions({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "paused") {
|
if (game?.status === GameStatus.Paused) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button onClick={() => resumeDownload(game.id)} theme="outline">
|
<Button onClick={() => resumeDownload(game.id)} theme="outline">
|
||||||
@ -151,10 +152,10 @@ export function HeroPanelActions({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "seeding" || (game && !game.status)) {
|
if (GameStatus.isReady(game?.status) || (game && !game.status)) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{game?.status === "seeding" ? (
|
{GameStatus.isReady(game?.status) ? (
|
||||||
<Button
|
<Button
|
||||||
onClick={openGameInstaller}
|
onClick={openGameInstaller}
|
||||||
theme="outline"
|
theme="outline"
|
||||||
@ -183,7 +184,7 @@ export function HeroPanelActions({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "cancelled") {
|
if (game?.status === GameStatus.Cancelled) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button onClick={openRepacksModal} theme="outline" disabled={deleting}>
|
<Button onClick={openRepacksModal} theme="outline" disabled={deleting}>
|
||||||
|
@ -11,6 +11,7 @@ import * as styles from "./hero-panel.css";
|
|||||||
import { useDate } from "@renderer/hooks/use-date";
|
import { useDate } from "@renderer/hooks/use-date";
|
||||||
import { formatBytes } from "@renderer/utils";
|
import { formatBytes } from "@renderer/utils";
|
||||||
import { HeroPanelActions } from "./hero-panel-actions";
|
import { HeroPanelActions } from "./hero-panel-actions";
|
||||||
|
import { GameStatus } from "@globals";
|
||||||
|
|
||||||
export interface HeroPanelProps {
|
export interface HeroPanelProps {
|
||||||
game: Game | null;
|
game: Game | null;
|
||||||
@ -94,7 +95,7 @@ export function HeroPanel({
|
|||||||
{eta && <small>{t("eta", { eta })}</small>}
|
{eta && <small>{t("eta", { eta })}</small>}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{gameDownloading?.status !== "downloading" ? (
|
{gameDownloading?.status !== GameStatus.Downloading ? (
|
||||||
<>
|
<>
|
||||||
<p>{t(gameDownloading?.status)}</p>
|
<p>{t(gameDownloading?.status)}</p>
|
||||||
{eta && <small>{t("eta", { eta })}</small>}
|
{eta && <small>{t("eta", { eta })}</small>}
|
||||||
@ -112,7 +113,7 @@ export function HeroPanel({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "paused") {
|
if (game?.status === GameStatus.Paused) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>
|
<p>
|
||||||
@ -127,7 +128,7 @@ export function HeroPanel({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game?.status === "seeding" || (game && !game.status)) {
|
if (GameStatus.isReady(game?.status) || (game && !game.status)) {
|
||||||
if (!game.lastTimePlayed) {
|
if (!game.lastTimePlayed) {
|
||||||
return <p>{t("not_played_yet", { title: game.title })}</p>;
|
return <p>{t("not_played_yet", { title: game.title })}</p>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user