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

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.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton
@@ -22,8 +25,11 @@ class TaskPipelineForegroundBootstrap @Inject constructor(
fun start() {
scope.launch {
orchestrator.foregroundUi.collect { ui ->
if (ui is TaskForegroundUiState.Visible) {
orchestrator.foregroundUi
.map { it is TaskForegroundUiState.Visible }
.distinctUntilChanged()
.filter { visible -> visible }
.collect {
ContextCompat.startForegroundService(
app,
Intent(app, TaskPipelineForegroundService::class.java),
@@ -31,5 +37,4 @@ class TaskPipelineForegroundBootstrap @Inject constructor(
}
}
}
}
}