From 7c7a623ae50f3d142cde5c5d3f5a84bba0d4abb6 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Fri, 4 Dec 2020 22:37:31 -0500 Subject: [PATCH] Fix select node of two processes in sync As proxy only mode is added in 1.4.0, I moved the toggle components to the daemon process When user start service from toggle, the full config is generated from a cached list. However, this cache is not in sync with the main process list. In fact, we don't need to generate full config right before the service start. We only need to when active node is changed. This way, code logic and daemon process is kept simple --- .../com/v2ray/ang/receiver/TaskerReceiver.kt | 2 +- .../v2ray/ang/service/V2RayServiceManager.kt | 11 ++++- .../kotlin/com/v2ray/ang/ui/MainActivity.kt | 2 +- .../com/v2ray/ang/ui/MainRecyclerAdapter.kt | 4 +- .../com/v2ray/ang/ui/SettingsActivity.kt | 3 +- .../com/v2ray/ang/util/AngConfigManager.kt | 11 +++-- .../main/kotlin/com/v2ray/ang/util/Utils.kt | 43 +++++-------------- 7 files changed, 32 insertions(+), 44 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/TaskerReceiver.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/TaskerReceiver.kt index dca1dc38..74f69416 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/TaskerReceiver.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/receiver/TaskerReceiver.kt @@ -21,7 +21,7 @@ class TaskerReceiver : BroadcastReceiver() { return } else if (switch) { if (guid == AppConfig.TASKER_DEFAULT_GUID) { - Utils.startVService(context) + Utils.startVServiceFromToggle(context) } else { Utils.startVService(context, guid) } diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt index fbf9f499..86e8ff05 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt @@ -18,6 +18,8 @@ import com.v2ray.ang.AppConfig.TAG_DIRECT import com.v2ray.ang.R import com.v2ray.ang.extension.defaultDPreference import com.v2ray.ang.extension.toSpeedString +import com.v2ray.ang.extension.toast +import com.v2ray.ang.extension.v2RayApplication import com.v2ray.ang.ui.MainActivity import com.v2ray.ang.ui.SettingsActivity import com.v2ray.ang.util.MessageUtil @@ -57,8 +59,13 @@ object V2RayServiceManager { private var mSubscription: Subscription? = null private var mNotificationManager: NotificationManager? = null - fun startV2Ray(context: Context, mode: String) { - val intent = if (mode == "VPN") { + fun startV2Ray(context: Context) { + if (context.v2RayApplication.defaultDPreference.getPrefBoolean(SettingsActivity.PREF_PROXY_SHARING, false)) { + context.toast(R.string.toast_warning_pref_proxysharing_short) + }else{ + context.toast(R.string.toast_services_start) + } + val intent = if (context.v2RayApplication.defaultDPreference.getPrefString(AppConfig.PREF_MODE, "VPN") == "VPN") { Intent(context.applicationContext, V2RayVpnService::class.java) } else { Intent(context.applicationContext, V2RayProxyOnlyService::class.java) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt index 380fd11d..23358065 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt @@ -128,7 +128,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList } showCircle() // toast(R.string.toast_services_start) - if (!Utils.startVService(this)) { + if (!Utils.startVService(this, AngConfigManager.configs.index)) { hideCircle() } } diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt index fbce435f..500be2e4 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt @@ -143,16 +143,14 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter