Skip to content
Merged
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
10 changes: 9 additions & 1 deletion app/src/main/java/com/wassupluke/widgets/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import com.wassupluke.widgets.data.dataStore
import com.wassupluke.widgets.ui.settings.SettingsScreen
import com.wassupluke.widgets.ui.settings.SettingsViewModel
import com.wassupluke.widgets.ui.theme.SimpleWeatherTheme
import com.wassupluke.widgets.widget.AlarmWidget
import com.wassupluke.widgets.widget.WeatherWidget
import com.wassupluke.widgets.worker.WorkScheduler
import androidx.glance.appwidget.updateAll
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -53,8 +56,13 @@ class MainActivity : ComponentActivity() {
}
}

// Schedule WorkManager on first launch (if location is already set)
lifecycleScope.launch(Dispatchers.IO) {
// Force both widgets to re-render, re-establishing correct Glance
// state mapping in case it drifted after a force-stop or update
WeatherWidget().updateAll(applicationContext)
AlarmWidget().updateAll(applicationContext)
Comment on lines +62 to +63
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Consider isolating widget updates from the WorkManager scheduling so a failure in updateAll doesn't block scheduling.

Because both widget updates run in the same coroutine as scheduling, any exception from updateAll will cancel the coroutine and prevent scheduling from running. To avoid missing periodic updates, consider wrapping each updateAll in its own try/catch or moving the scheduling into a separate coroutine.


// Schedule WorkManager (if location is already set)
val prefs = applicationContext.dataStore.data.first()
val lat = prefs[WeatherDataStore.LOCATION_LAT]
val lon = prefs[WeatherDataStore.LOCATION_LON]
Expand Down
Loading