Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/java/com/mensinator/app/widgets/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class BootReceiver : BroadcastReceiver() {
CoroutineScope(SupervisorJob() + Dispatchers.IO).launch {
try {
MidnightWorker.scheduleNextMidnight(context)
// Update all widgets immediately after boot so they show current data.
// Without this, widgets keep showing stale data until midnight or the user opens the app.
WidgetInstances.forEach { it.glanceAppWidget.updateAll(context) }
} finally {
pendingResult.finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ object PeriodCalculationWidgetUpdater : KoinComponent {
private fun updateWidgets() {
CoroutineScope(Dispatchers.IO).launch {
try {
// Emit to midnight trigger to force widget data refresh
MidnightTrigger.midnightTrigger.emit(Unit)
// Do NOT emit to MidnightTrigger here.
// Emitting before updateAll() could cause the active combine flow to recompose
// with the OLD nextPeriod() value (the new value hasn't been emitted by the
// nextPeriod() map block yet). updateAll() starts a fresh Glance composition that
// re-runs calculateNextPeriod() from scratch via the dbWriteTrigger replay, so the
// widget always gets the correct up-to-date data.
// Update all widgets concurrently for better performance
WidgetInstances.map { receiver ->
launch { receiver.glanceAppWidget.updateAll(context) }
Expand Down