From 633b3c7e7acb5a26cb329a10f053bf032342db60 Mon Sep 17 00:00:00 2001 From: Eugene Date: Tue, 15 Sep 2026 12:59:20 +0300 Subject: [PATCH] stop speak if user exit from app --- .../gigawear/presentation/chat/ChatComponent.kt | 12 +++++++++++- .../gigawear/presentation/chat/ChatScreen.kt | 7 +++++++ .../updater/presentation/UpdateComponent.kt | 1 - 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt index 558eb4b..019ad1a 100644 --- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt +++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt @@ -4,6 +4,7 @@ import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.childContext import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope import com.arkivanov.essenty.lifecycle.doOnStart +import com.arkivanov.essenty.lifecycle.doOnStop import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -12,6 +13,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.receiveAsFlow +import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import org.koin.core.annotation.Factory import org.koin.core.annotation.Named @@ -53,6 +55,13 @@ class ChatComponent( if (it == null) navigateToRouting() } } + lifecycle.doOnStop { + _state.update { it.copy(stopRequested = true) } + } + } + + fun resetStopState() { + _state.update { it.copy(stopRequested = false) } } fun onMicClicked() { @@ -88,7 +97,8 @@ class ChatComponent( val userText: String? = null, val assistantText: String? = null, val isLoading: Boolean = false, - val error: Throwable? = null + val error: Throwable? = null, + val stopRequested: Boolean = false ) } diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatScreen.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatScreen.kt index cb29b0c..95354af 100644 --- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatScreen.kt +++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatScreen.kt @@ -57,6 +57,13 @@ fun ChatScreen(component: ChatComponent) { } } + LaunchedEffect(state.stopRequested) { + if (state.stopRequested) { + speechManager.stop() + component.resetStopState() + } + } + LaunchedEffect(component) { component.events.collectLatest { event -> when (event) { diff --git a/feature/updater/updater-client/src/commonMain/kotlin/ru/shadowsparky/updater/presentation/UpdateComponent.kt b/feature/updater/updater-client/src/commonMain/kotlin/ru/shadowsparky/updater/presentation/UpdateComponent.kt index 922ca7d..114b281 100644 --- a/feature/updater/updater-client/src/commonMain/kotlin/ru/shadowsparky/updater/presentation/UpdateComponent.kt +++ b/feature/updater/updater-client/src/commonMain/kotlin/ru/shadowsparky/updater/presentation/UpdateComponent.kt @@ -49,7 +49,6 @@ class UpdateComponent( fun checkUpdates(byUser: Boolean = true) { if (!hasSupport) return - lastJob?.cancel() lastJob = scope.launch { interactor.checkUpdate().collect { isForceUpdate = (it as? UpdateState.UpdateAvailable)?.isForceUpdate ?: false