Commit 5b016d5c authored by mercury233's avatar mercury233

friendly aria2c fail tip

parent 38b0ad61
Pipeline #4125 failed with stages
in 3 minutes and 54 seconds
......@@ -27,7 +27,7 @@ if (handleElevate()) {
return;
}
const { ipcMain, app, shell, BrowserWindow, Menu, Tray } = require('electron');
const { ipcMain, app, shell, BrowserWindow, Menu, Tray, Notification } = require('electron');
const { autoUpdater } = require('electron-updater');
const isDev = require('electron-is-dev');
const child_process = require('child_process');
......@@ -37,6 +37,9 @@ const path = require('path');
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
// aria2c启动失败则为null
let aria2c;
// 单实例
const gotTheLock = app.requestSingleInstanceLock()
......@@ -136,9 +139,18 @@ function createAria2c() {
default:
throw 'unsupported platform';
}
return child_process.spawn(aria2c_path, ['--enable-rpc', '--rpc-allow-origin-all', '--continue', '--split=10', '--min-split-size=1M', '--max-connection-per-server=10', '--remove-control-file', '--allow-overwrite'], { stdio: 'ignore' });
aria2c = child_process.spawn(aria2c_path, [
'--enable-rpc',
'--rpc-allow-origin-all',
'--rpc-listen-port=6800',
'--continue',
'--split=10',
'--min-split-size=1M',
'--max-connection-per-server=10',
'--remove-control-file',
'--allow-overwrite'
], { stdio: 'ignore' });
}
const aria2c = createAria2c();
// 主窗口
function createWindow() {
......@@ -212,6 +224,12 @@ app.on('ready', async () => {
if (process.platform === 'win32') {
createTray();
}
createAria2c();
aria2c.on('error', (err) => {
new Notification({ title: 'MyCard', body: '启动aria2失败,可能是被杀毒软件误删。游戏下载和更新功能将不可用。' }).show();
console.error(err);
aria2c = null;
});
if (process.env['NODE_ENV'] === 'production') {
/*let updateTempPath = '~/.cache/mycard-updater'
if (process.platform === 'win32') {
......@@ -248,7 +266,7 @@ app.on('activate', function () {
app.on('quit', () => {
// windows 在非 detach 模式下会自动退出子进程
if (process.platform !== 'win32') {
if (process.platform !== 'win32' && aria2c) {
aria2c.kill();
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment