From 3449287e46d0dd973950e8eff904aa24d511af09 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Sun, 8 Sep 2024 11:09:25 +0800 Subject: [PATCH] ignore stdio when detached --- src/main/core/manager.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index ede712b..1214d37 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -82,8 +82,15 @@ export async function startCore(detached = false): Promise[]> { } } child = spawn(corePath, ['-d', mihomoWorkDir()], { - detached: detached + detached: detached, + stdio: detached ? 'ignore' : undefined }) + if (detached) { + child.unref() + return new Promise((resolve) => { + resolve([new Promise(() => {})]) + }) + } child.on('close', async (code, signal) => { await writeFile(logPath(), `[Manager]: Core closed, code: ${code}, signal: ${signal}\n`, { flag: 'a' @@ -176,13 +183,8 @@ export async function restartCore(): Promise { export async function keepCoreAlive(): Promise { try { await startCore(true) - stopMihomoTraffic() - stopMihomoConnections() - stopMihomoLogs() - stopMihomoMemory() if (child && child.pid) { await writeFile(path.join(dataDir(), 'core.pid'), child.pid.toString()) - child.unref() } } catch (e) { dialog.showErrorBox('内核启动出错', `${e}`)