stop speak if user exit from app
This commit is contained in:
+11
-1
@@ -4,6 +4,7 @@ import com.arkivanov.decompose.ComponentContext
|
|||||||
import com.arkivanov.decompose.childContext
|
import com.arkivanov.decompose.childContext
|
||||||
import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope
|
import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope
|
||||||
import com.arkivanov.essenty.lifecycle.doOnStart
|
import com.arkivanov.essenty.lifecycle.doOnStart
|
||||||
|
import com.arkivanov.essenty.lifecycle.doOnStop
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
@@ -12,6 +13,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.receiveAsFlow
|
import kotlinx.coroutines.flow.receiveAsFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.core.annotation.Factory
|
import org.koin.core.annotation.Factory
|
||||||
import org.koin.core.annotation.Named
|
import org.koin.core.annotation.Named
|
||||||
@@ -53,6 +55,13 @@ class ChatComponent(
|
|||||||
if (it == null) navigateToRouting()
|
if (it == null) navigateToRouting()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lifecycle.doOnStop {
|
||||||
|
_state.update { it.copy(stopRequested = true) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetStopState() {
|
||||||
|
_state.update { it.copy(stopRequested = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMicClicked() {
|
fun onMicClicked() {
|
||||||
@@ -88,7 +97,8 @@ class ChatComponent(
|
|||||||
val userText: String? = null,
|
val userText: String? = null,
|
||||||
val assistantText: String? = null,
|
val assistantText: String? = null,
|
||||||
val isLoading: Boolean = false,
|
val isLoading: Boolean = false,
|
||||||
val error: Throwable? = null
|
val error: Throwable? = null,
|
||||||
|
val stopRequested: Boolean = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
@@ -57,6 +57,13 @@ fun ChatScreen(component: ChatComponent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(state.stopRequested) {
|
||||||
|
if (state.stopRequested) {
|
||||||
|
speechManager.stop()
|
||||||
|
component.resetStopState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(component) {
|
LaunchedEffect(component) {
|
||||||
component.events.collectLatest { event ->
|
component.events.collectLatest { event ->
|
||||||
when (event) {
|
when (event) {
|
||||||
|
|||||||
-1
@@ -49,7 +49,6 @@ class UpdateComponent(
|
|||||||
|
|
||||||
fun checkUpdates(byUser: Boolean = true) {
|
fun checkUpdates(byUser: Boolean = true) {
|
||||||
if (!hasSupport) return
|
if (!hasSupport) return
|
||||||
lastJob?.cancel()
|
|
||||||
lastJob = scope.launch {
|
lastJob = scope.launch {
|
||||||
interactor.checkUpdate().collect {
|
interactor.checkUpdate().collect {
|
||||||
isForceUpdate = (it as? UpdateState.UpdateAvailable)?.isForceUpdate ?: false
|
isForceUpdate = (it as? UpdateState.UpdateAvailable)?.isForceUpdate ?: false
|
||||||
|
|||||||
Reference in New Issue
Block a user