Skip to content

Commit

Permalink
Optimize network detection
Browse files Browse the repository at this point in the history
Optimize tile service
  • Loading branch information
chen08209 committed Nov 26, 2024
1 parent bef4ad6 commit 57cba37
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/change.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: change

on:
push:
branches:
- 'main'
tags:
- 'v*'

jobs:
changelog:
Expand Down
6 changes: 4 additions & 2 deletions lib/fragments/dashboard/network_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class _NetworkDetectionState extends State<NetworkDetection> {
);
return;
}
_setTimeoutTimer = Timer(const Duration(milliseconds: 2000), () {
_clearSetTimeoutTimer();
_setTimeoutTimer = Timer(const Duration(milliseconds: 300), () {
networkDetectionState.value = networkDetectionState.value.copyWith(
isTesting: false,
ipInfo: null,
Expand Down Expand Up @@ -156,7 +157,8 @@ class _NetworkDetectionState extends State<NetworkDetection> {
.textTheme
.titleLarge
?.copyWith(
fontFamily: FontFamily.twEmoji.value,
fontFamily:
FontFamily.twEmoji.value,
),
),
)
Expand Down
54 changes: 32 additions & 22 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -96,10 +97,10 @@ Future<void> 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) {
Expand All @@ -115,25 +116,34 @@ Future<void> 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
Expand Down

0 comments on commit 57cba37

Please sign in to comment.