mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
fix: dns/sniffer override button logic2
This commit is contained in:
parent
6b93a59616
commit
b5f6658b72
@ -19,7 +19,7 @@ export async function getControledMihomoConfig(force = false): Promise<Partial<I
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>): Promise<void> {
|
export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>): Promise<void> {
|
||||||
const { useNameserverPolicy, controlDns = true, controlSniff = true } = await getAppConfig()
|
const { controlDns = true, controlSniff = true } = await getAppConfig()
|
||||||
|
|
||||||
if (patch.hosts) {
|
if (patch.hosts) {
|
||||||
controledMihomoConfig.hosts = patch.hosts
|
controledMihomoConfig.hosts = patch.hosts
|
||||||
@ -30,36 +30,18 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
|
|||||||
}
|
}
|
||||||
controledMihomoConfig = deepMerge(controledMihomoConfig, patch)
|
controledMihomoConfig = deepMerge(controledMihomoConfig, patch)
|
||||||
|
|
||||||
// 覆写开关控制
|
// 从不接管状态恢复
|
||||||
let configForProfile = { ...controledMihomoConfig }
|
if (controlDns && controledMihomoConfig.dns?.ipv6 === undefined) {
|
||||||
|
controledMihomoConfig.dns = defaultControledMihomoConfig.dns
|
||||||
if (!controlDns) {
|
|
||||||
delete configForProfile.dns
|
|
||||||
delete configForProfile.hosts
|
|
||||||
} else {
|
|
||||||
if (configForProfile.dns?.ipv6 === undefined) {
|
|
||||||
configForProfile.dns = defaultControledMihomoConfig.dns
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!controlSniff) {
|
if (controlSniff && !controledMihomoConfig.sniffer) {
|
||||||
delete configForProfile.sniffer
|
controledMihomoConfig.sniffer = defaultControledMihomoConfig.sniffer
|
||||||
} else {
|
|
||||||
if (!configForProfile.sniffer) {
|
|
||||||
configForProfile.sniffer = defaultControledMihomoConfig.sniffer
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!useNameserverPolicy) {
|
|
||||||
delete configForProfile?.dns?.['nameserver-policy']
|
|
||||||
}
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
delete configForProfile?.tun?.device
|
delete controledMihomoConfig?.tun?.device
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalConfig = controledMihomoConfig
|
|
||||||
controledMihomoConfig = configForProfile
|
|
||||||
await generateProfile()
|
await generateProfile()
|
||||||
controledMihomoConfig = originalConfig
|
|
||||||
|
|
||||||
await writeFile(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig), 'utf-8')
|
await writeFile(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig), 'utf-8')
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,9 +26,23 @@ let runtimeConfig: IMihomoConfig
|
|||||||
|
|
||||||
export async function generateProfile(): Promise<void> {
|
export async function generateProfile(): Promise<void> {
|
||||||
const { current } = await getProfileConfig()
|
const { current } = await getProfileConfig()
|
||||||
const { diffWorkDir = false } = await getAppConfig()
|
const { diffWorkDir = false, controlDns = true, controlSniff = true, useNameserverPolicy } = await getAppConfig()
|
||||||
const currentProfile = await overrideProfile(current, await getProfile(current))
|
const currentProfile = await overrideProfile(current, await getProfile(current))
|
||||||
const controledMihomoConfig = await getControledMihomoConfig()
|
let controledMihomoConfig = await getControledMihomoConfig()
|
||||||
|
|
||||||
|
// 根据开关状态过滤控制配置
|
||||||
|
controledMihomoConfig = { ...controledMihomoConfig }
|
||||||
|
if (!controlDns) {
|
||||||
|
delete controledMihomoConfig.dns
|
||||||
|
delete controledMihomoConfig.hosts
|
||||||
|
}
|
||||||
|
if (!controlSniff) {
|
||||||
|
delete controledMihomoConfig.sniffer
|
||||||
|
}
|
||||||
|
if (!useNameserverPolicy) {
|
||||||
|
delete controledMihomoConfig?.dns?.['nameserver-policy']
|
||||||
|
}
|
||||||
|
|
||||||
const profile = deepMerge(currentProfile, controledMihomoConfig)
|
const profile = deepMerge(currentProfile, controledMihomoConfig)
|
||||||
// 确保可以拿到基础日志信息
|
// 确保可以拿到基础日志信息
|
||||||
// 使用 debug 可以调试内核相关问题 `debug/pprof`
|
// 使用 debug 可以调试内核相关问题 `debug/pprof`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user