11import 'dart:async' ;
22
3- import 'package:animations/animations.dart' ;
43import 'package:dynamic_color/dynamic_color.dart' ;
54import 'package:fl_clash/clash/clash.dart' ;
65import 'package:fl_clash/common/common.dart' ;
@@ -59,22 +58,15 @@ class Application extends StatefulWidget {
5958
6059class ApplicationState extends State <Application > {
6160 late SystemColorSchemes systemColorSchemes;
62- Timer ? timer;
61+ Timer ? _autoUpdateGroupTaskTimer;
62+ Timer ? _autoUpdateProfilesTaskTimer;
6363
6464 final _pageTransitionsTheme = const PageTransitionsTheme (
6565 builders: < TargetPlatform , PageTransitionsBuilder > {
66- TargetPlatform .android: SharedAxisPageTransitionsBuilder (
67- transitionType: SharedAxisTransitionType .horizontal,
68- ),
69- TargetPlatform .windows: SharedAxisPageTransitionsBuilder (
70- transitionType: SharedAxisTransitionType .horizontal,
71- ),
72- TargetPlatform .linux: SharedAxisPageTransitionsBuilder (
73- transitionType: SharedAxisTransitionType .horizontal,
74- ),
75- TargetPlatform .macOS: SharedAxisPageTransitionsBuilder (
76- transitionType: SharedAxisTransitionType .horizontal,
77- ),
66+ TargetPlatform .android: CommonPageTransitionsBuilder (),
67+ TargetPlatform .windows: CommonPageTransitionsBuilder (),
68+ TargetPlatform .linux: CommonPageTransitionsBuilder (),
69+ TargetPlatform .macOS: CommonPageTransitionsBuilder (),
7870 },
7971 );
8072
@@ -96,7 +88,8 @@ class ApplicationState extends State<Application> {
9688 @override
9789 void initState () {
9890 super .initState ();
99- _initTimer ();
91+ _autoUpdateGroupTask ();
92+ _autoUpdateProfilesTask ();
10093 globalState.appController = AppController (context);
10194 globalState.measure = Measure .of (context);
10295 WidgetsBinding .instance.addPostFrameCallback ((timeStamp) async {
@@ -110,37 +103,37 @@ class ApplicationState extends State<Application> {
110103 });
111104 }
112105
113- _initTimer () {
114- _cancelTimer ();
115- timer = Timer .periodic (const Duration (milliseconds: 20000 ), (_) {
106+ _autoUpdateGroupTask () {
107+ _autoUpdateGroupTaskTimer = Timer (const Duration (milliseconds: 20000 ), () {
116108 WidgetsBinding .instance.addPostFrameCallback ((_) {
117- globalState.appController.updateGroupDebounce ();
109+ globalState.appController.updateGroupsDebounce ();
110+ _autoUpdateGroupTask ();
118111 });
119112 });
120113 }
121114
122- _cancelTimer () {
123- if (timer != null ) {
124- timer ? . cancel ();
125- timer = null ;
126- }
115+ _autoUpdateProfilesTask () {
116+ _autoUpdateProfilesTaskTimer = Timer ( const Duration (seconds : 5 ), () async {
117+ await globalState.appController. autoUpdateProfiles ();
118+ _autoUpdateProfilesTask () ;
119+ });
127120 }
128121
129- _buildApp (Widget app ) {
122+ _buildPlatformWrap (Widget child ) {
130123 if (system.isDesktop) {
131124 return WindowManager (
132125 child: TrayManager (
133126 child: HotKeyManager (
134127 child: ProxyManager (
135- child: app ,
128+ child: child ,
136129 ),
137130 ),
138131 ),
139132 );
140133 }
141134 return AndroidManager (
142135 child: TileManager (
143- child: app ,
136+ child: child ,
144137 ),
145138 );
146139 }
@@ -156,6 +149,17 @@ class ApplicationState extends State<Application> {
156149 );
157150 }
158151
152+ _buildWrap (Widget child) {
153+ return AppStateManager (
154+ child: ClashManager (
155+ child: ConnectivityManager (
156+ onConnectivityChanged: globalState.appController.updateLocalIp,
157+ child: child,
158+ ),
159+ ),
160+ );
161+ }
162+
159163 _updateSystemColorSchemes (
160164 ColorScheme ? lightDynamic,
161165 ColorScheme ? darkDynamic,
@@ -171,31 +175,31 @@ class ApplicationState extends State<Application> {
171175
172176 @override
173177 Widget build (context) {
174- return _buildApp (
175- AppStateManager (
176- child : ClashManager (
177- child : Selector2 < AppState , Config , ApplicationSelectorState > (
178- selector : (_, appState, config) => ApplicationSelectorState (
179- locale : config.appSetting.locale ,
180- themeMode : config.themeProps.themeMode ,
181- primaryColor : config.themeProps.primaryColor ,
182- prueBlack : config.themeProps.prueBlack ,
183- fontFamily : config.themeProps.fontFamily ,
184- ),
185- builder : (_, state, child) {
186- return DynamicColorBuilder (
187- builder : (lightDynamic, darkDynamic) {
188- _updateSystemColorSchemes (lightDynamic, darkDynamic);
189- return MaterialApp (
190- navigatorKey : globalState.navigatorKey,
191- localizationsDelegates : const [
192- AppLocalizations .delegate,
193- GlobalMaterialLocalizations .delegate,
194- GlobalCupertinoLocalizations .delegate,
195- GlobalWidgetsLocalizations .delegate
196- ],
197- builder : (_, child) {
198- return LayoutBuilder (
178+ return _buildWrap (
179+ _buildPlatformWrap (
180+ Selector2 < AppState , Config , ApplicationSelectorState > (
181+ selector : (_, appState, config) => ApplicationSelectorState (
182+ locale : config.appSetting.locale,
183+ themeMode : config.themeProps.themeMode ,
184+ primaryColor : config.themeProps.primaryColor ,
185+ prueBlack : config.themeProps.prueBlack ,
186+ fontFamily : config.themeProps.fontFamily ,
187+ ) ,
188+ builder : (_, state, child) {
189+ return DynamicColorBuilder (
190+ builder : (lightDynamic, darkDynamic) {
191+ _updateSystemColorSchemes (lightDynamic, darkDynamic);
192+ return MaterialApp (
193+ navigatorKey : globalState.navigatorKey,
194+ localizationsDelegates : const [
195+ AppLocalizations .delegate,
196+ GlobalMaterialLocalizations .delegate,
197+ GlobalCupertinoLocalizations .delegate,
198+ GlobalWidgetsLocalizations .delegate
199+ ],
200+ builder : (_, child) {
201+ return MessageManager (
202+ child : LayoutBuilder (
199203 builder: (_, container) {
200204 final appController = globalState.appController;
201205 final maxWidth = container.maxWidth;
@@ -204,41 +208,40 @@ class ApplicationState extends State<Application> {
204208 }
205209 return _buildPage (child! );
206210 },
207- );
208- },
209- scrollBehavior: BaseScrollBehavior (),
210- title: appName,
211- locale: other.getLocaleForString (state.locale),
212- supportedLocales:
213- AppLocalizations .delegate.supportedLocales,
214- themeMode: state.themeMode,
215- theme: ThemeData (
216- useMaterial3: true ,
217- fontFamily: state.fontFamily.value,
218- pageTransitionsTheme: _pageTransitionsTheme,
219- colorScheme: _getAppColorScheme (
220- brightness: Brightness .light,
221- systemColorSchemes: systemColorSchemes,
222- primaryColor: state.primaryColor,
223211 ),
212+ );
213+ },
214+ scrollBehavior: BaseScrollBehavior (),
215+ title: appName,
216+ locale: other.getLocaleForString (state.locale),
217+ supportedLocales: AppLocalizations .delegate.supportedLocales,
218+ themeMode: state.themeMode,
219+ theme: ThemeData (
220+ useMaterial3: true ,
221+ fontFamily: state.fontFamily.value,
222+ pageTransitionsTheme: _pageTransitionsTheme,
223+ colorScheme: _getAppColorScheme (
224+ brightness: Brightness .light,
225+ systemColorSchemes: systemColorSchemes,
226+ primaryColor: state.primaryColor,
224227 ),
225- darkTheme : ThemeData (
226- useMaterial3 : true ,
227- fontFamily : state.fontFamily.value ,
228- pageTransitionsTheme : _pageTransitionsTheme ,
229- colorScheme : _getAppColorScheme (
230- brightness : Brightness .dark,
231- systemColorSchemes : systemColorSchemes ,
232- primaryColor : state.primaryColor ,
233- ). toPrueBlack ( state.prueBlack) ,
234- ),
235- home : child ,
236- );
237- },
238- );
239- },
240- child : const HomePage () ,
241- ),
228+ ),
229+ darkTheme : ThemeData (
230+ useMaterial3 : true ,
231+ fontFamily : state.fontFamily.value ,
232+ pageTransitionsTheme : _pageTransitionsTheme,
233+ colorScheme : _getAppColorScheme (
234+ brightness : Brightness .dark ,
235+ systemColorSchemes : systemColorSchemes ,
236+ primaryColor : state.primaryColor ,
237+ ). toPrueBlack (state.prueBlack) ,
238+ ) ,
239+ home : child,
240+ );
241+ },
242+ );
243+ } ,
244+ child : const HomePage ( ),
242245 ),
243246 ),
244247 );
@@ -247,7 +250,8 @@ class ApplicationState extends State<Application> {
247250 @override
248251 Future <void > dispose () async {
249252 linkManager.destroy ();
250- _cancelTimer ();
253+ _autoUpdateGroupTaskTimer? .cancel ();
254+ _autoUpdateProfilesTaskTimer? .cancel ();
251255 await clashService? .destroy ();
252256 await globalState.appController.savePreferences ();
253257 await globalState.appController.handleExit ();
0 commit comments