Улучшен запуск сервиса

This commit is contained in:
2026-04-18 21:53:52 +03:00
parent d806e3a8a1
commit 9bea6a2a4c

View File

@@ -9,6 +9,9 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@@ -22,14 +25,16 @@ class TaskPipelineForegroundBootstrap @Inject constructor(
fun start() { fun start() {
scope.launch { scope.launch {
orchestrator.foregroundUi.collect { ui -> orchestrator.foregroundUi
if (ui is TaskForegroundUiState.Visible) { .map { it is TaskForegroundUiState.Visible }
.distinctUntilChanged()
.filter { visible -> visible }
.collect {
ContextCompat.startForegroundService( ContextCompat.startForegroundService(
app, app,
Intent(app, TaskPipelineForegroundService::class.java), Intent(app, TaskPipelineForegroundService::class.java),
) )
} }
}
} }
} }
} }