Skip to content

feat: add onMenuOpened callback to Tray composable#385

Open
kdroidFilter wants to merge 2 commits intomasterfrom
feat/on-menu-opened-callback
Open

feat: add onMenuOpened callback to Tray composable#385
kdroidFilter wants to merge 2 commits intomasterfrom
feat/on-menu-opened-callback

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

Summary

Closes #233

  • Add onMenuOpened: (() -> Unit)? = null parameter to all Tray() composable overloads
  • On Linux, hooks into the DBusMenu AboutToShow protocol to detect when the menu is about to open
  • Noop on Windows and macOS (parameter accepted but ignored)
  • Includes LayoutUpdated-based suppression to prevent infinite feedback loops when the callback mutates Compose state
  • Build script now invalidates the ~/.cache/composetray/ native library cache to avoid stale .so issues

API usage

Tray(
    icon = Icons.Default.Cloud,
    tooltip = "My App",
    onMenuOpened = {
        // Refresh data when menu opens
        serviceStatus = pollRemoteService()
    },
) {
    Item("Status: $serviceStatus")
}

Test plan

  • Linux: verify callback fires once per menu open, counter increments in main window
  • Linux: verify no infinite loop when callback mutates state
  • Linux: verify counter stays at 0 until user actually opens menu (not on startup)
  • Windows/macOS: verify no regression (parameter is noop)
  • GraalVM native-image: verify no additional metadata needed

kdroidFilter and others added 2 commits April 10, 2026 10:57
Add a callback invoked when the tray menu is about to be shown,
allowing apps to refresh state on demand. Implemented via the
DBusMenu AboutToShow protocol on Linux; noop on Windows/macOS.

Includes LayoutUpdated-based suppression to prevent feedback loops
when the callback mutates menu state, and build script cache
invalidation to avoid stale native library issues.
- Add menu opened callback storage and dispatch in TrayContext (Swift)
- Invoke callback in InstanceButtonClickHandler.handleClick() before menu.popUp()
- Expose tray_set_menu_opened_callback() C API with per-instance support
- Add JNI bridge and trampoline for menu opened callback
- Wire callback through MacNativeBridge, MacTrayManager, and MacTrayInitializer
- Initialize callback after tray_init() to ensure TrayContext exists
- Clear native library cache in macOS build script (darwin-aarch64/x86-64)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request : Add Callback onMenuOpened

1 participant