mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix: no mihomo.yaml
This commit is contained in:
parent
29a8904e03
commit
b30f49c9f4
@ -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) {
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user