@@ -315,19 +315,9 @@ class GlobalState {
315315 final profileId = profile.id;
316316 final configMap = await getProfileConfig (profileId);
317317 final rawConfig = await handleEvaluate (configMap);
318- final routeAddress =
319- config.networkProps.routeMode == RouteMode .bypassPrivate
320- ? defaultBypassPrivateRouteAddress
321- : patchConfig.tun.routeAddress;
322- final realPatchConfig = ! system.isDesktop
323- ? patchConfig.copyWith.tun (
324- autoRoute: routeAddress.isEmpty ? true : false ,
325- routeAddress: routeAddress,
326- )
327- : patchConfig.copyWith.tun (
328- autoRoute: true ,
329- routeAddress: [],
330- );
318+ final realPatchConfig = patchConfig.copyWith (
319+ tun: patchConfig.tun.getRealTun (config.networkProps.routeMode),
320+ );
331321 rawConfig["external-controller" ] = realPatchConfig.externalController.value;
332322 rawConfig["external-ui" ] = "" ;
333323 rawConfig["interface-name" ] = "" ;
@@ -411,21 +401,23 @@ class GlobalState {
411401 for (final host in realPatchConfig.hosts.entries) {
412402 rawConfig["hosts" ][host.key] = host.value.splitByMultipleSeparators;
413403 }
404+ if (rawConfig["dns" ] == null ) {
405+ rawConfig["dns" ] = {};
406+ }
407+ final isEnableDns = rawConfig["dns" ]["enable" ] == true ;
414408 final overrideDns = globalState.config.overrideDns;
415- if (overrideDns) {
416- rawConfig["dns" ] = realPatchConfig.dns.toJson ();
409+ if (overrideDns || ! isEnableDns) {
410+ final dns = switch (! isEnableDns) {
411+ true => realPatchConfig.dns.copyWith (
412+ nameserver: [...realPatchConfig.dns.nameserver, "system://" ]),
413+ false => realPatchConfig.dns,
414+ };
415+ rawConfig["dns" ] = dns.toJson ();
417416 rawConfig["dns" ]["nameserver-policy" ] = {};
418- for (final entry in realPatchConfig. dns.nameserverPolicy.entries) {
417+ for (final entry in dns.nameserverPolicy.entries) {
419418 rawConfig["dns" ]["nameserver-policy" ][entry.key] =
420419 entry.value.splitByMultipleSeparators;
421420 }
422- } else {
423- if (rawConfig["dns" ] == null ) {
424- rawConfig["dns" ] = {};
425- }
426- if (rawConfig["dns" ]["enable" ] != false ) {
427- rawConfig["dns" ]["enable" ] = true ;
428- }
429421 }
430422 var rules = [];
431423 if (rawConfig["rules" ] != null ) {
@@ -509,6 +501,9 @@ class DetectionState {
509501 debouncer.call (
510502 FunctionTag .checkIp,
511503 _checkIp,
504+ duration: Duration (
505+ milliseconds: 1200 ,
506+ ),
512507 );
513508 }
514509
@@ -533,36 +528,35 @@ class DetectionState {
533528 cancelToken = null ;
534529 }
535530 cancelToken = CancelToken ();
536- try {
531+ state.value = state.value.copyWith (
532+ isTesting: true ,
533+ );
534+ final res = await request.checkIp (cancelToken: cancelToken);
535+ if (res.isError) {
537536 state.value = state.value.copyWith (
538- isTesting: true ,
537+ isLoading: true ,
538+ ipInfo: null ,
539539 );
540- final ipInfo = await request.checkIp (cancelToken: cancelToken);
540+ return ;
541+ }
542+ final ipInfo = res.data;
543+ state.value = state.value.copyWith (
544+ isTesting: false ,
545+ );
546+ if (ipInfo != null ) {
541547 state.value = state.value.copyWith (
542- isTesting: false ,
548+ isLoading: false ,
549+ ipInfo: ipInfo,
543550 );
544- if (ipInfo != null ) {
545- state.value = state.value.copyWith (
546- isLoading: false ,
547- ipInfo: ipInfo,
548- );
549- return ;
550- }
551- _clearSetTimeoutTimer ();
552- _setTimeoutTimer = Timer (const Duration (milliseconds: 300 ), () {
553- state.value = state.value.copyWith (
554- isLoading: false ,
555- ipInfo: null ,
556- );
557- });
558- } catch (e) {
559- if (e.toString () == "cancelled" ) {
560- state.value = state.value.copyWith (
561- isLoading: true ,
562- ipInfo: null ,
563- );
564- }
551+ return ;
565552 }
553+ _clearSetTimeoutTimer ();
554+ _setTimeoutTimer = Timer (const Duration (milliseconds: 300 ), () {
555+ state.value = state.value.copyWith (
556+ isLoading: false ,
557+ ipInfo: null ,
558+ );
559+ });
566560 }
567561
568562 _clearSetTimeoutTimer () {
0 commit comments