try to fix relaunch error

This commit is contained in:
pompurin404 2024-09-04 17:26:10 +08:00
parent 7a1518c156
commit 317b9e8218
No known key found for this signature in database

View File

@ -14,7 +14,11 @@ import {
startMihomoTraffic,
startMihomoConnections,
startMihomoLogs,
startMihomoMemory
startMihomoMemory,
stopMihomoConnections,
stopMihomoTraffic,
stopMihomoLogs,
stopMihomoMemory
} from './mihomoApi'
import chokidar from 'chokidar'
import { writeFile } from 'fs/promises'
@ -22,19 +26,14 @@ import { promisify } from 'util'
import { mainWindow } from '..'
import path from 'path'
chokidar
.watch(path.join(mihomoCoreDir(), 'meta-update'))
.on('all', (event, path) => {
console.log(event, path)
})
.on('unlinkDir', async () => {
try {
await stopCore(true)
await startCore()
} catch (e) {
dialog.showErrorBox('内核启动出错', `${e}`)
}
})
chokidar.watch(path.join(mihomoCoreDir(), 'meta-update')).on('unlinkDir', async () => {
try {
await stopCore(true)
await startCore()
} catch (e) {
dialog.showErrorBox('内核启动出错', `${e}`)
}
})
let child: ChildProcess
let retry = 10
@ -125,6 +124,10 @@ export async function stopCore(force = false): Promise<void> {
child.removeAllListeners()
child.kill('SIGINT')
}
stopMihomoTraffic()
stopMihomoConnections()
stopMihomoLogs()
stopMihomoMemory()
}
export async function restartCore(): Promise<void> {