mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
24 lines
751 B
TypeScript
24 lines
751 B
TypeScript
import { readFile, writeFile } from 'fs/promises'
|
|
import { appConfigPath } from '../utils/dirs'
|
|
import yaml from 'yaml'
|
|
|
|
let appConfig: IAppConfig // config.yaml
|
|
|
|
export async function getAppConfig(force = false): Promise<IAppConfig> {
|
|
if (force || !appConfig) {
|
|
const data = await readFile(appConfigPath(), 'utf-8')
|
|
appConfig = yaml.parse(data)
|
|
}
|
|
return appConfig
|
|
}
|
|
|
|
export async function patchAppConfig(patch: Partial<IAppConfig>): Promise<void> {
|
|
if (patch.sysProxy) {
|
|
const oldSysProxy = appConfig.sysProxy || {}
|
|
const newSysProxy = Object.assign(oldSysProxy, patch.sysProxy)
|
|
patch.sysProxy = newSysProxy
|
|
}
|
|
appConfig = Object.assign(appConfig, patch)
|
|
await writeFile(appConfigPath(), yaml.stringify(appConfig))
|
|
}
|