mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
improve core manager
This commit is contained in:
parent
ceaacffe10
commit
d47a2a8908
@ -34,7 +34,7 @@ chokidar
|
|||||||
let child: ChildProcess
|
let child: ChildProcess
|
||||||
let retry = 10
|
let retry = 10
|
||||||
|
|
||||||
export async function startCore(): Promise<void> {
|
export async function startCore(): Promise<Promise<void>[]> {
|
||||||
const { core = 'mihomo', autoSetDNS = true } = await getAppConfig()
|
const { core = 'mihomo', autoSetDNS = true } = await getAppConfig()
|
||||||
const { tun } = await getControledMihomoConfig()
|
const { tun } = await getControledMihomoConfig()
|
||||||
const corePath = mihomoCorePath(core)
|
const corePath = mihomoCorePath(core)
|
||||||
@ -64,9 +64,11 @@ export async function startCore(): Promise<void> {
|
|||||||
await stopCore()
|
await stopCore()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
child.stdout?.on('data', async (data) => {
|
child.stdout?.on('data', async (data) => {
|
||||||
await writeFile(logPath(), data, { flag: 'a' })
|
await writeFile(logPath(), data, { flag: 'a' })
|
||||||
|
})
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
child.stdout?.on('data', async (data) => {
|
||||||
if (data.toString().includes('configure tun interface: operation not permitted')) {
|
if (data.toString().includes('configure tun interface: operation not permitted')) {
|
||||||
reject('虚拟网卡启动失败, 请尝试手动授予内核权限')
|
reject('虚拟网卡启动失败, 请尝试手动授予内核权限')
|
||||||
}
|
}
|
||||||
@ -82,14 +84,22 @@ export async function startCore(): Promise<void> {
|
|||||||
reject('内核连接失败, 请尝试修改外部控制端口或重启电脑')
|
reject('内核连接失败, 请尝试修改外部控制端口或重启电脑')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (data.toString().includes('RESTful API listening at')) {
|
||||||
|
resolve([
|
||||||
|
new Promise((resolve) => {
|
||||||
|
child.stdout?.on('data', async (data) => {
|
||||||
if (data.toString().includes('Start initial Compatible provider default')) {
|
if (data.toString().includes('Start initial Compatible provider default')) {
|
||||||
await startMihomoTraffic()
|
|
||||||
mainWindow?.webContents.send('coreRestart')
|
mainWindow?.webContents.send('coreRestart')
|
||||||
retry = 10
|
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
])
|
||||||
|
await startMihomoTraffic()
|
||||||
|
retry = 10
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function stopCore(force = false): Promise<void> {
|
export async function stopCore(force = false): Promise<void> {
|
||||||
|
|||||||
@ -92,10 +92,10 @@ app.whenReady().then(async () => {
|
|||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await startCore()
|
const [startPromise] = await startCore()
|
||||||
setTimeout(() => {
|
startPromise.then(async () => {
|
||||||
initProfileUpdater()
|
await initProfileUpdater()
|
||||||
}, 0)
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dialog.showErrorBox('内核启动出错', `${e}`)
|
dialog.showErrorBox('内核启动出错', `${e}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user