Skip to content

Commit ef97ef4

Browse files
committed
Remake dashboard
Optimize theme Optimize more details Update flutter version
1 parent 9cb75f4 commit ef97ef4

File tree

101 files changed

+4948
-1838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+4948
-1838
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
1113
migrate_working_dir/
1214

1315
# IntelliJ related

core/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
var (
3434
isRunning = false
3535
runLock sync.Mutex
36-
ips = []string{"ipinfo.io", "ipapi.co", "api.ip.sb", "ipwho.is"}
36+
ips = []string{"ipwho.is", "ifconfig.me", "icanhazip.com", "api.ip.sb", "ipinfo.io"}
3737
b, _ = batch.New[bool](context.Background(), batch.WithConcurrencyNum[bool](50))
3838
)
3939

core/constant.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const (
6565
closeConnectionMethod Method = "closeConnection"
6666
getExternalProvidersMethod Method = "getExternalProviders"
6767
getExternalProviderMethod Method = "getExternalProvider"
68+
getCountryCodeMethod Method = "getCountryCode"
69+
getMemoryMethod Method = "getMemory"
6870
updateGeoDataMethod Method = "updateGeoData"
6971
updateExternalProviderMethod Method = "updateExternalProvider"
7072
sideLoadExternalProviderMethod Method = "sideLoadExternalProvider"

core/hub.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/metacubex/mihomo/adapter/outboundgroup"
99
"github.com/metacubex/mihomo/common/observable"
1010
"github.com/metacubex/mihomo/common/utils"
11+
"github.com/metacubex/mihomo/component/mmdb"
1112
"github.com/metacubex/mihomo/component/updater"
1213
"github.com/metacubex/mihomo/config"
1314
"github.com/metacubex/mihomo/constant"
@@ -17,8 +18,10 @@ import (
1718
"github.com/metacubex/mihomo/log"
1819
"github.com/metacubex/mihomo/tunnel"
1920
"github.com/metacubex/mihomo/tunnel/statistic"
21+
"net"
2022
"runtime"
2123
"sort"
24+
"strconv"
2225
"time"
2326
)
2427

@@ -404,6 +407,25 @@ func handleStopLog() {
404407
}
405408
}
406409

410+
func handleGetCountryCode(ip string, fn func(value string)) {
411+
go func() {
412+
runLock.Lock()
413+
defer runLock.Unlock()
414+
codes := mmdb.IPInstance().LookupCode(net.ParseIP(ip))
415+
if len(codes) == 0 {
416+
fn("")
417+
return
418+
}
419+
fn(codes[0])
420+
}()
421+
}
422+
423+
func handleGetMemory(fn func(value string)) {
424+
go func() {
425+
fn(strconv.FormatUint(statistic.DefaultManager.Memory(), 10))
426+
}()
427+
}
428+
407429
func init() {
408430
adapter.UrlTestHook = func(name string, delay uint16) {
409431
delayData := &Delay{

core/lib.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ func getConnections() *C.char {
120120
return C.CString(handleGetConnections())
121121
}
122122

123+
//export getMemory
124+
func getMemory(port C.longlong) {
125+
i := int64(port)
126+
handleGetMemory(func(value string) {
127+
bridge.SendToPort(i, value)
128+
})
129+
}
130+
123131
//export closeConnections
124132
func closeConnections() {
125133
handleCloseConnections()
@@ -161,6 +169,15 @@ func updateExternalProvider(providerNameChar *C.char, port C.longlong) {
161169
})
162170
}
163171

172+
//export getCountryCode
173+
func getCountryCode(ipChar *C.char, port C.longlong) {
174+
ip := C.GoString(ipChar)
175+
i := int64(port)
176+
handleGetCountryCode(ip, func(value string) {
177+
bridge.SendToPort(i, value)
178+
})
179+
}
180+
164181
//export sideLoadExternalProvider
165182
func sideLoadExternalProvider(providerNameChar *C.char, dataChar *C.char, port C.longlong) {
166183
i := int64(port)

core/server.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ func handleAction(action *Action) {
157157
case stopListenerMethod:
158158
action.callback(handleStopListener())
159159
return
160+
case getCountryCodeMethod:
161+
ip := action.Data.(string)
162+
handleGetCountryCode(ip, func(value string) {
163+
action.callback(value)
164+
})
165+
return
166+
case getMemoryMethod:
167+
handleGetMemory(func(value string) {
168+
action.callback(value)
169+
})
170+
return
160171
}
161172

162173
}

lib/application.dart

Lines changed: 90 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
22

3-
import 'package:animations/animations.dart';
43
import 'package:dynamic_color/dynamic_color.dart';
54
import 'package:fl_clash/clash/clash.dart';
65
import 'package:fl_clash/common/common.dart';
@@ -59,22 +58,15 @@ class Application extends StatefulWidget {
5958

6059
class 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

Comments
 (0)