Compare commits

...

22 Commits

Author SHA1 Message Date
chen08209
665330e17a Fix the problem of invalid auto-selection 2024-05-05 16:13:52 +08:00
chen08209
0eb001e717 New Async UpdateConfig 2024-05-05 03:12:45 +08:00
chen08209
a563991d74 add changeProfileDebounce 2024-05-04 21:51:40 +08:00
chen08209
3e2a30008c Update Workflow 2024-05-04 16:50:37 +08:00
chen08209
ff68d573d6 Fix ChangeProfile block 2024-05-04 16:39:21 +08:00
chen08209
3223fca7ba Fix Release Message Error
(cherry picked from commit aef50fe0e3)
2024-05-04 16:38:03 +08:00
chen08209
006f9127fc Update Selector 2
(cherry picked from commit fc0767ed25)
2024-05-04 16:37:59 +08:00
chen08209
a2709e155c Update Version
(cherry picked from commit dbf1724cca)
2024-05-04 16:37:57 +08:00
chen08209
684fa7b58e Fix Proxies Select Error
(cherry picked from commit 909aa4038e)
2024-05-04 16:37:55 +08:00
chen08209
03b4da54b5 Fix the problem that the proxy group is empty in global mode.
(cherry picked from commit 2d0a7d8d46)
2024-05-04 16:37:54 +08:00
chen08209
a904b55d11 Fix the problem that the proxy group is empty in global mode.
(cherry picked from commit ca96cd1d82)
2024-05-04 16:37:54 +08:00
chen08209
d711935e2e Add ProxyProvider2
(cherry picked from commit 91ab1e5dac)
2024-05-04 16:37:53 +08:00
chen08209
98b1496eff Add ProxyProvider
(cherry picked from commit b3a5f74df8)
2024-05-03 21:28:41 +08:00
chen08209
442c32b6eb Update Version 2024-05-03 15:32:12 +08:00
chen08209
949a2aaac3 Update ProxyGroup Sort 2024-05-03 14:31:10 +08:00
chen08209
c77463f337 Fix Android quickStart VpnService some problems 2024-05-02 00:46:42 +08:00
chen08209
00377d6070 Update version 2024-05-01 23:39:21 +08:00
chen08209
f393b4b3e9 Set Android notification low importance 2024-05-01 23:29:32 +08:00
chen08209
75e6cfde15 Add Telegram in README_zh_CN.md
(cherry picked from commit 8a188a37c9)
2024-05-01 21:52:22 +08:00
chen08209
7bfe5617d9 Add Telegram 2024-05-01 21:49:18 +08:00
chen08209
97cc96c243 Fix the issue that VpnService can't be closed correctly in special cases 2024-05-01 21:29:54 +08:00
chen08209
1821ee2f61 Fix the problem that TileService is not destroyed correctly in some cases
Adjust tab animation defaults
2024-05-01 15:13:09 +08:00
34 changed files with 607 additions and 225 deletions

View File

