@@ -4,6 +4,7 @@ import yaml from 'yaml'
4
4
import { getAxios , startMihomoMemory , startMihomoTraffic } from '../core/mihomoApi'
5
5
import { generateProfile } from '../resolve/factory'
6
6
import { getAppConfig } from './app'
7
+ import { defaultControledMihomoConfig } from '../utils/template'
7
8
8
9
let controledMihomoConfig : Partial < IMihomoConfig > // mihomo.yaml
9
10
@@ -16,12 +17,21 @@ export async function getControledMihomoConfig(force = false): Promise<Partial<I
16
17
}
17
18
18
19
export async function patchControledMihomoConfig ( patch : Partial < IMihomoConfig > ) : Promise < void > {
19
- const { useNameserverPolicy } = await getAppConfig ( )
20
+ const { useNameserverPolicy, controlDns , controlSniff } = await getAppConfig ( )
20
21
if ( patch . tun ) {
21
22
const oldTun = controledMihomoConfig . tun || { }
22
23
const newTun = Object . assign ( oldTun , patch . tun )
23
24
patch . tun = newTun
24
25
}
26
+ if ( ! controlDns ) {
27
+ delete controledMihomoConfig . dns
28
+ delete controledMihomoConfig . hosts
29
+ } else {
30
+ if ( controledMihomoConfig . hosts === undefined ) {
31
+ controledMihomoConfig . dns = defaultControledMihomoConfig . dns
32
+ controledMihomoConfig . hosts = defaultControledMihomoConfig . hosts
33
+ }
34
+ }
25
35
if ( patch . dns ) {
26
36
const oldDns = controledMihomoConfig . dns || { }
27
37
const newDns = Object . assign ( oldDns , patch . dns )
@@ -30,6 +40,13 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
30
40
}
31
41
patch . dns = newDns
32
42
}
43
+ if ( ! controlSniff ) {
44
+ delete controledMihomoConfig . sniffer
45
+ } else {
46
+ if ( ! controledMihomoConfig . sniffer ) {
47
+ controledMihomoConfig . sniffer = defaultControledMihomoConfig . sniffer
48
+ }
49
+ }
33
50
if ( patch . sniffer ) {
34
51
const oldSniffer = controledMihomoConfig . sniffer || { }
35
52
const newSniffer = Object . assign ( oldSniffer , patch . sniffer )
0 commit comments