Description
Problem to solve
Currently we can trigger HomeWidget.updateWidget
to update home screen widget.
Proposal
I would like to distinguish whether in the update method (in onUpdate for GlanceAppWidgetReceiver?) it is run because system wants to rebuild the widget, or because we triggered manual update from Flutter app.
For android, there is this updateWidget method https://github.com/ABausG/home_widget/blob/main/packages/home_widget/android/src/main/kotlin/es/antonborri/home_widget/HomeWidgetPlugin.kt#L101 which already on 111 adds an extra. I think we can use similar approach and do
intent.putExtra("isManualUpdate", true)
And then in our widget we can do something like this
class MyGlanceAppWidget : GlanceAppWidget() {
override suspend fun onUpdate(context: Context, glanceId: GlanceId) {
// Retrieve any relevant state or intent information
val intent = (context as? Activity)?.intent
val isManualUpdate = intent?.getBooleanExtra("isManualUpdate", false) ?: false
if (isManualUpdate) {
// Handle manual update logic
Log.d("MyGlanceAppWidget", "Handling manual update")
} else {
// Handle regular update logic
Log.d("MyGlanceAppWidget", "Handling system update")
}
// Perform widget update
}
}
I suppose iOS might work similarly.
More information
I have a periodic worker which is run every time the update is done. And inside of the work I check that I only run it once per 1 minute in case it is called multiple times because of the system or whatever. But on manual trigger from Flutter app I would want to run it every time and therefore I would like to have some way to determine the type of the update.
Which Platform would be improved?
Android, iOS
Other
- Are you interested in working on a PR for this?