From 78c5527a3dfc14baab898d1cb7f317b13acd8bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 6 Jul 2026 21:14:30 +0800 Subject: [PATCH] Fix clear logs not working when service is stopped --- .../sfa/compose/screen/log/LogViewModel.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/nekohasekai/sfa/compose/screen/log/LogViewModel.kt b/app/src/main/java/io/nekohasekai/sfa/compose/screen/log/LogViewModel.kt index ecaf56d..ef7ebe1 100644 --- a/app/src/main/java/io/nekohasekai/sfa/compose/screen/log/LogViewModel.kt +++ b/app/src/main/java/io/nekohasekai/sfa/compose/screen/log/LogViewModel.kt @@ -98,10 +98,16 @@ class LogViewModel : override fun requestClearLogs() { viewModelScope.launch { - withContext(Dispatchers.IO) { - runCatching { - Libbox.newStandaloneCommandClient().clearLogs() + val sent = + withContext(Dispatchers.IO) { + runCatching { + Libbox.newStandaloneCommandClient().clearLogs() + }.isSuccess } + // With the service stopped there is no broadcast to clear the UI, + // so the local buffer is cleared directly. + if (!sent) { + clearLogs() } } }