@@ -89,7 +89,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
submodules: recursive fetch-depth: 0
- name: Download - name: Download
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -101,13 +101,13 @@ jobs:
- name: Pre Release - name: Pre Release
run: | run: |
pip install gitchangelog pystache mustache markdown pip install gitchangelog pystache mustache markdown
prelease=$(curl --silent "https://api.github.com/repos/chen08209/FlClash/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' || echo "") pre=$(curl --silent "https://api.github.com/repos/chen08209/FlClash/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' || echo "")
if [ -z "$prelease" ]; then if [ -z "pre" ]; then
echo "init" > release.md echo "init" > release.md
else else
current="${{ github.ref_name }}" current="${{ github.ref_name }}"
echo -e "\n\n<details markdown=1><summary>All changes from $current to the latest commit:</summary>\n\n" >> release.md echo -e "\n\n<details markdown=1><summary>All changes from $current to the latest commit:</summary>\n\n" >> release.md
gitchangelog "${prelease}.." >> release.md 2>&1 || echo "Error in gitchangelog" gitchangelog "${pre}.." >> release.md 2>&1 || echo "Error in gitchangelog"
echo -e "\n\n</details>" >> release.md echo -e "\n\n</details>" >> release.md
fi fi
- name: Release - name: Release

View File

@@ -10,12 +10,12 @@ A multi-platform proxy client based on ClashMeta, simple and easy to use, open-s
on Desktop: on Desktop:
<p style="text-align: center;"> <p style="text-align: center;">
<img src="snapshots/desktop.gif"> <img alt="desktop" src="snapshots/desktop.gif">
</p> </p>
on Mobile: on Mobile:
<p style="text-align: center;"> <p style="text-align: center;">
<img src="snapshots/mobile.gif"> <img alt="mobile" src="snapshots/mobile.gif">
</p> </p>
## Features ## Features
@@ -28,6 +28,10 @@ on Mobile:
✨ Support subscription link, Dark mode ✨ Support subscription link, Dark mode
## Contact
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
## Build ## Build
1. Update submodules 1. Update submodules
@@ -81,4 +85,7 @@ on Mobile:
```bash ```bash
dart .\setup.dart dart .\setup.dart
``` ```

View File

@@ -10,12 +10,12 @@
on Desktop: on Desktop:
<p style="text-align: center;"> <p style="text-align: center;">
<img src="snapshots/desktop.gif"> <img alt="desktop" src="snapshots/desktop.gif">
</p> </p>
on Mobile: on Mobile:
<p style="text-align: center;"> <p style="text-align: center;">
<img src="snapshots/mobile.gif"> <img alt="mobile" src="snapshots/mobile.gif">
</p> </p>
## Features ## Features
@@ -28,6 +28,10 @@ on Mobile:
✨ 支持一键导入订阅, 深色模式 ✨ 支持一键导入订阅, 深色模式
## Contact
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
## Build ## Build
1. 更新 submodules 1. 更新 submodules

View File

@@ -10,6 +10,7 @@ import io.flutter.embedding.engine.FlutterEngine
class MainActivity : FlutterActivity() { class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GlobalState.flutterEngine?.destroy()
super.configureFlutterEngine(flutterEngine) super.configureFlutterEngine(flutterEngine)
flutterEngine.plugins.add(AppPlugin()) flutterEngine.plugins.add(AppPlugin())
flutterEngine.plugins.add(ProxyPlugin()) flutterEngine.plugins.add(ProxyPlugin())

View File

@@ -37,14 +37,12 @@ class FlClashTileService : TileService() {
} }
} }
override fun onStartListening() { override fun onStartListening() {
super.onStartListening() super.onStartListening()
GlobalState.runState.value?.let { updateTile(it) } GlobalState.runState.value?.let { updateTile(it) }
GlobalState.runState.observeForever(observer) GlobalState.runState.observeForever(observer)
} }
@SuppressLint("StartActivityAndCollapseDeprecated") @SuppressLint("StartActivityAndCollapseDeprecated")
private fun activityTransfer() { private fun activityTransfer() {
val intent = Intent(this, TempActivity::class.java) val intent = Intent(this, TempActivity::class.java)
@@ -88,7 +86,7 @@ class FlClashTileService : TileService() {
if(currentTilePlugin == null){ if(currentTilePlugin == null){
initFlutterEngine() initFlutterEngine()
}else{ }else{
currentTilePlugin?.handleStart() currentTilePlugin.handleStart()
} }
} else if(GlobalState.runState.value == RunState.START){ } else if(GlobalState.runState.value == RunState.START){
GlobalState.runState.value = RunState.PENDING GlobalState.runState.value = RunState.PENDING
@@ -97,7 +95,6 @@ class FlClashTileService : TileService() {
} }
override fun onDestroy() { override fun onDestroy() {
GlobalState.runState.removeObserver(observer) GlobalState.runState.removeObserver(observer)
super.onDestroy() super.onDestroy()

View File

@@ -25,7 +25,8 @@ class FlClashVpnService : VpnService() {
private val CHANNEL = "FlClash" private val CHANNEL = "FlClash"
var fd: Int? = null; var fd: Int? = null
private val notificationId: Int = 1
private val passList = listOf( private val passList = listOf(
"*zhihu.com", "*zhihu.com",
@@ -100,11 +101,12 @@ class FlClashVpnService : VpnService() {
fun startForeground(title: String, content: String) { fun startForeground(title: String, content: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = val channel =
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_DEFAULT) NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_LOW)
val manager = getSystemService(NotificationManager::class.java) val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(channel) manager.createNotificationChannel(channel)
val intent = Intent(this, MainActivity::class.java) val intent = Intent(this, MainActivity::class.java)
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity( PendingIntent.getActivity(
this, this,
@@ -120,7 +122,9 @@ class FlClashVpnService : VpnService() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
} }
val icon = IconCompat.createWithResource(this, this.applicationInfo.icon) val icon = IconCompat.createWithResource(this, this.applicationInfo.icon)
val notification = with(NotificationCompat.Builder(this, CHANNEL)) { val notification = with(NotificationCompat.Builder(this, CHANNEL)) {
setSmallIcon(icon) setSmallIcon(icon)
setContentTitle(title) setContentTitle(title)
@@ -132,12 +136,13 @@ class FlClashVpnService : VpnService() {
build() build()
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(1, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE) startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
} else { } else {
startForeground(1, notification) startForeground(notificationId, notification)
} }
} }
} }
private fun stopForeground() { private fun stopForeground() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
stopForeground(Service.STOP_FOREGROUND_REMOVE) stopForeground(Service.STOP_FOREGROUND_REMOVE)

View File

@@ -121,6 +121,7 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi
targetConfig.Tun.Device = patchConfig.Tun.Device targetConfig.Tun.Device = patchConfig.Tun.Device
targetConfig.Tun.DNSHijack = patchConfig.Tun.DNSHijack targetConfig.Tun.DNSHijack = patchConfig.Tun.DNSHijack
targetConfig.Tun.Stack = patchConfig.Tun.Stack targetConfig.Tun.Stack = patchConfig.Tun.Stack
targetConfig.Profile.StoreSelected = false
if targetConfig.DNS.Enable == false { if targetConfig.DNS.Enable == false {
targetConfig.DNS = patchConfig.DNS targetConfig.DNS = patchConfig.DNS
} else { } else {
@@ -164,10 +165,7 @@ func patchConfig(general *config.General) {
resolver.DisableIPv6 = !general.IPv6 resolver.DisableIPv6 = !general.IPv6
} }
func applyConfig(isPatch bool) bool { func applyConfig(isPatch bool) {
if currentConfig == nil {
return false
}
cfg, err := config.ParseRawConfig(currentConfig) cfg, err := config.ParseRawConfig(currentConfig)
if err != nil { if err != nil {
cfg, _ = config.ParseRawConfig(config.DefaultRawConfig()) cfg, _ = config.ParseRawConfig(config.DefaultRawConfig())
@@ -176,7 +174,5 @@ func applyConfig(isPatch bool) bool {
patchConfig(cfg.General) patchConfig(cfg.General)
} else { } else {
executor.ApplyConfig(cfg, true) executor.ApplyConfig(cfg, true)
} }
return true
} }

View File

@@ -24,7 +24,7 @@ func InitDartApi(api unsafe.Pointer) {
} }
} }
func sendToPort(port int64, msg string) { func SendToPort(port int64, msg string) {
var obj C.Dart_CObject var obj C.Dart_CObject
obj._type = C.Dart_CObject_kString obj._type = C.Dart_CObject_kString
msgString := C.CString(msg) msgString := C.CString(msg)

View File

@@ -24,5 +24,5 @@ func (message *Message) toJson() string {
} }
func SendMessage(message Message) { func SendMessage(message Message) {
sendToPort(*Port, message.toJson()) SendToPort(*Port, message.toJson())
} }

View File

@@ -21,7 +21,7 @@ import (
"unsafe" "unsafe"
) )
var currentConfig *config.RawConfig var currentConfig = config.DefaultRawConfig()
var isInit = false var isInit = false
@@ -63,26 +63,30 @@ func validateConfig(s *C.char) bool {
} }
//export updateConfig //export updateConfig
func updateConfig(s *C.char) bool { func updateConfig(s *C.char, port C.longlong) {
paramsString := C.GoString(s) i := int64(port)
var params = &GenerateConfigParams{} go func() {
err := json.Unmarshal([]byte(paramsString), params) paramsString := C.GoString(s)
if err != nil { var params = &GenerateConfigParams{}
log.Errorln("generateConfig Unmarshal error %v", err) err := json.Unmarshal([]byte(paramsString), params)
return false if err != nil {
} bridge.SendToPort(i, err.Error())
prof := decorationConfig(params.ProfilePath, *params.Config) return
currentConfig = prof }
if *params.IsPatch { prof := decorationConfig(params.ProfilePath, *params.Config)
return applyConfig(true) currentConfig = prof
} else { if *params.IsPatch {
return applyConfig(false) applyConfig(true)
} } else {
applyConfig(false)
}
bridge.SendToPort(i, "")
}()
} }
//export getProxies //export getProxies
func getProxies() *C.char { func getProxies() *C.char {
data, err := json.Marshal(tunnel.Proxies()) data, err := json.Marshal(tunnel.ProxiesWithProviders())
if err != nil { if err != nil {
return C.CString("") return C.CString("")
} }
@@ -98,7 +102,7 @@ func changeProxy(s *C.char) bool {
log.Infoln("Unmarshal ChangeProxyParams %v", err) log.Infoln("Unmarshal ChangeProxyParams %v", err)
return false return false
} }
proxies := tunnel.Proxies() proxies := tunnel.ProxiesWithProviders()
proxy := proxies[*params.GroupName] proxy := proxies[*params.GroupName]
if proxy == nil { if proxy == nil {
return false return false
@@ -148,7 +152,7 @@ func asyncTestDelay(s *C.char) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(params.Timeout)) ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(params.Timeout))
defer cancel() defer cancel()
proxies := tunnel.Proxies() proxies := tunnel.ProxiesWithProviders()
proxy := proxies[params.ProxyName] proxy := proxies[params.ProxyName]
delayData := &Delay{ delayData := &Delay{

View File

@@ -112,7 +112,6 @@ class ApplicationState extends State<Application> {
primaryColor: config.primaryColor, primaryColor: config.primaryColor,
), ),
builder: (_, state, child) { builder: (_, state, child) {
debugPrint("[Application] update===>");
return DynamicColorBuilder( return DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) { builder: (lightDynamic, darkDynamic) {
_updateSystemColorSchemes(lightDynamic, darkDynamic); _updateSystemColorSchemes(lightDynamic, darkDynamic);

View File

@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:ffi'; import 'dart:ffi';
import 'dart:io'; import 'dart:io';
@@ -16,19 +17,22 @@ class ClashCore {
late final ClashFFI clashFFI; late final ClashFFI clashFFI;
late final DynamicLibrary lib; late final DynamicLibrary lib;
ClashCore._internal() { DynamicLibrary _getClashLib() {
if (Platform.isWindows) { if (Platform.isWindows) {
lib = DynamicLibrary.open("libclash.dll"); return DynamicLibrary.open("libclash.dll");
clashFFI = ClashFFI(lib);
} }
if (Platform.isMacOS) { if (Platform.isMacOS) {
lib = DynamicLibrary.open("libclash.dylib"); return DynamicLibrary.open("libclash.dylib");
clashFFI = ClashFFI(lib);
} }
if (Platform.isAndroid || Platform.isLinux) { if (Platform.isAndroid || Platform.isLinux) {
lib = DynamicLibrary.open("libclash.so"); return DynamicLibrary.open("libclash.so");
clashFFI = ClashFFI(lib);
} }
throw "Platform is not supported";
}
ClashCore._internal() {
lib = _getClashLib();
clashFFI = ClashFFI(lib);
clashFFI.initNativeApiBridge( clashFFI.initNativeApiBridge(
NativeApi.initializeApiDLData, NativeApi.initializeApiDLData,
receiver.sendPort.nativePort, receiver.sendPort.nativePort,
@@ -61,51 +65,49 @@ class ClashCore {
1; 1;
} }
bool updateConfig(UpdateConfigParams updateConfigParams) { Future<String> updateConfig(UpdateConfigParams updateConfigParams) {
final completer = Completer<String>();
final receiver = ReceivePort();
receiver.listen((message) {
if(!completer.isCompleted){
completer.complete(message);
receiver.close();
}
});
final params = json.encode(updateConfigParams); final params = json.encode(updateConfigParams);
return clashFFI.updateConfig( clashFFI.updateConfig(
params.toNativeUtf8().cast(), params.toNativeUtf8().cast(),
) == receiver.sendPort.nativePort,
1; );
return completer.future;
} }
List<Group> getProxiesGroups() { Future<List<Group>> getProxiesGroups() {
final proxiesRaw = clashFFI.getProxies(); final proxiesRaw = clashFFI.getProxies();
final proxies = json.decode(proxiesRaw.cast<Utf8>().toDartString()); final proxiesRawString = proxiesRaw.cast<Utf8>().toDartString();
final groupsRaw = List.from(proxies.values).where((e) { return Isolate.run<List<Group>>(() {
final excludeName = !UsedProxyExtension.valueList final proxies = json.decode(proxiesRawString);
.where((element) => element != UsedProxy.GLOBAL.name) final groupNames = [
.contains(e['name']); UsedProxy.GLOBAL.name,
final validType = GroupTypeExtension.valueList.contains(e['type']); ...(proxies[UsedProxy.GLOBAL.name]["all"] as List).where((e) {
return excludeName && validType; final proxy = proxies[e];
}).map( return GroupTypeExtension.valueList.contains(proxy['type']);
(e) { })
e["all"] = ((e["all"] ?? []) as List) ];
final groupsRaw = groupNames.map((groupName) {
final group = proxies[groupName];
group["all"] = ((group["all"] ?? []) as List)
.where(
(name) => !groupNames.contains(groupNames),
)
.map( .map(
(name) => proxies[name], (name) => proxies[name],
) )
.toList(); .toList();
return e; return group;
}, }).toList();
).toList() return groupsRaw.map((e) => Group.fromJson(e)).toList();
..sort( });
(a, b) {
final aIndex = GroupTypeExtension.getGroupType(a['type'])?.index;
final bIndex = GroupTypeExtension.getGroupType(b['type'])?.index;
if (a == null && b == null) {
return 0;
}
if (a == null) {
return 1;
}
if (b == null) {
return -1;
}
return aIndex! - bIndex!;
},
);
final groups = groupsRaw.map((e) => Group.fromJson(e)).toList();
return groups;
} }
bool changeProxy(ChangeProxyParams changeProxyParams) { bool changeProxy(ChangeProxyParams changeProxyParams) {

View File

@@ -907,19 +907,22 @@ class ClashFFI {
late final _validateConfig = late final _validateConfig =
_validateConfigPtr.asFunction<int Function(ffi.Pointer<ffi.Char>)>(); _validateConfigPtr.asFunction<int Function(ffi.Pointer<ffi.Char>)>();
int updateConfig( void updateConfig(
ffi.Pointer<ffi.Char> s, ffi.Pointer<ffi.Char> s,
int port,
) { ) {
return _updateConfig( return _updateConfig(
s, s,
port,
); );
} }
late final _updateConfigPtr = late final _updateConfigPtr = _lookup<
_lookup<ffi.NativeFunction<GoUint8 Function(ffi.Pointer<ffi.Char>)>>( ffi.NativeFunction<
'updateConfig'); ffi.Void Function(
ffi.Pointer<ffi.Char>, ffi.LongLong)>>('updateConfig');
late final _updateConfig = late final _updateConfig =
_updateConfigPtr.asFunction<int Function(ffi.Pointer<ffi.Char>)>(); _updateConfigPtr.asFunction<void Function(ffi.Pointer<ffi.Char>, int)>();
ffi.Pointer<ffi.Char> getProxies() { ffi.Pointer<ffi.Char> getProxies() {
return _getProxies(); return _getProxies();

View File

@@ -19,8 +19,8 @@ Function debounce<F extends Function>(F func,{int milliseconds = 600}) {
if (timer != null) { if (timer != null) {
timer!.cancel(); timer!.cancel();
} }
timer = Timer(Duration(milliseconds: milliseconds), () { timer = Timer(Duration(milliseconds: milliseconds), () async {
Function.apply(func, args ?? [], namedArgs); await Function.apply(func, args ?? [], namedArgs);
}); });
}; };
} }

View File

@@ -56,7 +56,9 @@ class AppController {
updateRunTime() { updateRunTime() {
if (proxyManager.startTime != null) { if (proxyManager.startTime != null) {
final startTimeStamp = proxyManager.startTime!.millisecondsSinceEpoch; final startTimeStamp = proxyManager.startTime!.millisecondsSinceEpoch;
final nowTimeStamp = DateTime.now().millisecondsSinceEpoch; final nowTimeStamp = DateTime
.now()
.millisecondsSinceEpoch;
appState.runTime = nowTimeStamp - startTimeStamp; appState.runTime = nowTimeStamp - startTimeStamp;
} else { } else {
appState.runTime = null; appState.runTime = null;
@@ -71,28 +73,10 @@ class AppController {
} }
changeProxy() { changeProxy() {
final currentGroupName = globalState.changeProxy(
appState.getCurrentGroupName(config.currentGroupName, clashConfig.mode); appState: appState,
final currentProxyName = config: config,
appState.getCurrentProxyName(config.currentProxyName, clashConfig.mode); clashConfig: clashConfig,
if (config.profiles.isEmpty || currentProxyName == null) {
updateSystemProxy(false);
return;
}
if (currentGroupName == null) return;
final groupIndex = appState.groups.indexWhere(
(element) => element.name == currentGroupName,
);
if (groupIndex == -1) return;
final proxyIndex = appState.groups[groupIndex].all.indexWhere(
(element) => element.name == currentProxyName,
);
if (proxyIndex == -1) return;
clashCore.changeProxy(
ChangeProxyParams(
groupName: currentGroupName,
proxyName: currentProxyName,
),
); );
} }
@@ -133,7 +117,7 @@ class AppController {
} }
} }
Future<bool> updateClashConfig({bool isPatch = true}) async { Future<String> updateClashConfig({bool isPatch = true}) async {
return await globalState.updateClashConfig( return await globalState.updateClashConfig(
clashConfig: clashConfig, clashConfig: clashConfig,
config: config, config: config,
@@ -141,12 +125,31 @@ class AppController {
); );
} }
applyProfile() async {
await globalState.applyProfile(
appState: appState,
config: config,
clashConfig: clashConfig,
);
}
Function? _changeProfileDebounce;
changeProfileDebounce(String? profileId) {
if (profileId == config.currentProfileId) return;
config.currentProfileId = profileId;
_changeProfileDebounce ??= debounce<Function(String?)>((profileId) async {
await applyProfile();
appState.delayMap = {};
saveConfigPreferences();
});
_changeProfileDebounce!([profileId]);
}
changeProfile(String? value) async { changeProfile(String? value) async {
if (value == config.currentProfileId) return; if (value == config.currentProfileId) return;
config.currentProfileId = value; config.currentProfileId = value;
await updateClashConfig(isPatch: false); await applyProfile();
updateGroups();
changeProxy();
appState.delayMap = {}; appState.delayMap = {};
saveConfigPreferences(); saveConfigPreferences();
} }
@@ -156,19 +159,16 @@ class AppController {
if (!profile.autoUpdate) return; if (!profile.autoUpdate) return;
final isNotNeedUpdate = profile.lastUpdateDate final isNotNeedUpdate = profile.lastUpdateDate
?.add( ?.add(
profile.autoUpdateDuration, profile.autoUpdateDuration,
) )
.isBeforeNow(); .isBeforeNow();
if (isNotNeedUpdate == false) continue; if (isNotNeedUpdate == false) continue;
final result = await profile.update(); await profile.update();
if (result.type == ResultType.error) continue;
updateGroups();
changeProxy();
} }
} }
updateGroups() { Future<void> updateGroups() async {
globalState.updateGroups(appState); await globalState.updateGroups(appState);
} }
updateSystemColorSchemes(SystemColorSchemes systemColorSchemes) { updateSystemColorSchemes(SystemColorSchemes systemColorSchemes) {
@@ -177,7 +177,7 @@ class AppController {
clearCurrentDelay() { clearCurrentDelay() {
final currentProxyName = final currentProxyName =
appState.getCurrentProxyName(config.currentProxyName, clashConfig.mode); appState.getCurrentProxyName(config.currentProxyName, clashConfig.mode);
if (currentProxyName == null) return; if (currentProxyName == null) return;
appState.setDelay(Delay(name: currentProxyName, value: null)); appState.setDelay(Delay(name: currentProxyName, value: null));
} }
@@ -226,7 +226,6 @@ class AppController {
afterInit() async { afterInit() async {
if (appState.isInit) { if (appState.isInit) {
changeProxy();
if (config.autoRun) { if (config.autoRun) {
await updateSystemProxy(true); await updateSystemProxy(true);
} else { } else {
@@ -265,7 +264,7 @@ class AppController {
toProfiles() { toProfiles() {
final index = globalState.currentNavigationItems.indexWhere( final index = globalState.currentNavigationItems.indexWhere(
(element) => element.label == "profiles", (element) => element.label == "profiles",
); );
if (index != -1) { if (index != -1) {
toPage(index); toPage(index);
@@ -278,7 +277,7 @@ class AppController {
final commonScaffoldState = globalState.homeScaffoldKey.currentState; final commonScaffoldState = globalState.homeScaffoldKey.currentState;
if (commonScaffoldState?.mounted != true) return; if (commonScaffoldState?.mounted != true) return;
commonScaffoldState?.loadingRun( commonScaffoldState?.loadingRun(
() async { () async {
await Future.delayed(const Duration(milliseconds: 300)); await Future.delayed(const Duration(milliseconds: 300));
final profile = Profile( final profile = Profile(
url: url, url: url,
@@ -299,7 +298,7 @@ class AppController {
initLink() { initLink() {
linkManager.initAppLinksListen( linkManager.initAppLinksListen(
(url) { (url) {
globalState.showMessage( globalState.showMessage(
title: "${appLocalizations.add}${appLocalizations.profile}", title: "${appLocalizations.add}${appLocalizations.profile}",
message: TextSpan( message: TextSpan(
@@ -308,14 +307,20 @@ class AppController {
TextSpan( TextSpan(
text: " $url ", text: " $url ",
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: Theme
.of(context)
.colorScheme
.primary,
decoration: TextDecoration.underline, decoration: TextDecoration.underline,
decorationColor: Theme.of(context).colorScheme.primary, decorationColor: Theme
.of(context)
.colorScheme
.primary,
), ),
), ),
TextSpan( TextSpan(
text: text:
"${appLocalizations.create}${appLocalizations.profile}"), "${appLocalizations.create}${appLocalizations.profile}"),
], ],
), ),
onTab: () { onTab: () {
@@ -335,7 +340,7 @@ class AppController {
final commonScaffoldState = globalState.homeScaffoldKey.currentState; final commonScaffoldState = globalState.homeScaffoldKey.currentState;
if (commonScaffoldState?.mounted != true) return; if (commonScaffoldState?.mounted != true) return;
commonScaffoldState?.loadingRun( commonScaffoldState?.loadingRun(
() async { () async {
await Future.delayed(const Duration(milliseconds: 300)); await Future.delayed(const Duration(milliseconds: 300));
final bytes = result.data?.bytes; final bytes = result.data?.bytes;
if (bytes == null) { if (bytes == null) {

View File

@@ -9,8 +9,7 @@ extension GroupTypeExtension on GroupType {
) )
.toList(); .toList();
static GroupType? getGroupType(String? value) { static GroupType? getGroupType(String value) {
if (value == null) return null;
final index = GroupTypeExtension.valueList.indexOf(value); final index = GroupTypeExtension.valueList.indexOf(value);
if (index == -1) return null; if (index == -1) return null;
return GroupType.values[index]; return GroupType.values[index];

View File

@@ -12,7 +12,6 @@ class CoreInfo extends StatelessWidget {
return Selector<AppState, VersionInfo?>( return Selector<AppState, VersionInfo?>(
selector: (_, appState) => appState.versionInfo, selector: (_, appState) => appState.versionInfo,
builder: (_, versionInfo, __) { builder: (_, versionInfo, __) {
debugPrint("[CoreInfo] update===>");
return CommonCard( return CommonCard(
info: Info( info: Info(
label: appLocalizations.coreInfo, label: appLocalizations.coreInfo,

View File

@@ -111,7 +111,6 @@ class _NetworkDetectionState extends State<NetworkDetection> {
); );
}, },
builder: (_, state, __) { builder: (_, state, __) {
debugPrint("[UpdateCurrentDelay] update===>");
_updateCurrentDelay( _updateCurrentDelay(
state.currentProxyName, state.currentProxyName,
state.delay, state.delay,
@@ -145,7 +144,6 @@ class _NetworkDetectionState extends State<NetworkDetection> {
); );
}, },
builder: (_, state, __) { builder: (_, state, __) {
debugPrint("[NetworkDetection] update===>");
return Container( return Container(
padding: const EdgeInsets.all(16).copyWith(top: 0), padding: const EdgeInsets.all(16).copyWith(top: 0),
child: Column( child: Column(

View File

@@ -63,7 +63,6 @@ class _StartButtonState extends State<StartButton>
hasProfile: config.profiles.isNotEmpty, hasProfile: config.profiles.isNotEmpty,
), ),
builder: (_, state, child) { builder: (_, state, child) {
debugPrint("[StartButton] update===>");
if (!state.isInit || !state.hasProfile) { if (!state.isInit || !state.hasProfile) {
return Container(); return Container();
} }

View File

@@ -24,6 +24,7 @@ class ProfilesFragment extends StatefulWidget {
} }
class _ProfilesFragmentState extends State<ProfilesFragment> { class _ProfilesFragmentState extends State<ProfilesFragment> {
String _getLastUpdateTimeDifference(DateTime lastDateTime) { String _getLastUpdateTimeDifference(DateTime lastDateTime) {
final currentDateTime = DateTime.now(); final currentDateTime = DateTime.now();
final difference = currentDateTime.difference(lastDateTime); final difference = currentDateTime.difference(lastDateTime);
@@ -209,7 +210,7 @@ class _ProfilesFragmentState extends State<ProfilesFragment> {
child: _profileItem( child: _profileItem(
profile: profile, profile: profile,
groupValue: state.currentProfileId, groupValue: state.currentProfileId,
onChanged: context.appController.changeProfile, onChanged: context.appController.changeProfileDebounce,
), ),
), ),
], ],
@@ -234,7 +235,6 @@ class _ProfilesFragmentState extends State<ProfilesFragment> {
currentProfileId: config.currentProfileId, currentProfileId: config.currentProfileId,
), ),
builder: (context, state, child) { builder: (context, state, child) {
debugPrint("[Profiles] update===>");
if (state.profiles.isEmpty) { if (state.profiles.isEmpty) {
return NullStatus( return NullStatus(
label: appLocalizations.nullProfileDesc, label: appLocalizations.nullProfileDesc,

View File

@@ -1,4 +1,3 @@
import 'package:collection/collection.dart';
import 'package:fl_clash/clash/clash.dart'; import 'package:fl_clash/clash/clash.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
@@ -57,26 +56,6 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
}); });
} }
_updateTabController(length) {
if (_tabController != null) {
_tabController!.dispose();
_tabController = null;
}
_tabController = TabController(
length: length,
vsync: this,
);
}
@override
void dispose() {
if (_tabController != null) {
_tabController!.dispose();
_tabController = null;
}
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Selector<AppState, bool>( return Selector<AppState, bool>(
@@ -87,14 +66,31 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
} }
return child!; return child!;
}, },
child: Selector2<AppState, ClashConfig, List<Group>>( child: Selector3<AppState, Config, ClashConfig, ProxiesSelectorState>(
selector: (_, appState, clashConfig) => selector: (_, appState, config, clashConfig) {
appState.getCurrentGroups(clashConfig.mode), final currentGroups = appState.getCurrentGroups(clashConfig.mode);
shouldRebuild: (prev, next) => final currentProxyName = appState.getCurrentGroupNameWithGroups(
!const ListEquality<Group>().equals(prev, next), currentGroups,
builder: (_, groups, __) { config.currentGroupName,
debugPrint("[Proxies] update===>"); clashConfig.mode,
_updateTabController(groups.length); );
final currentIndex = currentGroups
.indexWhere((element) => element.name == currentProxyName);
return ProxiesSelectorState(
currentIndex: currentIndex != -1 ? currentIndex : 0,
groups: currentGroups,
);
},
builder: (_, state, __) {
if (_tabController != null) {
_tabController!.dispose();
_tabController = null;
}
_tabController = TabController(
length: state.groups.length,
vsync: this,
initialIndex: state.currentIndex,
);
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@@ -108,7 +104,7 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
overlayColor: overlayColor:
const MaterialStatePropertyAll(Colors.transparent), const MaterialStatePropertyAll(Colors.transparent),
tabs: [ tabs: [
for (final group in groups) for (final group in state.groups)
Tab( Tab(
text: group.name, text: group.name,
), ),
@@ -118,7 +114,7 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
child: TabBarView( child: TabBarView(
controller: _tabController, controller: _tabController,
children: [ children: [
for (final group in groups) for (final group in state.groups)
KeepContainer( KeepContainer(
child: ProxiesTabView( child: ProxiesTabView(
group: group, group: group,
@@ -197,7 +193,7 @@ class _ProxiesTabViewState extends State<ProxiesTabView>
_controller.dispose(); _controller.dispose();
} }
get group => widget.group; Group get group => widget.group;
get measure => context.appController.measure; get measure => context.appController.measure;
@@ -369,25 +365,33 @@ class _ProxiesTabViewState extends State<ProxiesTabView>
}) { }) {
return SingleChildScrollView( return SingleChildScrollView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: AnimateGrid<Proxy>( child: Selector3<AppState, Config, ClashConfig, ProxiesCardSelectorState>(
items: _getProxies(group.all, proxiesSortType), selector: (_, appState, config, clashConfig) =>
columns: columns, ProxiesCardSelectorState(
itemHeight: _getItemHeight(), currentGroupName: appState.getCurrentGroupName(
keyBuilder: (item) { config.currentGroupName,
return ObjectKey(item); clashConfig.mode,
}, ),
builder: (_, proxy) { currentProxyName: appState.getCurrentProxyName(
return Selector3<AppState, Config, ClashConfig, String?>( config.currentProxyName,
selector: (_, appState, config, clashConfig) => clashConfig.mode,
appState.getCurrentProxyName( ),
config.currentProxyName, ),
clashConfig.mode, builder: (_, state, __) {
), return AnimateGrid<Proxy>(
builder: (_, value, __) { items: _getProxies(group.all, proxiesSortType),
final currentProxyName = columns: columns,
group.type == GroupType.Selector ? value : group.now; itemHeight: _getItemHeight(),
keyBuilder: (item) {
return ObjectKey(item);
},
builder: (_, proxy) {
final isSelected = group.type == GroupType.Selector
? group.name == state.currentGroupName &&
proxy.name == state.currentProxyName
: group.now == proxy.name;
return _card( return _card(
isSelected: proxy.name == currentProxyName, isSelected: isSelected,
onPressed: () { onPressed: () {
if (group.type == GroupType.Selector) { if (group.type == GroupType.Selector) {
final config = context.read<Config>(); final config = context.read<Config>();

View File

@@ -78,6 +78,7 @@ Future<void> vpnService() async {
TileListenerWithVpn( TileListenerWithVpn(
onStop: () async { onStop: () async {
await app?.tip(appLocalizations.stopVpn); await app?.tip(appLocalizations.stopVpn);
await globalState.stopSystemProxy();
clashCore.shutdown(); clashCore.shutdown();
exit(0); exit(0);
}, },

View File

@@ -165,19 +165,26 @@ class AppState with ChangeNotifier {
} }
} }
String? getCurrentGroupName(String? groupName, Mode mode) { String? getCurrentGroupNameWithGroups(
final currentGroups = getCurrentGroups(mode); List<Group> groups,
String? groupName,
Mode mode,
) {
switch (mode) { switch (mode) {
case Mode.direct: case Mode.direct:
return null; return null;
case Mode.global: case Mode.global:
return UsedProxy.GLOBAL.name; return UsedProxy.GLOBAL.name;
case Mode.rule: case Mode.rule:
return groupName ?? return groupName ?? (groups.isNotEmpty ? groups.first.name : null);
(currentGroups.isNotEmpty ? currentGroups.first.name : null);
} }
} }
String? getCurrentGroupName(String? groupName, Mode mode) {
final currentGroups = getCurrentGroups(mode);
return getCurrentGroupNameWithGroups(currentGroups, groupName, mode);
}
String? getCurrentProxyName(String? proxyName, Mode mode) { String? getCurrentProxyName(String? proxyName, Mode mode) {
final currentGroups = getCurrentGroups(mode); final currentGroups = getCurrentGroups(mode);
switch (mode) { switch (mode) {

View File

@@ -87,7 +87,7 @@ class Config extends ChangeNotifier {
_isMinimizeOnExit = true, _isMinimizeOnExit = true,
_isAccessControl = false, _isAccessControl = false,
_accessControl = AccessControl(), _accessControl = AccessControl(),
_isAnimateToPage = false; _isAnimateToPage = true;
deleteProfileById(String id) { deleteProfileById(String id) {
_profiles = profiles.where((element) => element.id != id).toList(); _profiles = profiles.where((element) => element.id != id).toList();

View File

@@ -1740,3 +1740,295 @@ abstract class _HomeNavigationSelectorState
_$$HomeNavigationSelectorStateImplCopyWith<_$HomeNavigationSelectorStateImpl> _$$HomeNavigationSelectorStateImplCopyWith<_$HomeNavigationSelectorStateImpl>
get copyWith => throw _privateConstructorUsedError; get copyWith => throw _privateConstructorUsedError;
} }
/// @nodoc
mixin _$ProxiesSelectorState {
int get currentIndex => throw _privateConstructorUsedError;
List<Group> get groups => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ProxiesSelectorStateCopyWith<ProxiesSelectorState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProxiesSelectorStateCopyWith<$Res> {
factory $ProxiesSelectorStateCopyWith(ProxiesSelectorState value,
$Res Function(ProxiesSelectorState) then) =
_$ProxiesSelectorStateCopyWithImpl<$Res, ProxiesSelectorState>;
@useResult
$Res call({int currentIndex, List<Group> groups});
}
/// @nodoc
class _$ProxiesSelectorStateCopyWithImpl<$Res,
$Val extends ProxiesSelectorState>
implements $ProxiesSelectorStateCopyWith<$Res> {
_$ProxiesSelectorStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? currentIndex = null,
Object? groups = null,
}) {
return _then(_value.copyWith(
currentIndex: null == currentIndex
? _value.currentIndex
: currentIndex // ignore: cast_nullable_to_non_nullable
as int,
groups: null == groups
? _value.groups
: groups // ignore: cast_nullable_to_non_nullable
as List<Group>,
) as $Val);
}
}
/// @nodoc
abstract class _$$ProxiesSelectorStateImplCopyWith<$Res>
implements $ProxiesSelectorStateCopyWith<$Res> {
factory _$$ProxiesSelectorStateImplCopyWith(_$ProxiesSelectorStateImpl value,
$Res Function(_$ProxiesSelectorStateImpl) then) =
__$$ProxiesSelectorStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({int currentIndex, List<Group> groups});
}
/// @nodoc
class __$$ProxiesSelectorStateImplCopyWithImpl<$Res>
extends _$ProxiesSelectorStateCopyWithImpl<$Res, _$ProxiesSelectorStateImpl>
implements _$$ProxiesSelectorStateImplCopyWith<$Res> {
__$$ProxiesSelectorStateImplCopyWithImpl(_$ProxiesSelectorStateImpl _value,
$Res Function(_$ProxiesSelectorStateImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? currentIndex = null,
Object? groups = null,
}) {
return _then(_$ProxiesSelectorStateImpl(
currentIndex: null == currentIndex
? _value.currentIndex
: currentIndex // ignore: cast_nullable_to_non_nullable
as int,
groups: null == groups
? _value._groups
: groups // ignore: cast_nullable_to_non_nullable
as List<Group>,
));
}
}
/// @nodoc
class _$ProxiesSelectorStateImpl implements _ProxiesSelectorState {
const _$ProxiesSelectorStateImpl(
{required this.currentIndex, required final List<Group> groups})
: _groups = groups;
@override
final int currentIndex;
final List<Group> _groups;
@override
List<Group> get groups {
if (_groups is EqualUnmodifiableListView) return _groups;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_groups);
}
@override
String toString() {
return 'ProxiesSelectorState(currentIndex: $currentIndex, groups: $groups)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProxiesSelectorStateImpl &&
(identical(other.currentIndex, currentIndex) ||
other.currentIndex == currentIndex) &&
const DeepCollectionEquality().equals(other._groups, _groups));
}
@override
int get hashCode => Object.hash(
runtimeType, currentIndex, const DeepCollectionEquality().hash(_groups));
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$ProxiesSelectorStateImplCopyWith<_$ProxiesSelectorStateImpl>
get copyWith =>
__$$ProxiesSelectorStateImplCopyWithImpl<_$ProxiesSelectorStateImpl>(
this, _$identity);
}
abstract class _ProxiesSelectorState implements ProxiesSelectorState {
const factory _ProxiesSelectorState(
{required final int currentIndex,
required final List<Group> groups}) = _$ProxiesSelectorStateImpl;
@override
int get currentIndex;
@override
List<Group> get groups;
@override
@JsonKey(ignore: true)
_$$ProxiesSelectorStateImplCopyWith<_$ProxiesSelectorStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$ProxiesCardSelectorState {
String? get currentGroupName => throw _privateConstructorUsedError;
String? get currentProxyName => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ProxiesCardSelectorStateCopyWith<ProxiesCardSelectorState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProxiesCardSelectorStateCopyWith<$Res> {
factory $ProxiesCardSelectorStateCopyWith(ProxiesCardSelectorState value,
$Res Function(ProxiesCardSelectorState) then) =
_$ProxiesCardSelectorStateCopyWithImpl<$Res, ProxiesCardSelectorState>;
@useResult
$Res call({String? currentGroupName, String? currentProxyName});
}
/// @nodoc
class _$ProxiesCardSelectorStateCopyWithImpl<$Res,
$Val extends ProxiesCardSelectorState>
implements $ProxiesCardSelectorStateCopyWith<$Res> {
_$ProxiesCardSelectorStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? currentGroupName = freezed,
Object? currentProxyName = freezed,
}) {
return _then(_value.copyWith(
currentGroupName: freezed == currentGroupName
? _value.currentGroupName
: currentGroupName // ignore: cast_nullable_to_non_nullable
as String?,
currentProxyName: freezed == currentProxyName
? _value.currentProxyName
: currentProxyName // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}
}
/// @nodoc
abstract class _$$ProxiesCardSelectorStateImplCopyWith<$Res>
implements $ProxiesCardSelectorStateCopyWith<$Res> {
factory _$$ProxiesCardSelectorStateImplCopyWith(
_$ProxiesCardSelectorStateImpl value,
$Res Function(_$ProxiesCardSelectorStateImpl) then) =
__$$ProxiesCardSelectorStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String? currentGroupName, String? currentProxyName});
}
/// @nodoc
class __$$ProxiesCardSelectorStateImplCopyWithImpl<$Res>
extends _$ProxiesCardSelectorStateCopyWithImpl<$Res,
_$ProxiesCardSelectorStateImpl>
implements _$$ProxiesCardSelectorStateImplCopyWith<$Res> {
__$$ProxiesCardSelectorStateImplCopyWithImpl(
_$ProxiesCardSelectorStateImpl _value,
$Res Function(_$ProxiesCardSelectorStateImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? currentGroupName = freezed,
Object? currentProxyName = freezed,
}) {
return _then(_$ProxiesCardSelectorStateImpl(
currentGroupName: freezed == currentGroupName
? _value.currentGroupName
: currentGroupName // ignore: cast_nullable_to_non_nullable
as String?,
currentProxyName: freezed == currentProxyName
? _value.currentProxyName
: currentProxyName // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
class _$ProxiesCardSelectorStateImpl implements _ProxiesCardSelectorState {
const _$ProxiesCardSelectorStateImpl(
{required this.currentGroupName, required this.currentProxyName});
@override
final String? currentGroupName;
@override
final String? currentProxyName;
@override
String toString() {
return 'ProxiesCardSelectorState(currentGroupName: $currentGroupName, currentProxyName: $currentProxyName)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProxiesCardSelectorStateImpl &&
(identical(other.currentGroupName, currentGroupName) ||
other.currentGroupName == currentGroupName) &&
(identical(other.currentProxyName, currentProxyName) ||
other.currentProxyName == currentProxyName));
}
@override
int get hashCode =>
Object.hash(runtimeType, currentGroupName, currentProxyName);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$ProxiesCardSelectorStateImplCopyWith<_$ProxiesCardSelectorStateImpl>
get copyWith => __$$ProxiesCardSelectorStateImplCopyWithImpl<
_$ProxiesCardSelectorStateImpl>(this, _$identity);
}
abstract class _ProxiesCardSelectorState implements ProxiesCardSelectorState {
const factory _ProxiesCardSelectorState(
{required final String? currentGroupName,
required final String? currentProxyName}) =
_$ProxiesCardSelectorStateImpl;
@override
String? get currentGroupName;
@override
String? get currentProxyName;
@override
@JsonKey(ignore: true)
_$$ProxiesCardSelectorStateImplCopyWith<_$ProxiesCardSelectorStateImpl>
get copyWith => throw _privateConstructorUsedError;
}

View File

@@ -5,6 +5,7 @@ import 'config.dart';
import 'navigation.dart'; import 'navigation.dart';
import 'package.dart'; import 'package.dart';
import 'profile.dart'; import 'profile.dart';
import 'proxy.dart';
part 'generated/selector.freezed.dart'; part 'generated/selector.freezed.dart';
@@ -101,3 +102,19 @@ class HomeNavigationSelectorState with _$HomeNavigationSelectorState{
required String? locale, required String? locale,
}) = _HomeNavigationSelectorState; }) = _HomeNavigationSelectorState;
} }
@freezed
class ProxiesSelectorState with _$ProxiesSelectorState{
const factory ProxiesSelectorState({
required int currentIndex,
required List<Group> groups,
}) = _ProxiesSelectorState;
}
@freezed
class ProxiesCardSelectorState with _$ProxiesCardSelectorState{
const factory ProxiesCardSelectorState({
required String? currentGroupName,
required String? currentProxyName,
}) = _ProxiesCardSelectorState;
}

View File

@@ -140,7 +140,6 @@ class HomePage extends StatelessWidget {
child: Selector<AppState, List<NavigationItem>>( child: Selector<AppState, List<NavigationItem>>(
selector: (_, appState) => appState.navigationItems, selector: (_, appState) => appState.navigationItems,
builder: (_, navigationItems, __) { builder: (_, navigationItems, __) {
debugPrint("[Home] update===>");
final desktopNavigationItems = navigationItems final desktopNavigationItems = navigationItems
.where( .where(
(element) => (element) =>

View File

@@ -38,7 +38,7 @@ class GlobalState {
timer?.cancel(); timer?.cancel();
} }
Future<bool> updateClashConfig({ Future<String> updateClashConfig({
required ClashConfig clashConfig, required ClashConfig clashConfig,
required Config config, required Config config,
bool isPatch = true, bool isPatch = true,
@@ -87,6 +87,25 @@ class GlobalState {
updateCurrentDelayDebounce!([proxyName]); updateCurrentDelayDebounce!([proxyName]);
} }
applyProfile({
required AppState appState,
required Config config,
required ClashConfig clashConfig,
}) async {
final res = await updateClashConfig(
clashConfig: clashConfig,
config: config,
isPatch: false,
);
if (res.isNotEmpty) return Result.error(message: res);
await updateGroups(appState);
changeProxy(
appState: appState,
config: config,
clashConfig: clashConfig,
);
}
init({ init({
required AppState appState, required AppState appState,
required Config config, required Config config,
@@ -100,15 +119,44 @@ class GlobalState {
); );
} }
if (!appState.isInit) return; if (!appState.isInit) return;
await updateClashConfig( await applyProfile(
clashConfig: clashConfig, appState: appState,
config: config, config: config,
isPatch: false, clashConfig: clashConfig,
); );
updateGroups(appState);
updateCoreVersionInfo(appState); updateCoreVersionInfo(appState);
} }
changeProxy({
required AppState appState,
required Config config,
required ClashConfig clashConfig,
}) {
final currentGroupName =
appState.getCurrentGroupName(config.currentGroupName, clashConfig.mode);
final currentProxyName =
appState.getCurrentProxyName(config.currentProxyName, clashConfig.mode);
if (config.profiles.isEmpty || currentProxyName == null) {
stopSystemProxy();
return;
}
if (currentGroupName == null) return;
final groupIndex = appState.groups.indexWhere(
(element) => element.name == currentGroupName,
);
if (groupIndex == -1) return;
final proxyIndex = appState.groups[groupIndex].all.indexWhere(
(element) => element.name == currentProxyName,
);
if (proxyIndex == -1) return;
clashCore.changeProxy(
ChangeProxyParams(
groupName: currentGroupName,
proxyName: currentProxyName,
),
);
}
updatePackages(AppState appState) async { updatePackages(AppState appState) async {
if (appState.packages.isEmpty && updatePackagesLock == false) { if (appState.packages.isEmpty && updatePackagesLock == false) {
updatePackagesLock = true; updatePackagesLock = true;
@@ -130,8 +178,8 @@ class GlobalState {
); );
} }
updateGroups(AppState appState) { Future<void> updateGroups(AppState appState) async {
appState.groups = clashCore.getProxiesGroups(); appState.groups = await clashCore.getProxiesGroups();
} }
showMessage({ showMessage({
@@ -198,7 +246,7 @@ class GlobalState {
required Config config, required Config config,
}) { }) {
final traffic = clashCore.getTraffic(); final traffic = clashCore.getTraffic();
if(appState != null){ if (appState != null) {
appState.addTraffic(traffic); appState.addTraffic(traffic);
} }
if (Platform.isAndroid) { if (Platform.isAndroid) {

View File

@@ -15,7 +15,6 @@ class AppStateContainer extends StatelessWidget {
return Selector<Config, bool>( return Selector<Config, bool>(
selector: (_, config) => config.autoLaunch, selector: (_, config) => config.autoLaunch,
builder: (_, isAutoLaunch, child) { builder: (_, isAutoLaunch, child) {
debugPrint("[autoLaunchContainer] update===>");
autoLaunch?.updateStatus(isAutoLaunch); autoLaunch?.updateStatus(isAutoLaunch);
return child!; return child!;
}, },
@@ -35,7 +34,6 @@ class AppStateContainer extends StatelessWidget {
); );
}, },
builder: (context, state, child) { builder: (context, state, child) {
debugPrint("[NavigationsContainer] update===>");
WidgetsBinding.instance.addPostFrameCallback( WidgetsBinding.instance.addPostFrameCallback(
(_) { (_) {
context.appController.appState.navigationItems = context.appController.appState.navigationItems =

View File

@@ -446,7 +446,6 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
return Selector<Config, ThemeMode>( return Selector<Config, ThemeMode>(
selector: (_, config) => config.themeMode, selector: (_, config) => config.themeMode,
builder: (_, __, ___) { builder: (_, __, ___) {
debugPrint("[OpenContainerTheme] update===>");
_colorTween = _getColorTween( _colorTween = _getColorTween(
transitionType: transitionType, transitionType: transitionType,
closedColor: Theme.of(context).colorScheme.background, closedColor: Theme.of(context).colorScheme.background,

View File

@@ -144,7 +144,6 @@ class _TrayContainerState extends State<TrayContainer> with TrayListener {
locale: config.locale, locale: config.locale,
), ),
builder: (_, state, child) { builder: (_, state, child) {
debugPrint("[TrayContainer] update===>");
WidgetsBinding.instance.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
updateMenu(state); updateMenu(state);
}); });

View File

@@ -258,10 +258,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_adaptive_scaffold name: flutter_adaptive_scaffold
sha256: "600bbe237530a249f957f7d0f36273c20bd38d137e28e098c5231c30cadbe927" sha256: "9a1d5e9f728815e27b7b612883db19107ba8a35a46a97c757ea00896cb027451"
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.1.10+1" version: "0.1.10+2"
flutter_lints: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:
@@ -279,10 +279,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: flutter_plugin_android_lifecycle name: flutter_plugin_android_lifecycle
sha256: "592dc01a18961a51c24ae5d963b724b2b7fa4a95c100fe8eb6ca8a5a4732cadf" sha256: "8cf40eebf5dec866a6d1956ad7b4f7016e6c0cc69847ab946833b7d43743809f"
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.18" version: "2.0.19"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@@ -997,10 +997,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: yaml_edit name: yaml_edit
sha256: c566f4f804215d84a7a2c377667f546c6033d5b34b4f9e60dfb09d17c4e97826 sha256: e9c1a3543d2da0db3e90270dbb1e4eebc985ee5e3ffe468d83224472b2194a5f
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.2.0" version: "2.2.1"
sdks: sdks:
dart: ">=3.3.0 <4.0.0" dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0" flutter: ">=3.19.0"

View File

@@ -1,7 +1,7 @@
name: fl_clash name: fl_clash
description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free. description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
publish_to: 'none' publish_to: 'none'
version: 0.7.0 version: 0.7.9
environment: environment:
sdk: '>=3.1.0 <4.0.0' sdk: '>=3.1.0 <4.0.0'