diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index 9087aeb..479fbe4 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -56,7 +56,7 @@ function processRulesWithOffset(ruleStrings: string[], currentRules: string[], i return { normalRules, insertRules: rules } } -export async function generateProfile(): Promise { +export async function generateProfile(): Promise { // 读取最新的配置 const { current } = await getProfileConfig(true) const { @@ -150,6 +150,7 @@ export async function generateProfile(): Promise { diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work'), runtimeConfigStr ) + return current } async function prepareProfileWorkDir(current: string | undefined): Promise { diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 215ab73..a6a36c6 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -13,7 +13,6 @@ import { generateProfile } from './factory' import { getAppConfig, getControledMihomoConfig, - getProfileConfig, patchAppConfig, patchControledMihomoConfig, manageSmartOverride @@ -130,15 +129,15 @@ export async function startCore(detached = false): Promise[]> { await rm(path.join(dataDir(), 'core.pid')) } } - const { current } = await getProfileConfig(true) const { tun } = await getControledMihomoConfig() const corePath = mihomoCorePath(core) // 管理 Smart 内核覆写配置 await manageSmartOverride() - await generateProfile() - await checkProfile() + // generateProfile 返回实际使用的 current,确保内核工作目录与配置文件一致 + const current = await generateProfile() + await checkProfile(current) await stopCore() await cleanupSocketFile() @@ -453,9 +452,8 @@ export async function quitWithoutCore(): Promise { app.exit() } -async function checkProfile(): Promise { +async function checkProfile(current: string | undefined): Promise { const { core = 'mihomo', diffWorkDir = false } = await getAppConfig() - const { current } = await getProfileConfig() const corePath = mihomoCorePath(core) const execFilePromise = promisify(execFile)