mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
fix: fixing download cancel
This commit is contained in:
parent
ae159a4d44
commit
ba6eb2ecc8
3 changed files with 38 additions and 32 deletions
|
@ -2,7 +2,7 @@ import { registerEvent } from "../register-event";
|
||||||
|
|
||||||
import { DownloadManager } from "@main/services";
|
import { DownloadManager } from "@main/services";
|
||||||
import { GameShop } from "@types";
|
import { GameShop } from "@types";
|
||||||
import { downloadsSublevel, levelKeys } from "@main/level";
|
import { levelKeys } from "@main/level";
|
||||||
|
|
||||||
const cancelGameDownload = async (
|
const cancelGameDownload = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
@ -12,8 +12,6 @@ const cancelGameDownload = async (
|
||||||
const downloadKey = levelKeys.game(shop, objectId);
|
const downloadKey = levelKeys.game(shop, objectId);
|
||||||
|
|
||||||
await DownloadManager.cancelDownload(downloadKey);
|
await DownloadManager.cancelDownload(downloadKey);
|
||||||
|
|
||||||
await downloadsSublevel.del(downloadKey);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("cancelGameDownload", cancelGameDownload);
|
registerEvent("cancelGameDownload", cancelGameDownload);
|
||||||
|
|
|
@ -228,14 +228,17 @@ export class DownloadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async cancelDownload(downloadKey = this.downloadingGameId) {
|
static async cancelDownload(downloadKey = this.downloadingGameId) {
|
||||||
await PythonRPC.rpc.post("/action", {
|
await PythonRPC.rpc
|
||||||
|
.post("/action", {
|
||||||
action: "cancel",
|
action: "cancel",
|
||||||
game_id: downloadKey,
|
game_id: downloadKey,
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
logger.error("Failed to cancel game download", err);
|
||||||
});
|
});
|
||||||
|
|
||||||
WindowManager.mainWindow?.setProgressBar(-1);
|
|
||||||
|
|
||||||
if (downloadKey === this.downloadingGameId) {
|
if (downloadKey === this.downloadingGameId) {
|
||||||
|
WindowManager.mainWindow?.setProgressBar(-1);
|
||||||
WindowManager.mainWindow?.webContents.send("on-download-progress", null);
|
WindowManager.mainWindow?.webContents.send("on-download-progress", null);
|
||||||
this.downloadingGameId = null;
|
this.downloadingGameId = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,9 @@ export function DownloadSettingsModal({
|
||||||
(state) => state.userPreferences.value
|
(state) => state.userPreferences.value
|
||||||
);
|
);
|
||||||
|
|
||||||
const getDiskFreeSpace = (path: string) => {
|
const getDiskFreeSpace = async (path: string) => {
|
||||||
window.electron.getDiskFreeSpace(path).then((result) => {
|
const result = await window.electron.getDiskFreeSpace(path);
|
||||||
setDiskFreeSpace(result.free);
|
setDiskFreeSpace(result.free);
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkFolderWritePermission = useCallback(
|
const checkFolderWritePermission = useCallback(
|
||||||
|
@ -100,6 +99,7 @@ export function DownloadSettingsModal({
|
||||||
userPreferences?.downloadsPath,
|
userPreferences?.downloadsPath,
|
||||||
downloaders,
|
downloaders,
|
||||||
userPreferences?.realDebridApiToken,
|
userPreferences?.realDebridApiToken,
|
||||||
|
userPreferences?.torBoxApiToken,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const handleChooseDownloadsPath = async () => {
|
const handleChooseDownloadsPath = async () => {
|
||||||
|
@ -155,17 +155,21 @@ export function DownloadSettingsModal({
|
||||||
<span>{t("downloader")}</span>
|
<span>{t("downloader")}</span>
|
||||||
|
|
||||||
<div className="download-settings-modal__downloaders">
|
<div className="download-settings-modal__downloaders">
|
||||||
{downloaders.map((downloader) => (
|
{downloaders.map((downloader) => {
|
||||||
|
const shouldDisableButton =
|
||||||
|
(downloader === Downloader.RealDebrid &&
|
||||||
|
!userPreferences?.realDebridApiToken) ||
|
||||||
|
(downloader === Downloader.TorBox &&
|
||||||
|
!userPreferences?.torBoxApiToken);
|
||||||
|
|
||||||
|
return (
|
||||||
<Button
|
<Button
|
||||||
key={downloader}
|
key={downloader}
|
||||||
className="download-settings-modal__downloader-option"
|
className="download-settings-modal__downloader-option"
|
||||||
theme={
|
theme={
|
||||||
selectedDownloader === downloader ? "primary" : "outline"
|
selectedDownloader === downloader ? "primary" : "outline"
|
||||||
}
|
}
|
||||||
disabled={
|
disabled={shouldDisableButton}
|
||||||
downloader === Downloader.RealDebrid &&
|
|
||||||
!userPreferences?.realDebridApiToken
|
|
||||||
}
|
|
||||||
onClick={() => setSelectedDownloader(downloader)}
|
onClick={() => setSelectedDownloader(downloader)}
|
||||||
>
|
>
|
||||||
{selectedDownloader === downloader && (
|
{selectedDownloader === downloader && (
|
||||||
|
@ -173,7 +177,8 @@ export function DownloadSettingsModal({
|
||||||
)}
|
)}
|
||||||
{DOWNLOADER_NAME[downloader]}
|
{DOWNLOADER_NAME[downloader]}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue