Commit b81b5bdd authored by mercury233's avatar mercury233

fix log

parent bc1051f5
Pipeline #39095 failed with stages
in 4 minutes and 3 seconds
......@@ -65,6 +65,25 @@ if (!process.env['NODE_ENV']) {
process.env['NODE_ENV'] = isDev ? 'development' : 'production';
}
// 记录主窗口加载前的日志
const logBuffer = [];
function mylog(...args) {
logBuffer.push(args);
console.log(args);
flushLogBuffer();
}
// 转发给主窗口
function flushLogBuffer() {
if (mainWindow && mainWindow.webContents && logBuffer.length > 0) {
logBuffer.forEach(args => {
mainWindow.webContents.executeJavaScript(
`console.log.apply(console, ${JSON.stringify(args)})`
);
});
logBuffer.length = 0;
}
}
// 自动更新
let updateWindow;
global.autoUpdater = autoUpdater;
......@@ -156,17 +175,13 @@ function createAria2c() {
'--max-download-result=40000'
], { stdio: 'ignore' });
aria2c.on('error', (err) => {
console.error('aria2c spawn error:', aria2c_path, err);
});
aria2c.on('exit', (code, signal) => {
if (code !== 0) {
console.error(`aria2c exited with code ${code}, signal ${signal}, aria2c_path: ${aria2c_path}`);
mylog(`aria2c exited with code ${code}, signal ${signal}, aria2c_path: ${aria2c_path}`);
}
});
} catch (err) {
console.error('Failed to start aria2c:', aria2c_path, err);
mylog('Failed to start aria2c:', aria2c_path, err);
}
}
......@@ -239,13 +254,14 @@ function createTray() {
// Some APIs can only be used after this event occurs.
app.on('ready', async () => {
createWindow();
flushLogBuffer();
if (process.platform === 'win32') {
createTray();
}
createAria2c();
aria2c.on('error', (err) => {
new Notification({ title: 'MyCard', body: '启动aria2失败,可能是被杀毒软件误删。游戏下载和更新功能将不可用。' }).show();
console.error(err);
mylog('启动aria2失败', err, '工作目录:', process.cwd());
aria2c = null;
});
if (process.env['NODE_ENV'] === 'production') {
......
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