Skip to content

Commit

Permalink
ignore stdio when detached
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 8, 2024
1 parent e8d52ca commit 3449287
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
}
}
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'
Expand Down Expand Up @@ -176,13 +183,8 @@ export async function restartCore(): Promise<void> {
export async function keepCoreAlive(): Promise<void> {
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}`)
Expand Down

0 comments on commit 3449287

Please sign in to comment.