From 57cba3700cff910faa131937d302d73d4194adc6 Mon Sep 17 00:00:00 2001 From: chen08209 Date: Tue, 26 Nov 2024 11:21:16 +0800 Subject: [PATCH] Optimize network detection Optimize tile service --- .github/workflows/change.yaml | 4 +- .../dashboard/network_detection.dart | 6 ++- lib/main.dart | 54 +++++++++++-------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.github/workflows/change.yaml b/.github/workflows/change.yaml index ea99dc0f..1fa65401 100644 --- a/.github/workflows/change.yaml +++ b/.github/workflows/change.yaml @@ -2,8 +2,8 @@ name: change on: push: - branches: - - 'main' + tags: + - 'v*' jobs: changelog: diff --git a/lib/fragments/dashboard/network_detection.dart b/lib/fragments/dashboard/network_detection.dart index 0472c2b7..8cc4822f 100644 --- a/lib/fragments/dashboard/network_detection.dart +++ b/lib/fragments/dashboard/network_detection.dart @@ -55,7 +55,8 @@ class _NetworkDetectionState extends State { ); return; } - _setTimeoutTimer = Timer(const Duration(milliseconds: 2000), () { + _clearSetTimeoutTimer(); + _setTimeoutTimer = Timer(const Duration(milliseconds: 300), () { networkDetectionState.value = networkDetectionState.value.copyWith( isTesting: false, ipInfo: null, @@ -156,7 +157,8 @@ class _NetworkDetectionState extends State { .textTheme .titleLarge ?.copyWith( - fontFamily: FontFamily.twEmoji.value, + fontFamily: + FontFamily.twEmoji.value, ), ), ) diff --git a/lib/main.dart b/lib/main.dart index c9c93ea6..2e953a9c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,10 +8,11 @@ import 'package:fl_clash/plugins/vpn.dart'; import 'package:fl_clash/state.dart'; import 'package:flutter/material.dart'; import 'package:package_info_plus/package_info_plus.dart'; + import 'application.dart'; +import 'common/common.dart'; import 'l10n/l10n.dart'; import 'models/models.dart'; -import 'common/common.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -96,10 +97,10 @@ Future vpnService() async { ); }, onStarted: (String runTime) async { - await globalState.applyProfile( - appState: appState, - config: config, + await globalState.updateClashConfig( clashConfig: clashConfig, + config: config, + isPatch: false, ); }, onLoaded: (String groupName) { @@ -115,25 +116,34 @@ Future vpnService() async { ), ); await app?.tip(appLocalizations.startVpn); - await globalState.handleStart(); - - tile?.addListener( - TileListenerWithVpn( - onStop: () async { - await app?.tip(appLocalizations.stopVpn); - await globalState.handleStop(); - clashCore.shutdown(); - exit(0); - }, - ), - ); - globalState.updateTraffic(); - globalState.updateFunctionLists = [ - () { - globalState.updateTraffic(); - } - ]; + globalState + .updateClashConfig( + clashConfig: clashConfig, + config: config, + isPatch: false, + ) + .then((_) async { + await globalState.handleStart(); + + tile?.addListener( + TileListenerWithVpn( + onStop: () async { + await app?.tip(appLocalizations.stopVpn); + await globalState.handleStop(); + clashCore.shutdown(); + exit(0); + }, + ), + ); + + globalState.updateTraffic(); + globalState.updateFunctionLists = [ + () { + globalState.updateTraffic(); + } + ]; + }); } @immutable