Compare commits

..

2 Commits

Author SHA1 Message Date
ezequielnick
66a41306d6 fix: unexpected lightmode core exit 2025-09-05 22:37:46 +08:00
ezequielnick
75db218888 Revert "fix: selection loss in light mode"
This reverts commit e176f6db14941c686fdb40f359b1dd039e8b28c2.
2025-09-05 21:54:28 +08:00

View File

@ -144,7 +144,7 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
corePath, corePath,
['-d', diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), ctlParam, dynamicIpcPath], ['-d', diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), ctlParam, dynamicIpcPath],
{ {
detached: true, detached: detached,
stdio: detached ? 'ignore' : undefined, stdio: detached ? 'ignore' : undefined,
env: env env: env
} }
@ -153,6 +153,7 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
os.setPriority(child.pid, os.constants.priority[mihomoCpuPriority]) os.setPriority(child.pid, os.constants.priority[mihomoCpuPriority])
} }
if (detached) { if (detached) {
await managerLogger.info(`Core process detached successfully on ${process.platform}, PID: ${child.pid}`)
child.unref() child.unref()
return new Promise((resolve) => { return new Promise((resolve) => {
resolve([new Promise(() => {})]) resolve([new Promise(() => {})])
@ -378,7 +379,7 @@ export async function restartCore(): Promise<void> {
export async function keepCoreAlive(): Promise<void> { export async function keepCoreAlive(): Promise<void> {
try { try {
if (!child) await startCore(true) await startCore(true)
if (child && child.pid) { if (child && child.pid) {
await writeFile(path.join(dataDir(), 'core.pid'), child.pid.toString()) await writeFile(path.join(dataDir(), 'core.pid'), child.pid.toString())
} }
@ -388,8 +389,21 @@ export async function keepCoreAlive(): Promise<void> {
} }
export async function quitWithoutCore(): Promise<void> { export async function quitWithoutCore(): Promise<void> {
await keepCoreAlive() await managerLogger.info(`Starting lightweight mode on platform: ${process.platform}`)
try {
await startCore(true)
if (child && child.pid) {
await writeFile(path.join(dataDir(), 'core.pid'), child.pid.toString())
await managerLogger.info(`Core started in lightweight mode with PID: ${child.pid}`)
}
} catch (e) {
await managerLogger.error('Failed to start core in lightweight mode:', e)
safeShowErrorBox('mihomo.error.coreStartFailed', `${e}`)
}
await startMonitor(true) await startMonitor(true)
await managerLogger.info('Exiting main process, core will continue running in background')
app.exit() app.exit()
} }