Widget: Fix widgets freezing at initial state after first render#561
Merged
Conversation
Glance only calls provideGlance() once per widget session; subsequent update() calls recompose the existing composition without re-running provideGlance. The previous capture-once approach left widgets frozen at initial state because the composition had no reactive State to read. Subscribe to a widgetDeviceFlow(profileId) inside provideContent that pre-filters by WidgetDeviceKey, so the composition recomposes on visible state changes without firing on every BLE advertisement. Replace updateAll() with explicit per-GlanceId update() calls in WidgetManager, with a platform-id fallback when Glance returns no IDs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Fixed a bug where the home-screen widgets stopped updating after the first time they appeared. Battery levels, in-ear status, ANC mode, and charging state would freeze at whatever they were when the widget started, even though the rest of the app (notification, popup, settings screen) reflected the correct values.
Technical Context
GlanceAppWidget.provideGlance()once per widget session — at mount, after process death, or on widget reconfiguration. Subsequentupdate()/updateAll()calls send anUpdateGlanceStateevent to the existing session, which only triggers a recomposition of the already-runningprovideContent { }block. A previous refactor moved data reads (device,isPro,profileLabel) out of the composition into one-time captures at the top ofprovideGlance. The composition then read those captured local variables — not Compose State — so recompositions produced the same RemoteViews every time.widgetDeviceFlow(profileId)flow insideprovideContentviacollectAsState. The flow is pre-deduped byWidgetDeviceKey, so the composition only recomposes on state changes that actually affect rendering — not on every BLE advertisement.WidgetManagerrewritten to callwidget.update(context, id)per resolved GlanceId rather thanwidget.updateAll(context), with a fallback to platformAppWidgetManager.getAppWidgetIds(...)when Glance returns no IDs (defensive against the edge case where Glance's internal map is empty but platform widget instances exist).PodDevicefix:isLeftInEar/isRightInEarnow resolve when AAP reports both pods in the same placement andprimaryPodis unresolved — previously returned null in that ambiguous case, blanking the widget's wear indicators.