From 2d38c27b25bcf1605d75bee21061db4718210756 Mon Sep 17 00:00:00 2001 From: chen08209 Date: Sun, 24 Nov 2024 04:22:24 +0800 Subject: [PATCH] Update network detection --- .github/workflows/change.yaml | 2 ++ .../dashboard/network_detection.dart | 33 ++++--------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/.github/workflows/change.yaml b/.github/workflows/change.yaml index 61a82812..0116b6be 100644 --- a/.github/workflows/change.yaml +++ b/.github/workflows/change.yaml @@ -4,6 +4,8 @@ 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..79e95b71 100644 --- a/lib/fragments/dashboard/network_detection.dart +++ b/lib/fragments/dashboard/network_detection.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:dio/dio.dart'; import 'package:fl_clash/common/common.dart'; import 'package:fl_clash/enum/enum.dart'; @@ -25,7 +23,6 @@ class _NetworkDetectionState extends State { ); bool? _preIsStart; Function? _checkIpDebounce; - Timer? _setTimeoutTimer; CancelToken? cancelToken; _checkIp() async { @@ -35,7 +32,6 @@ class _NetworkDetectionState extends State { if (!isInit) return; final isStart = appFlowingState.isStart; if (_preIsStart == false && _preIsStart == isStart) return; - _clearSetTimeoutTimer(); networkDetectionState.value = networkDetectionState.value.copyWith( isTesting: true, ipInfo: null, @@ -48,34 +44,18 @@ class _NetworkDetectionState extends State { cancelToken = CancelToken(); try { final ipInfo = await request.checkIp(cancelToken: cancelToken); - if (ipInfo != null) { - networkDetectionState.value = networkDetectionState.value.copyWith( - isTesting: false, - ipInfo: ipInfo, - ); - return; - } - _setTimeoutTimer = Timer(const Duration(milliseconds: 2000), () { - networkDetectionState.value = networkDetectionState.value.copyWith( - isTesting: false, - ipInfo: null, - ); - }); + networkDetectionState.value = networkDetectionState.value.copyWith( + isTesting: false, + ipInfo: ipInfo, + ); } catch (_) { networkDetectionState.value = networkDetectionState.value.copyWith( - isTesting: true, + isTesting: false, ipInfo: null, ); } } - _clearSetTimeoutTimer() { - if (_setTimeoutTimer != null) { - _setTimeoutTimer?.cancel(); - _setTimeoutTimer = null; - } - } - _checkIpContainer(Widget child) { return Selector( selector: (_, appState) { @@ -156,7 +136,8 @@ class _NetworkDetectionState extends State { .textTheme .titleLarge ?.copyWith( - fontFamily: FontFamily.twEmoji.value, + fontFamily: + FontFamily.twEmoji.value, ), ), )