From 0f9e58ba49556dc7b8135943af4612c51decda14 Mon Sep 17 00:00:00 2001 From: ZenX <39208173+ZenX404@users.noreply.github.com> Date: Sat, 25 Jul 2026 16:30:26 +0800 Subject: [PATCH] Fix external Clash control shortcuts Replace the cached Remote.broadcasts.clashRunning state with a direct StatusClient query for start and toggle actions. Always dispatch the stop request for ACTION_STOP_CLASH, ensuring the stop shortcut works even when the app process has not initialized or refreshed its cached service state. --- .../kr328/clash/ExternalControlActivity.kt | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/github/kr328/clash/ExternalControlActivity.kt b/app/src/main/java/com/github/kr328/clash/ExternalControlActivity.kt index 2f451ebf73..e31d3d18b2 100644 --- a/app/src/main/java/com/github/kr328/clash/ExternalControlActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/ExternalControlActivity.kt @@ -10,7 +10,6 @@ import com.github.kr328.clash.common.util.intent import com.github.kr328.clash.common.util.setUUID import com.github.kr328.clash.design.MainDesign import com.github.kr328.clash.design.ui.ToastDuration -import com.github.kr328.clash.remote.Remote import com.github.kr328.clash.remote.StatusClient import com.github.kr328.clash.service.model.Profile import com.github.kr328.clash.util.startClashService @@ -56,30 +55,33 @@ class ExternalControlActivity : Activity(), CoroutineScope by MainScope() { return } - Intents.ACTION_TOGGLE_CLASH -> if(Remote.broadcasts.clashRunning) { - stopClash() - } - else { - startClash() - } - - Intents.ACTION_START_CLASH -> if(!Remote.broadcasts.clashRunning) { - startClash() + Intents.ACTION_TOGGLE_CLASH -> { + if (isClashRunning()) { + stopClash() + } else { + startClash() + } } - else { - Toast.makeText(this, R.string.external_control_started, Toast.LENGTH_LONG).show() + + Intents.ACTION_START_CLASH -> { + if (isClashRunning()) { + Toast.makeText(this, R.string.external_control_started, Toast.LENGTH_LONG).show() + } else { + startClash() + } } - - Intents.ACTION_STOP_CLASH -> if(Remote.broadcasts.clashRunning) { + + Intents.ACTION_STOP_CLASH -> { stopClash() } - else { - Toast.makeText(this, R.string.external_control_stopped, Toast.LENGTH_LONG).show() - } } return finish() } + private fun isClashRunning(): Boolean { + return StatusClient(this).currentProfile() != null + } + private fun startClash() { // if (currentProfile == null) { // Toast.makeText(this, R.string.no_profile_selected, Toast.LENGTH_LONG).show()