diff --git a/electron/electron-down.js b/electron/electron-down.js index c0621ffbb..b01059353 100644 --- a/electron/electron-down.js +++ b/electron/electron-down.js @@ -2,7 +2,7 @@ const {BrowserWindow, screen, shell, ipcMain} = require('electron') const fs = require('fs'); const path = require('path'); const loger = require("electron-log"); -const {default: electronDl, download, CancelError} = require("@dootask/electron-dl"); +const {default: electronDl, download, CancelError, InterruptedError} = require("@dootask/electron-dl"); const utils = require("./lib/utils"); const {DownloadManager, DownloadStore} = require("./lib/download-manager"); @@ -116,10 +116,12 @@ async function createDownload(window_, url, options = {}) { try { return await download(window_, url, options); } catch (error) { - // electron-dl rejects with CancelError when a download is cancelled; treat it as expected. + // electron-dl rejects with CancelError/InterruptedError; treat them as expected. const isCancelError = (typeof CancelError === 'function' && error instanceof CancelError) || error?.name === 'CancelError'; - if (!isCancelError) { + const isInterruptedError = (typeof InterruptedError === 'function' && error instanceof InterruptedError) + || error?.name === 'InterruptedError'; + if (!isCancelError && !isInterruptedError) { throw error; } return null; diff --git a/electron/electron.js b/electron/electron.js index e9e60658b..9af28de75 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -1060,4 +1060,4 @@ ipcMain.on('updateQuitAndInstall', (event, args) => { //================================================================ onExport() -onRenderer(mainWindow) +onRenderer(() => mainWindow) diff --git a/electron/lib/renderer.js b/electron/lib/renderer.js index 5e62e1286..af3a21ab4 100644 --- a/electron/lib/renderer.js +++ b/electron/lib/renderer.js @@ -572,7 +572,7 @@ const renderer = { }, } -const onRenderer = (mainWindow) => { +const onRenderer = (getMainWindow) => { ipcMain.on("rendererReq", async (event, args) => { try { let ret = null; @@ -651,7 +651,7 @@ const onRenderer = (mainWindow) => { ret = await electronDown.updateWindow(args.language, args.theme); break; case 'createDownload': - ret = await electronDown.createDownload(mainWindow, args.url, args.options || {}); + ret = await electronDown.createDownload(getMainWindow(), args.url, args.options || {}); break; case 'watchFile': ret = await renderer.watchFile(args.path);