From dd657f83d0e00f487193df5afab8f4933fcf5a72 Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 3 Aug 2026 21:52:57 +0300 Subject: [PATCH] fix events leak --- .../vbox/shared/presentation/VBoxRootComponent.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/VBoxRootComponent.kt b/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/VBoxRootComponent.kt index 0e4a56f..61ec15e 100644 --- a/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/VBoxRootComponent.kt +++ b/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/VBoxRootComponent.kt @@ -8,13 +8,14 @@ import com.arkivanov.decompose.router.webhistory.WebNavigation import com.arkivanov.decompose.router.webhistory.WebNavigationOwner import com.arkivanov.essenty.lifecycle.coroutines.repeatOnLifecycle import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import kotlinx.serialization.KSerializer import org.koin.core.Koin import org.koin.core.annotation.Factory import ru.shadowsparky.http.domain.TokenStorage -import ru.shadowsparky.http.domain.hasAccount import ru.shadowsparky.ui.nav.RootComponent import ru.shadowsparky.updater.presentation.UpdateComponentFactory import ru.shadowsparky.vbox.shared.di.factory.ImageLoaderProvider @@ -48,9 +49,13 @@ class VBoxRootComponent( init { scope.launch { repeatOnLifecycle { - if (tokenStorage.hasAccount()) { - remoteEventListener.event.collect() - } + tokenStorage.token.flatMapLatest { + if (it != null) { + remoteEventListener.event + } else { + flowOf() + } + }.collect() } } scope.launch {