fix: apply Mihomo settings changes to running core, close #1874

This commit is contained in:
zjdndjf
2026-05-27 02:23:05 +08:00
parent c958845f71
commit 9b08fd5297
3 changed files with 23 additions and 1 deletions

View File

@@ -7,6 +7,10 @@
- 重构简化连接页
- 优化软件启动和退出速度
## 修复 (Fix)
- 修复修改 Mihomo 设置(如日志等级、端口等)后未应用到运行中内核的问题
# 1.9.5
## 新功能 (Feat)

View File

@@ -3,7 +3,7 @@ import { existsSync } from 'fs'
import { controledMihomoConfigPath } from '../utils/dirs'
import { parse, stringify } from '../utils/yaml'
import { generateProfile } from '../core/factory'
import { patchMihomoConfig } from '../core/mihomoApi'
import { patchMihomoConfig, startMihomoLogs } from '../core/mihomoApi'
import { defaultControledMihomoConfig } from '../utils/template'
import { deepMerge } from '../utils/merge'
import { createLogger } from '../utils/logger'
@@ -114,6 +114,15 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
error
)
}
// log-level 改变时重连日志 WebSocket使新等级立刻生效
if (patch['log-level']) {
try {
await startMihomoLogs()
} catch (error) {
controledMihomoLogger.warn('Failed to restart log stream after log-level change', error)
}
}
})
await controledMihomoWriteQueue
}

View File

@@ -320,6 +320,15 @@ const Mihomo: React.FC = () => {
const onChangeNeedRestart = async (patch: Partial<IMihomoConfig>): Promise<void> => {
await patchControledMihomoConfig(patch)
try {
if (appConfig?.useHotReloadProfile) {
await mihomoHotReloadConfig()
} else {
await restartCore()
}
} catch (e) {
console.error('Apply config change failed:', e)
}
}
const handleConfigChangeWithRestart = async (key: string, value: unknown) => {