From 50c3503e375a18868dcf5695fcc7833ab5e1930b Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Thu, 30 May 2024 00:17:17 +0100 Subject: [PATCH] chore: disabling resuming real debrid downloads when real debrid is not set --- .../pages/downloads/delete-game-modal.css.ts | 10 + .../src/pages/downloads/delete-game-modal.tsx | 43 +++++ .../modals/download-settings-modal.css.ts | 34 ++++ .../modals/download-settings-modal.tsx | 177 ++++++++++++++++++ 4 files changed, 264 insertions(+) create mode 100644 src/renderer/src/pages/downloads/delete-game-modal.css.ts create mode 100644 src/renderer/src/pages/downloads/delete-game-modal.tsx create mode 100644 src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts create mode 100644 src/renderer/src/pages/game-details/modals/download-settings-modal.tsx diff --git a/src/renderer/src/pages/downloads/delete-game-modal.css.ts b/src/renderer/src/pages/downloads/delete-game-modal.css.ts new file mode 100644 index 00000000..ef0ba179 --- /dev/null +++ b/src/renderer/src/pages/downloads/delete-game-modal.css.ts @@ -0,0 +1,10 @@ +import { SPACING_UNIT } from "../../theme.css"; +import { style } from "@vanilla-extract/css"; + +export const deleteActionsButtonsCtn = style({ + display: "flex", + width: "100%", + justifyContent: "end", + alignItems: "center", + gap: `${SPACING_UNIT}px`, +}); diff --git a/src/renderer/src/pages/downloads/delete-game-modal.tsx b/src/renderer/src/pages/downloads/delete-game-modal.tsx new file mode 100644 index 00000000..e4ff7f9e --- /dev/null +++ b/src/renderer/src/pages/downloads/delete-game-modal.tsx @@ -0,0 +1,43 @@ +import { useTranslation } from "react-i18next"; + +import { Button, Modal } from "@renderer/components"; + +import * as styles from "./delete-game-modal.css"; + +interface DeleteGameModalProps { + visible: boolean; + onClose: () => void; + deleteGame: () => void; +} + +export function DeleteGameModal({ + onClose, + visible, + deleteGame, +}: DeleteGameModalProps) { + const { t } = useTranslation("downloads"); + + const handleDeleteGame = () => { + deleteGame(); + onClose(); + }; + + return ( + +
+ + + +
+
+ ); +} diff --git a/src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts b/src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts new file mode 100644 index 00000000..3c52cf56 --- /dev/null +++ b/src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts @@ -0,0 +1,34 @@ +import { style } from "@vanilla-extract/css"; +import { SPACING_UNIT, vars } from "../../../theme.css"; + +export const container = style({ + display: "flex", + flexDirection: "column", + gap: `${SPACING_UNIT * 3}px`, + width: "100%", +}); + +export const downloadsPathField = style({ + display: "flex", + gap: `${SPACING_UNIT}px`, +}); + +export const hintText = style({ + fontSize: "12px", + color: vars.color.body, +}); + +export const downloaders = style({ + display: "flex", + gap: `${SPACING_UNIT}px`, +}); + +export const downloaderOption = style({ + flex: "1", + position: "relative", +}); + +export const downloaderIcon = style({ + position: "absolute", + left: `${SPACING_UNIT * 2}px`, +}); diff --git a/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx b/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx new file mode 100644 index 00000000..ef4ba040 --- /dev/null +++ b/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx @@ -0,0 +1,177 @@ +import { useEffect, useState } from "react"; +import { Trans, useTranslation } from "react-i18next"; + +import { DiskSpace } from "check-disk-space"; +import * as styles from "./download-settings-modal.css"; +import { Button, Link, Modal, TextField } from "@renderer/components"; +import { CheckCircleFillIcon, DownloadIcon } from "@primer/octicons-react"; +import { Downloader, formatBytes } from "@shared"; + +import type { GameRepack } from "@types"; +import { SPACING_UNIT } from "@renderer/theme.css"; +import { DOWNLOADER_NAME } from "@renderer/constants"; +import { useAppSelector } from "@renderer/hooks"; + +export interface DownloadSettingsModalProps { + visible: boolean; + onClose: () => void; + startDownload: ( + repack: GameRepack, + downloader: Downloader, + downloadPath: string + ) => Promise; + repack: GameRepack | null; +} + +const downloaders = [Downloader.Torrent, Downloader.RealDebrid]; + +export function DownloadSettingsModal({ + visible, + onClose, + startDownload, + repack, +}: DownloadSettingsModalProps) { + const { t } = useTranslation("game_details"); + + const [diskFreeSpace, setDiskFreeSpace] = useState(null); + const [selectedPath, setSelectedPath] = useState(""); + const [downloadStarting, setDownloadStarting] = useState(false); + const [selectedDownloader, setSelectedDownloader] = useState( + Downloader.Torrent + ); + + const userPreferences = useAppSelector( + (state) => state.userPreferences.value + ); + + useEffect(() => { + if (visible) { + getDiskFreeSpace(selectedPath); + } + }, [visible, selectedPath]); + + useEffect(() => { + if (userPreferences?.downloadsPath) { + setSelectedPath(userPreferences.downloadsPath); + } else { + window.electron + .getDefaultDownloadsPath() + .then((defaultDownloadsPath) => setSelectedPath(defaultDownloadsPath)); + } + + if (userPreferences?.realDebridApiToken) + setSelectedDownloader(Downloader.RealDebrid); + }, [userPreferences?.downloadsPath, userPreferences?.realDebridApiToken]); + + const getDiskFreeSpace = (path: string) => { + window.electron.getDiskFreeSpace(path).then((result) => { + setDiskFreeSpace(result); + }); + }; + + const handleChooseDownloadsPath = async () => { + const { filePaths } = await window.electron.showOpenDialog({ + defaultPath: selectedPath, + properties: ["openDirectory"], + }); + + if (filePaths && filePaths.length > 0) { + const path = filePaths[0]; + setSelectedPath(path); + } + }; + + const handleStartClick = () => { + if (repack) { + setDownloadStarting(true); + + startDownload(repack, selectedDownloader, selectedPath).finally(() => { + setDownloadStarting(false); + onClose(); + }); + } + }; + + return ( + +
+
+ + {t("downloader")} + + +
+ {downloaders.map((downloader) => ( + + ))} +
+
+ +
+
+ + + +
+ +

+ + + +

+
+ + +
+
+ ); +}