fix: fixing download cancel

This commit is contained in:
Chubby Granny Chaser 2025-02-16 03:01:47 +00:00
parent ae159a4d44
commit ba6eb2ecc8
No known key found for this signature in database
3 changed files with 38 additions and 32 deletions

View file

@ -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);

View file

@ -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
action: "cancel", .post("/action", {
game_id: downloadKey, action: "cancel",
}); game_id: downloadKey,
})
WindowManager.mainWindow?.setProgressBar(-1); .catch((err) => {
logger.error("Failed to cancel game download", err);
});
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;
} }

View file

@ -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,25 +155,30 @@ 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) => {
<Button const shouldDisableButton =
key={downloader} (downloader === Downloader.RealDebrid &&
className="download-settings-modal__downloader-option" !userPreferences?.realDebridApiToken) ||
theme={ (downloader === Downloader.TorBox &&
selectedDownloader === downloader ? "primary" : "outline" !userPreferences?.torBoxApiToken);
}
disabled={ return (
downloader === Downloader.RealDebrid && <Button
!userPreferences?.realDebridApiToken key={downloader}
} className="download-settings-modal__downloader-option"
onClick={() => setSelectedDownloader(downloader)} theme={
> selectedDownloader === downloader ? "primary" : "outline"
{selectedDownloader === downloader && ( }
<CheckCircleFillIcon className="download-settings-modal__downloader-icon" /> disabled={shouldDisableButton}
)} onClick={() => setSelectedDownloader(downloader)}
{DOWNLOADER_NAME[downloader]} >
</Button> {selectedDownloader === downloader && (
))} <CheckCircleFillIcon className="download-settings-modal__downloader-icon" />
)}
{DOWNLOADER_NAME[downloader]}
</Button>
);
})}
</div> </div>
</div> </div>