mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
allow disable controled dns and sniff
This commit is contained in:
parent
a3c129f9e1
commit
0c5ab9de41
@ -4,6 +4,7 @@ import yaml from 'yaml'
|
||||
import { getAxios, startMihomoMemory, startMihomoTraffic } from '../core/mihomoApi'
|
||||
import { generateProfile } from '../resolve/factory'
|
||||
import { getAppConfig } from './app'
|
||||
import { defaultControledMihomoConfig } from '../utils/template'
|
||||
|
||||
let controledMihomoConfig: Partial<IMihomoConfig> // mihomo.yaml
|
||||
|
||||
@ -16,12 +17,21 @@ export async function getControledMihomoConfig(force = false): Promise<Partial<I
|
||||
}
|
||||
|
||||
export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>): Promise<void> {
|
||||
const { useNameserverPolicy } = await getAppConfig()
|
||||
const { useNameserverPolicy, controlDns, controlSniff } = await getAppConfig()
|
||||
if (patch.tun) {
|
||||
const oldTun = controledMihomoConfig.tun || {}
|
||||
const newTun = Object.assign(oldTun, patch.tun)
|
||||
patch.tun = newTun
|
||||
}
|
||||
if (!controlDns) {
|
||||
delete controledMihomoConfig.dns
|
||||
delete controledMihomoConfig.hosts
|
||||
} else {
|
||||
if (controledMihomoConfig.hosts === undefined) {
|
||||
controledMihomoConfig.dns = defaultControledMihomoConfig.dns
|
||||
controledMihomoConfig.hosts = defaultControledMihomoConfig.hosts
|
||||
}
|
||||
}
|
||||
if (patch.dns) {
|
||||
const oldDns = controledMihomoConfig.dns || {}
|
||||
const newDns = Object.assign(oldDns, patch.dns)
|
||||
@ -30,6 +40,13 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
|
||||
}
|
||||
patch.dns = newDns
|
||||
}
|
||||
if (!controlSniff) {
|
||||
delete controledMihomoConfig.sniffer
|
||||
} else {
|
||||
if (!controledMihomoConfig.sniffer) {
|
||||
controledMihomoConfig.sniffer = defaultControledMihomoConfig.sniffer
|
||||
}
|
||||
}
|
||||
if (patch.sniffer) {
|
||||
const oldSniffer = controledMihomoConfig.sniffer || {}
|
||||
const newSniffer = Object.assign(oldSniffer, patch.sniffer)
|
||||
|
||||
@ -7,6 +7,8 @@ export const defaultConfig: IAppConfig = {
|
||||
autoCheckUpdate: true,
|
||||
autoCloseConnection: true,
|
||||
useNameserverPolicy: false,
|
||||
controlDns: true,
|
||||
controlSniff: true,
|
||||
nameserverPolicy: {},
|
||||
siderOrder: [
|
||||
'mode',
|
||||
|
||||
@ -33,6 +33,8 @@ const App: React.FC = () => {
|
||||
const { appConfig, patchAppConfig } = useAppConfig()
|
||||
const {
|
||||
appTheme = 'system',
|
||||
controlDns = true,
|
||||
controlSniff = true,
|
||||
siderOrder = [
|
||||
'sysproxy',
|
||||
'tun',
|
||||
@ -119,6 +121,8 @@ const App: React.FC = () => {
|
||||
})}
|
||||
>
|
||||
{order.map((key: string) => {
|
||||
if (key === 'dns' && controlDns === false) return null
|
||||
if (key === 'sniff' && controlSniff === false) return null
|
||||
return componentMap[key]
|
||||
})}
|
||||
</SortableContext>
|
||||
|
||||
@ -8,7 +8,8 @@ import {
|
||||
enableAutoRun,
|
||||
disableAutoRun,
|
||||
quitApp,
|
||||
checkUpdate
|
||||
checkUpdate,
|
||||
patchControledMihomoConfig
|
||||
} from '@renderer/utils/ipc'
|
||||
import { IoLogoGithub } from 'react-icons/io5'
|
||||
import { version } from '@renderer/utils/init'
|
||||
@ -26,6 +27,8 @@ const Settings: React.FC = () => {
|
||||
const { appConfig, patchAppConfig } = useAppConfig()
|
||||
const {
|
||||
silentStart = false,
|
||||
controlDns = true,
|
||||
controlSniff = true,
|
||||
delayTestUrl,
|
||||
delayTestTimeout,
|
||||
autoCheckUpdate,
|
||||
@ -188,6 +191,26 @@ const Settings: React.FC = () => {
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="接管DNS设置" divider>
|
||||
<Switch
|
||||
size="sm"
|
||||
isSelected={controlDns}
|
||||
onValueChange={async (v) => {
|
||||
await patchAppConfig({ controlDns: v })
|
||||
await patchControledMihomoConfig({})
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="接管域名嗅探设置" divider>
|
||||
<Switch
|
||||
size="sm"
|
||||
isSelected={controlSniff}
|
||||
onValueChange={async (v) => {
|
||||
await patchAppConfig({ controlSniff: v })
|
||||
await patchControledMihomoConfig({})
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="自动断开连接">
|
||||
<Switch
|
||||
size="sm"
|
||||
|
||||
2
src/shared/types.d.ts
vendored
2
src/shared/types.d.ts
vendored
@ -214,6 +214,8 @@ interface IAppConfig {
|
||||
delayTestUrl?: string
|
||||
delayTestTimeout?: number
|
||||
encryptedPassword?: Buffer
|
||||
controlDns?: boolean
|
||||
controlSniff?: boolean
|
||||
useNameserverPolicy: boolean
|
||||
nameserverPolicy: { [key: string]: string | string[] }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user