Skip to content

Commit

Permalink
optimize core manager
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 12, 2024
1 parent 7902f92 commit a15a2c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,28 @@ export async function startCore(): Promise<void> {
}
)
})
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'
})
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()
}
})
})
}

export function stopCore(): void {
if (child) {
child.removeAllListeners()
if (!child.kill('SIGINT')) {
stopCore()
}
child.kill('SIGINT')
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function createWindow(): void {
stopMihomoMemory()
event.preventDefault()
window?.hide()
window?.webContents.reload()
})

window.webContents.setWindowOpenHandler((details) => {
Expand Down

0 comments on commit a15a2c2

Please sign in to comment.