diff --git a/app/src/main/java/com/github/nullptroma/wallenc/app/tasks/TaskPipelineForegroundBootstrap.kt b/app/src/main/java/com/github/nullptroma/wallenc/app/tasks/TaskPipelineForegroundBootstrap.kt index 3276b92..33a6780 100644 --- a/app/src/main/java/com/github/nullptroma/wallenc/app/tasks/TaskPipelineForegroundBootstrap.kt +++ b/app/src/main/java/com/github/nullptroma/wallenc/app/tasks/TaskPipelineForegroundBootstrap.kt @@ -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,14 +25,16 @@ 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), ) } - } } } }