Skip to content

Commit 21663e5

Browse files
committed
Update network detection
1 parent 0901390 commit 21663e5

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

.github/workflows/change.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches:
66
- 'main'
7+
tags:
8+
- 'v*'
79

810
jobs:
911
changelog:

lib/fragments/dashboard/network_detection.dart

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:async';
2-
31
import 'package:dio/dio.dart';
42
import 'package:fl_clash/common/common.dart';
53
import 'package:fl_clash/enum/enum.dart';
@@ -25,7 +23,6 @@ class _NetworkDetectionState extends State<NetworkDetection> {
2523
);
2624
bool? _preIsStart;
2725
Function? _checkIpDebounce;
28-
Timer? _setTimeoutTimer;
2926
CancelToken? cancelToken;
3027

3128
_checkIp() async {
@@ -35,7 +32,6 @@ class _NetworkDetectionState extends State<NetworkDetection> {
3532
if (!isInit) return;
3633
final isStart = appFlowingState.isStart;
3734
if (_preIsStart == false && _preIsStart == isStart) return;
38-
_clearSetTimeoutTimer();
3935
networkDetectionState.value = networkDetectionState.value.copyWith(
4036
isTesting: true,
4137
ipInfo: null,
@@ -48,34 +44,18 @@ class _NetworkDetectionState extends State<NetworkDetection> {
4844
cancelToken = CancelToken();
4945
try {
5046
final ipInfo = await request.checkIp(cancelToken: cancelToken);
51-
if (ipInfo != null) {
52-
networkDetectionState.value = networkDetectionState.value.copyWith(
53-
isTesting: false,
54-
ipInfo: ipInfo,
55-
);
56-
return;
57-
}
58-
_setTimeoutTimer = Timer(const Duration(milliseconds: 2000), () {
59-
networkDetectionState.value = networkDetectionState.value.copyWith(
60-
isTesting: false,
61-
ipInfo: null,
62-
);
63-
});
47+
networkDetectionState.value = networkDetectionState.value.copyWith(
48+
isTesting: false,
49+
ipInfo: ipInfo,
50+
);
6451
} catch (_) {
6552
networkDetectionState.value = networkDetectionState.value.copyWith(
66-
isTesting: true,
53+
isTesting: false,
6754
ipInfo: null,
6855
);
6956
}
7057
}
7158

72-
_clearSetTimeoutTimer() {
73-
if (_setTimeoutTimer != null) {
74-
_setTimeoutTimer?.cancel();
75-
_setTimeoutTimer = null;
76-
}
77-
}
78-
7959
_checkIpContainer(Widget child) {
8060
return Selector<AppState, num>(
8161
selector: (_, appState) {
@@ -156,7 +136,8 @@ class _NetworkDetectionState extends State<NetworkDetection> {
156136
.textTheme
157137
.titleLarge
158138
?.copyWith(
159-
fontFamily: FontFamily.twEmoji.value,
139+
fontFamily:
140+
FontFamily.twEmoji.value,
160141
),
161142
),
162143
)

0 commit comments

Comments
 (0)