mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
Compare commits
2 Commits
dfbe11deb4
...
66a41306d6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66a41306d6 | ||
|
|
75db218888 |
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user