Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
feat: Track assistive ball service state to synchronize UI toggle updates
Durganshu Mishrab3f2d628059f
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.ktindex 2af1460..bbc4f1f 100644--- a/app/src/main/java/com/gotcha/MainActivity.kt+++ b/app/src/main/java/com/gotcha/MainActivity.kt@@ -210,6 +210,14 @@ class MainActivity : ComponentActivity() {LaunchedEffect(Unit) { chatViewModel.refreshSettings() }+ // Track the service's real state so the toggle updates when the ball is+ // hidden from its own overlay menu (which stops the service directly).+ LaunchedEffect(Unit) {+ AssistiveBallService.isRunning.collect { running ->+ assistiveBallOn = running+ }+ }+// Honor the assistive ball's "Open Chat" option.LaunchedEffect(openChatRequested) {if (openChatRequested) {diff --git a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt b/app/src/main/java/com/gotcha/service/AssistiveBallService.ktindex ae100cb..8ee09f6 100644--- a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt+++ b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt@@ -22,6 +22,9 @@ import kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.SupervisorJobimport kotlinx.coroutines.cancelimport kotlinx.coroutines.delay+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.launch/**@@ -76,6 +79,7 @@ class AssistiveBallService : Service() {else -> {startAsForeground()overlay.show()+ _isRunning.value = true}}return START_STICKY@@ -84,6 +88,7 @@ class AssistiveBallService : Service() {override fun onBind(intent: Intent?): IBinder? = nulloverride fun onDestroy() {+ _isRunning.value = falseoverlay.dismiss()ttsEngine.shutdown()scope.cancel()@@ -177,6 +182,10 @@ class AssistiveBallService : Service() {// ---- Lifecycle helpers ----private fun stopBall() {+ // Keep the persisted toggle in sync when the ball is hidden from its own+ // menu (not just from the in-app toggle), so the app reopens with it off.+ settingsRepository.save(settingsRepository.load().copy(assistiveBallEnabled = false))+ _isRunning.value = falseoverlay.dismiss()stopForeground(STOP_FOREGROUND_REMOVE)stopSelf()@@ -256,6 +265,10 @@ class AssistiveBallService : Service() {companion object {const val ACTION_START = "com.gotcha.assistiveball.START"const val ACTION_STOP = "com.gotcha.assistiveball.STOP"++ private val _isRunning = MutableStateFlow(false)+ /** Live running state of the ball, so UI toggles can track "Hide ball" too. */+ val isRunning: StateFlow<Boolean> = _isRunning.asStateFlow()private const val CHANNEL_ID = "assistive_ball"private const val NOTIFICATION_ID = 4711