From 1c54db6bf3244c0c780f63966bb91451efb3bd0f Mon Sep 17 00:00:00 2001 From: chen08209 Date: Mon, 15 Jul 2024 16:14:19 +0800 Subject: [PATCH] Rollback partial modification --- .../kotlin/com/follow/clash/GlobalState.kt | 2 +- .../clash/services/FlClashVpnService.kt | 23 +++++++++++-------- lib/main.dart | 11 ++++----- lib/plugins/proxy.dart | 2 ++ pubspec.yaml | 2 +- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/android/app/src/main/kotlin/com/follow/clash/GlobalState.kt b/android/app/src/main/kotlin/com/follow/clash/GlobalState.kt index 760b2ca2..30197e02 100644 --- a/android/app/src/main/kotlin/com/follow/clash/GlobalState.kt +++ b/android/app/src/main/kotlin/com/follow/clash/GlobalState.kt @@ -44,7 +44,7 @@ object GlobalState { fun initServiceEngine(context: Context) { if (serviceEngine != null) return lock.withLock { - if (serviceEngine != null) return + destroyServiceEngine() serviceEngine = FlutterEngine(context) serviceEngine?.plugins?.add(ProxyPlugin()) serviceEngine?.plugins?.add(AppPlugin()) 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 b4dbf7e1..f2576f72 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 @@ -174,16 +174,19 @@ class FlClashVpnService : VpnService() { inner class LocalBinder : Binder() { fun getService(): FlClashVpnService = this@FlClashVpnService - override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean { - CoroutineScope(Dispatchers.Main).launch { - GlobalState.getCurrentTitlePlugin()?.handleStop() - } - try { - return super.onTransact(code, data, reply, flags) - } catch (e: RemoteException) { - throw e - } - } +// override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean { +// try { +// val isSuccess = super.onTransact(code, data, reply, flags) +// if (!isSuccess) { +// CoroutineScope(Dispatchers.Main).launch { +// GlobalState.getCurrentTitlePlugin()?.handleStop() +// } +// } +// return isSuccess +// } catch (e: RemoteException) { +// throw e +// } +// } } diff --git a/lib/main.dart b/lib/main.dart index 3ff77088..86ebc3fe 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:io'; import 'package:fl_clash/clash/clash.dart'; import 'package:fl_clash/plugins/app.dart'; @@ -67,7 +66,6 @@ Future vpnService() async { clashCore.setFdMap(fd.id); }, onProcess: (Process process) async { - print(process); var packageName = await app?.resolverProcess(process); clashCore.setProcessMap( ProcessMapItem( @@ -112,14 +110,13 @@ Future vpnService() async { onStop: () async { await app?.tip(appLocalizations.stopVpn); await globalState.stopSystemProxy(); - exit(0); }, ), ); globalState.updateTraffic(); globalState.updateFunctionLists = [ - () { + () { globalState.updateTraffic(); } ]; @@ -137,7 +134,8 @@ class ServiceMessageHandler with ServiceMessageListener { required Function(Process process) onProcess, required Function(String runTime) onStarted, required Function(String groupName) onLoaded, - }) : _onProtect = onProtect, + }) + : _onProtect = onProtect, _onProcess = onProcess, _onStarted = onStarted, _onLoaded = onLoaded; @@ -163,10 +161,11 @@ class ServiceMessageHandler with ServiceMessageListener { } } +@immutable class TileListenerWithVpn with TileListener { final Function() _onStop; - TileListenerWithVpn({ + const TileListenerWithVpn({ required Function() onStop, }) : _onStop = onStop; diff --git a/lib/plugins/proxy.dart b/lib/plugins/proxy.dart index 3f19999f..035f5faf 100644 --- a/lib/plugins/proxy.dart +++ b/lib/plugins/proxy.dart @@ -8,6 +8,7 @@ import 'package:fl_clash/common/common.dart'; import 'package:fl_clash/enum/enum.dart'; import 'package:fl_clash/models/models.dart'; import 'package:fl_clash/state.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:proxy/proxy_platform_interface.dart'; @@ -80,6 +81,7 @@ class Proxy extends ProxyPlatform { bool get isStart => startTime != null && startTime!.isBeforeNow; onStarted(int? fd) { + debugPrint("onStarted ==> $fd"); if (fd == null) return; if (receiver != null) { receiver!.close(); diff --git a/pubspec.yaml b/pubspec.yaml index c1b84f26..7fd4e319 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.39+202407151 +version: 0.8.40+202407152 environment: sdk: '>=3.1.0 <4.0.0'