mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-21 16:48:13 +00:00
fix(electron): 修复客户端下载功能无法启动的问题
- 将 onRenderer 参数从 mainWindow 改为 getMainWindow 函数,解决模块加载时 mainWindow 为 null 导致下载无法触发的问题 - 处理 InterruptedError 错误,避免下载中断时抛出未处理异常
This commit is contained in:
parent
bc460f0da8
commit
2163bb0bff
8
electron/electron-down.js
vendored
8
electron/electron-down.js
vendored
@ -2,7 +2,7 @@ const {BrowserWindow, screen, shell, ipcMain} = require('electron')
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const loger = require("electron-log");
|
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 utils = require("./lib/utils");
|
||||||
const {DownloadManager, DownloadStore} = require("./lib/download-manager");
|
const {DownloadManager, DownloadStore} = require("./lib/download-manager");
|
||||||
|
|
||||||
@ -116,10 +116,12 @@ async function createDownload(window_, url, options = {}) {
|
|||||||
try {
|
try {
|
||||||
return await download(window_, url, options);
|
return await download(window_, url, options);
|
||||||
} catch (error) {
|
} 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)
|
const isCancelError = (typeof CancelError === 'function' && error instanceof CancelError)
|
||||||
|| error?.name === 'CancelError';
|
|| error?.name === 'CancelError';
|
||||||
if (!isCancelError) {
|
const isInterruptedError = (typeof InterruptedError === 'function' && error instanceof InterruptedError)
|
||||||
|
|| error?.name === 'InterruptedError';
|
||||||
|
if (!isCancelError && !isInterruptedError) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
2
electron/electron.js
vendored
2
electron/electron.js
vendored
@ -1060,4 +1060,4 @@ ipcMain.on('updateQuitAndInstall', (event, args) => {
|
|||||||
//================================================================
|
//================================================================
|
||||||
|
|
||||||
onExport()
|
onExport()
|
||||||
onRenderer(mainWindow)
|
onRenderer(() => mainWindow)
|
||||||
|
|||||||
4
electron/lib/renderer.js
vendored
4
electron/lib/renderer.js
vendored
@ -572,7 +572,7 @@ const renderer = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const onRenderer = (mainWindow) => {
|
const onRenderer = (getMainWindow) => {
|
||||||
ipcMain.on("rendererReq", async (event, args) => {
|
ipcMain.on("rendererReq", async (event, args) => {
|
||||||
try {
|
try {
|
||||||
let ret = null;
|
let ret = null;
|
||||||
@ -651,7 +651,7 @@ const onRenderer = (mainWindow) => {
|
|||||||
ret = await electronDown.updateWindow(args.language, args.theme);
|
ret = await electronDown.updateWindow(args.language, args.theme);
|
||||||
break;
|
break;
|
||||||
case 'createDownload':
|
case 'createDownload':
|
||||||
ret = await electronDown.createDownload(mainWindow, args.url, args.options || {});
|
ret = await electronDown.createDownload(getMainWindow(), args.url, args.options || {});
|
||||||
break;
|
break;
|
||||||
case 'watchFile':
|
case 'watchFile':
|
||||||
ret = await renderer.watchFile(args.path);
|
ret = await renderer.watchFile(args.path);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user