diff --git a/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt b/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt index 5c1d1aaa..ef81b234 100644 --- a/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt +++ b/android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt @@ -48,13 +48,16 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware private val iconMap = mutableMapOf() override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + scope = CoroutineScope(Dispatchers.Default) context = flutterPluginBinding.applicationContext; channel = MethodChannel(flutterPluginBinding.binaryMessenger, "app") channel.setMethodCallHandler(this) + } override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) + scope.cancel() } private fun tip(message: String?) { @@ -224,7 +227,6 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware override fun onAttachedToActivity(binding: ActivityPluginBinding) { activity = binding.activity; - scope = CoroutineScope(Dispatchers.Default) } override fun onDetachedFromActivityForConfigChanges() { @@ -237,7 +239,6 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware override fun onDetachedFromActivity() { channel.invokeMethod("exit", null) - scope.cancel() activity = null } } diff --git a/android/app/src/main/kotlin/com/follow/clash/plugins/ProxyPlugin.kt b/android/app/src/main/kotlin/com/follow/clash/plugins/ProxyPlugin.kt index b6301732..3fb4bbad 100644 --- a/android/app/src/main/kotlin/com/follow/clash/plugins/ProxyPlugin.kt +++ b/android/app/src/main/kotlin/com/follow/clash/plugins/ProxyPlugin.kt @@ -46,8 +46,6 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar flClashVpnService = binder.getService() if (isStart) { startVpn() - } else { - flClashVpnService?.initServiceEngine() } } diff --git a/android/app/src/main/kotlin/com/follow/clash/services/FlClashVpnService.kt b/android/app/src/main/kotlin/com/follow/clash/services/FlClashVpnService.kt index 87d477d9..fa412f23 100644 --- a/android/app/src/main/kotlin/com/follow/clash/services/FlClashVpnService.kt +++ b/android/app/src/main/kotlin/com/follow/clash/services/FlClashVpnService.kt @@ -44,6 +44,11 @@ class FlClashVpnService : VpnService() { "192.168.*" ) + override fun onCreate() { + super.onCreate() + initServiceEngine() + } + fun start(port: Int, props: Props?): Int? { return with(Builder()) { addAddress("172.16.0.1", 30) diff --git a/lib/common/package.dart b/lib/common/package.dart index cad54a5a..f864a5ca 100644 --- a/lib/common/package.dart +++ b/lib/common/package.dart @@ -7,7 +7,7 @@ import 'common.dart'; extension PackageInfoExtension on PackageInfo { String get ua => [ "$appName/v$version", - "clash-verge/v1.6.6", + "clash-verge", "Platform/${Platform.operatingSystem}", ].join(" "); } diff --git a/lib/fragments/dashboard/outbound_mode.dart b/lib/fragments/dashboard/outbound_mode.dart index c36ca89a..7cfc6ab9 100644 --- a/lib/fragments/dashboard/outbound_mode.dart +++ b/lib/fragments/dashboard/outbound_mode.dart @@ -16,6 +16,7 @@ class OutboundMode extends StatelessWidget { if (value == null || clashConfig.mode == value) return; clashConfig.mode = value; await appController.updateClashConfig(); + appController.addCheckIpNumDebounce(); } @override diff --git a/lib/fragments/profiles/profiles.dart b/lib/fragments/profiles/profiles.dart index 04e32759..4728f940 100644 --- a/lib/fragments/profiles/profiles.dart +++ b/lib/fragments/profiles/profiles.dart @@ -216,7 +216,12 @@ class _ProfileItemState extends State { Future updateProfile([isSingle = true]) async { isUpdating.value = true; try { - await globalState.appController.updateProfile(widget.profile); + final appController = globalState.appController; + await appController.updateProfile(widget.profile); + if (widget.profile.id == appController.config.currentProfile?.id && + !appController.appState.isStart) { + globalState.appController.rawApplyProfile(); + } } catch (e) { isUpdating.value = false; if (!isSingle) { diff --git a/lib/main.dart b/lib/main.dart index 9e3913e7..3ff77088 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io'; import 'package:fl_clash/clash/clash.dart'; import 'package:fl_clash/plugins/app.dart'; @@ -66,6 +67,7 @@ Future vpnService() async { clashCore.setFdMap(fd.id); }, onProcess: (Process process) async { + print(process); var packageName = await app?.resolverProcess(process); clashCore.setProcessMap( ProcessMapItem( @@ -110,6 +112,7 @@ Future vpnService() async { onStop: () async { await app?.tip(appLocalizations.stopVpn); await globalState.stopSystemProxy(); + exit(0); }, ), ); diff --git a/lib/plugins/proxy.dart b/lib/plugins/proxy.dart index 7832a77f..3f19999f 100644 --- a/lib/plugins/proxy.dart +++ b/lib/plugins/proxy.dart @@ -105,16 +105,12 @@ class Proxy extends ProxyPlatform { switch (m.type) { case ServiceMessageType.protect: _serviceMessageHandler?.onProtect(Fd.fromJson(m.data)); - break; case ServiceMessageType.process: _serviceMessageHandler?.onProcess(Process.fromJson(m.data)); - break; case ServiceMessageType.started: _serviceMessageHandler?.onStarted(m.data); - break; case ServiceMessageType.loaded: _serviceMessageHandler?.onLoaded(m.data); - break; } } } diff --git a/pubspec.yaml b/pubspec.yaml index ac431290..8f7193f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: fl_clash description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free. publish_to: 'none' -version: 0.8.36+202407131 +version: 0.8.36+202407132 environment: sdk: '>=3.1.0 <4.0.0'