Merge pull request #706 from hydralauncher/feature/libtorrent-reloaded-remake-remaster

Feature/libtorrent reloaded remake remaster
This commit is contained in:
Chubby Granny Chaser 2024-06-28 15:21:45 +01:00 committed by GitHub
commit 2a44313d84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 1675 additions and 1364 deletions

View file

@ -32,8 +32,17 @@ export function BottomPanel() {
const status = useMemo(() => {
if (isGameDownloading) {
if (lastPacket?.isCheckingFiles)
return t("checking_files", {
title: lastPacket?.game.title,
percentage: progress,
});
if (lastPacket?.isDownloadingMetadata)
return t("downloading_metadata", { title: lastPacket?.game.title });
return t("downloading_metadata", {
title: lastPacket?.game.title,
percentage: progress,
});
if (!eta) {
return t("calculating_eta", {
@ -56,6 +65,7 @@ export function BottomPanel() {
isGameDownloading,
lastPacket?.game,
lastPacket?.isDownloadingMetadata,
lastPacket?.isCheckingFiles,
progress,
eta,
downloadSpeed,

View file

@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router-dom";
@ -14,6 +14,7 @@ import { buildGameDetailsPath } from "@renderer/helpers";
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
import { SidebarProfile } from "./sidebar-profile";
import { sortBy } from "lodash-es";
const SIDEBAR_MIN_WIDTH = 200;
const SIDEBAR_INITIAL_WIDTH = 250;
@ -35,6 +36,10 @@ export function Sidebar() {
const location = useLocation();
const sortedLibrary = useMemo(() => {
return sortBy(library, (game) => game.title);
}, [library]);
const { lastPacket, progress } = useDownload();
const { showWarningToast } = useToast();
@ -43,7 +48,7 @@ export function Sidebar() {
updateLibrary();
}, [lastPacket?.game.id, updateLibrary]);
const isDownloading = library.some(
const isDownloading = sortedLibrary.some(
(game) => game.status === "active" && game.progress !== 1
);
@ -63,7 +68,7 @@ export function Sidebar() {
const handleFilter: React.ChangeEventHandler<HTMLInputElement> = (event) => {
setFilteredLibrary(
library.filter((game) =>
sortedLibrary.filter((game) =>
game.title
.toLowerCase()
.includes(event.target.value.toLocaleLowerCase())
@ -72,8 +77,8 @@ export function Sidebar() {
};
useEffect(() => {
setFilteredLibrary(library);
}, [library]);
setFilteredLibrary(sortedLibrary);
}, [sortedLibrary]);
useEffect(() => {
window.onmousemove = (event: MouseEvent) => {

View file

@ -22,13 +22,14 @@ export function useDownload() {
);
const dispatch = useAppDispatch();
const startDownload = (payload: StartGameDownloadPayload) =>
const startDownload = (payload: StartGameDownloadPayload) => {
dispatch(clearDownload());
window.electron.startGameDownload(payload).then((game) => {
dispatch(clearDownload());
updateLibrary();
return game;
});
};
const pauseDownload = async (gameId: number) => {
await window.electron.pauseGameDownload(gameId);
@ -65,7 +66,7 @@ export function useDownload() {
updateLibrary();
});
const getETA = () => {
const calculateETA = () => {
if (!lastPacket || lastPacket.timeRemaining < 0) return "";
try {
@ -85,9 +86,9 @@ export function useDownload() {
return {
downloadSpeed: `${formatBytes(lastPacket?.downloadSpeed ?? 0)}/s`,
progress: formatDownloadProgress(lastPacket?.game.progress),
progress: formatDownloadProgress(lastPacket?.progress ?? 0),
lastPacket,
eta: getETA(),
eta: calculateETA(),
startDownload,
pauseDownload,
resumeDownload,

View file

@ -67,6 +67,19 @@ export function DownloadGroup({
}
if (isGameDownloading) {
if (lastPacket?.isDownloadingMetadata) {
return <p>{t("downloading_metadata")}</p>;
}
if (lastPacket?.isCheckingFiles) {
return (
<>
<p>{progress}</p>
<p>{t("checking_files")}</p>
</>
);
}
return (
<>
<p>{progress}</p>
@ -110,7 +123,7 @@ export function DownloadGroup({
);
}
return <p>{t(game.status)}</p>;
return <p>{t(game.status as string)}</p>;
};
const getGameActions = (game: LibraryGame) => {

View file

@ -54,7 +54,7 @@ export function HeroPanelPlaytime() {
if (!game) return null;
const hasDownload =
["active", "paused"].includes(game.status) && game.progress !== 1;
["active", "paused"].includes(game.status as string) && game.progress !== 1;
const isGameDownloading =
game.status === "active" && lastPacket?.game.id === game.id;

View file

@ -23,7 +23,7 @@ export function GameOptionsModal({
const { showSuccessToast, showErrorToast } = useToast();
const { updateGame, setShowRepacksModal, selectGameExecutable } =
const { updateGame, setShowRepacksModal, repacks, selectGameExecutable } =
useContext(gameDetailsContext);
const [showDeleteModal, setShowDeleteModal] = useState(false);
@ -156,7 +156,7 @@ export function GameOptionsModal({
<Button
onClick={() => setShowRepacksModal(true)}
theme="outline"
disabled={deleting || isGameDownloading}
disabled={deleting || isGameDownloading || !repacks.length}
>
{t("open_download_options")}
</Button>