fix: no mihomo.yaml

This commit is contained in:
Memory 2025-09-17 11:58:12 +08:00 committed by GitHub
parent 29a8904e03
commit b30f49c9f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,13 +5,23 @@ import { generateProfile } from '../core/factory'
import { getAppConfig } from './app'
import { defaultControledMihomoConfig } from '../utils/template'
import { deepMerge } from '../utils/merge'
import { existsSync } from 'fs'
let controledMihomoConfig: Partial<IMihomoConfig> // mihomo.yaml
export async function getControledMihomoConfig(force = false): Promise<Partial<IMihomoConfig>> {
if (force || !controledMihomoConfig) {
const data = await readFile(controledMihomoConfigPath(), 'utf-8')
controledMihomoConfig = parse(data) || defaultControledMihomoConfig
if (existsSync(controledMihomoConfigPath())) {
const data = await readFile(controledMihomoConfigPath(), 'utf-8')
controledMihomoConfig = parse(data) || defaultControledMihomoConfig
} else {
controledMihomoConfig = defaultControledMihomoConfig
try {
await writeFile(controledMihomoConfigPath(), stringify(defaultControledMihomoConfig), 'utf-8')
} catch (error) {
console.error('Failed to create mihomo.yaml file:', error)
}
}
// 确保配置包含所有必要的默认字段,处理升级场景
controledMihomoConfig = deepMerge(defaultControledMihomoConfig, controledMihomoConfig)