From a15a2c273f86e6788a14328ac6ddd9befb3990e2 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Mon, 12 Aug 2024 12:21:42 +0800 Subject: [PATCH] optimize core manager --- src/main/core/manager.ts | 21 ++++++++------------- src/main/index.ts | 1 + 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index cd78f2f5..5c6d68a8 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -53,15 +53,6 @@ export async function startCore(): Promise { } ) }) - child.on('error', (err) => { - if (retry) { - retry-- - startCore() - } else { - dialog.showErrorBox('External controller listen error', err.toString()) - reject(err) - } - }) child.on('close', async (code, signal) => { fs.writeFileSync(logPath(), `[Manager]: Core closed, code: ${code}, signal: ${signal}\n`, { flag: 'a' @@ -69,7 +60,13 @@ export async function startCore(): Promise { fs.writeFileSync(logPath(), `[Manager]: Restart Core\n`, { flag: 'a' }) - await startCore() + if (retry) { + retry-- + await restartCore() + } else { + dialog.showErrorBox('Mihomo Core Closed', `Core closed, code: ${code}, signal: ${signal}`) + stopCore() + } }) }) } @@ -77,9 +74,7 @@ export async function startCore(): Promise { export function stopCore(): void { if (child) { child.removeAllListeners() - if (!child.kill('SIGINT')) { - stopCore() - } + child.kill('SIGINT') } } diff --git a/src/main/index.ts b/src/main/index.ts index 49b2a663..7a8a6b41 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -139,6 +139,7 @@ function createWindow(): void { stopMihomoMemory() event.preventDefault() window?.hide() + window?.webContents.reload() }) window.webContents.setWindowOpenHandler((details) => {