fix: ensure consistent current profile id when diffWorkDir enabled

This commit is contained in:
xmk23333 2025-12-28 20:06:26 +08:00
parent 75f2522a99
commit fbde5c3f09
2 changed files with 6 additions and 7 deletions

View File

@ -56,7 +56,7 @@ function processRulesWithOffset(ruleStrings: string[], currentRules: string[], i
return { normalRules, insertRules: rules } return { normalRules, insertRules: rules }
} }
export async function generateProfile(): Promise<void> { export async function generateProfile(): Promise<string | undefined> {
// 读取最新的配置 // 读取最新的配置
const { current } = await getProfileConfig(true) const { current } = await getProfileConfig(true)
const { const {
@ -150,6 +150,7 @@ export async function generateProfile(): Promise<void> {
diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work'), diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work'),
runtimeConfigStr runtimeConfigStr
) )
return current
} }
async function prepareProfileWorkDir(current: string | undefined): Promise<void> { async function prepareProfileWorkDir(current: string | undefined): Promise<void> {

View File

@ -13,7 +13,6 @@ import { generateProfile } from './factory'
import { import {
getAppConfig, getAppConfig,
getControledMihomoConfig, getControledMihomoConfig,
getProfileConfig,
patchAppConfig, patchAppConfig,
patchControledMihomoConfig, patchControledMihomoConfig,
manageSmartOverride manageSmartOverride
@ -130,15 +129,15 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
await rm(path.join(dataDir(), 'core.pid')) await rm(path.join(dataDir(), 'core.pid'))
} }
} }
const { current } = await getProfileConfig(true)
const { tun } = await getControledMihomoConfig() const { tun } = await getControledMihomoConfig()
const corePath = mihomoCorePath(core) const corePath = mihomoCorePath(core)
// 管理 Smart 内核覆写配置 // 管理 Smart 内核覆写配置
await manageSmartOverride() await manageSmartOverride()
await generateProfile() // generateProfile 返回实际使用的 current确保内核工作目录与配置文件一致
await checkProfile() const current = await generateProfile()
await checkProfile(current)
await stopCore() await stopCore()
await cleanupSocketFile() await cleanupSocketFile()
@ -453,9 +452,8 @@ export async function quitWithoutCore(): Promise<void> {
app.exit() app.exit()
} }
async function checkProfile(): Promise<void> { async function checkProfile(current: string | undefined): Promise<void> {
const { core = 'mihomo', diffWorkDir = false } = await getAppConfig() const { core = 'mihomo', diffWorkDir = false } = await getAppConfig()
const { current } = await getProfileConfig()
const corePath = mihomoCorePath(core) const corePath = mihomoCorePath(core)
const execFilePromise = promisify(execFile) const execFilePromise = promisify(execFile)