fix: make CheckableItem reactive and serialize tray updates - #433
Merged
Conversation
CheckableItem clicks captured the checked value at menu-build time, so repeated clicks without a rebuild kept sending the same toggle (Linux's live lookup read the builder's own never-updated list, so it had the same bug). Each checkable item now keeps a live AtomicBoolean toggled on click, reports the new value to onCheckedChange, and patches the native checkmark immediately via updateMenuItemCheckedState (added to WindowsTrayManager, made submenu-aware on macOS). NativeTray.updateComposable was fire-and-forget on trayScope, letting a stale icon/menu update land after a fresher one when the parent recomposes frequently. Updates now go through a conflated channel with a single worker: applied in order, one at a time, superseded updates dropped. dispose() cancels the scope so an in-flight update cannot re-create a disposed tray. Fixes #432
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.
Fixes #432
Problem
CheckableItemclicks capturedcheckedat menu-build time. On Windows/macOS the click handler sent!capturedCheckedforever; Linux's "live lookup" read the builder's own list, which is never updated (only the manager's copy is), so it behaved the same. After one toggle without a rebuild, further clicks were no-ops.NativeTray.updateComposablefire-and-forgot each update ontrayScope, so a stale render/menu (e.g. still holdingchecked = true) could land after a fresher one whenever the parent recomposes frequently.Fix
Live checked state (all platforms)
CheckableItemkeeps a per-itemAtomicBooleantoggled on click;onCheckedChangereceives the toggle of the current value, not the captured one.WindowsTrayManager.updateMenuItemCheckedState(text, checked)— queued and applied on the tray thread (patches the stored item list, rebuilds the menu structs,nativeUpdateTray). The builder now receives the manager, soWindowsTrayInitializercreates/looks up the manager before building.updateMenuItemCheckedState, which is now submenu-aware.nativeItemCheck/Uncheck.Switchin a window toggling the same flag) reasserts whatever the app decides.Serialized updates
updateComposablenow enqueues into aChannel(CONFLATED)drained by a single worker: updates apply in submission order, one at a time, and a newer update replaces any queued-but-unapplied one. A stale update can no longer overwrite a fresh one.dispose()cancelstrayScopeso an in-flight update can't re-create a disposed tray.Testing
compileKotlinJvm(main + tray-app),ktlintCheck,detekt,jvmTestall pass.