Улучшен запуск сервиса
This commit is contained in:
@@ -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(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user