Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa5d60f9 authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

Merge branch 'fix_241_widget_out_of_date' into 'main'

FIX 241, widget not updated when no leaks

See merge request e/privacy-central/privacycentralapp!50
parents 6d8ad343 75416b72
Loading
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -29,16 +29,20 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import java.time.temporal.ChronoUnit

/**
 * Implementation of App Widget functionality.
@@ -88,9 +92,18 @@ class Widget : AppWidgetProvider() {
                )
            }.sample(50)
                .combine(
                    merge(
                        trackersStatisticsUseCase.listenUpdates()
                            .onStart { emit(Unit) }
                        .debounce(5000)
                            .debounce(5000),
                        flow {
                            while (true) {
                                emit(Unit)
                                delay(ChronoUnit.HOURS.duration.toMillis())
                            }
                        }

                    )
                ) { state, _ ->
                    state.copy(
                        dayStatistics = trackersStatisticsUseCase.getDayTrackersCalls(),