Skip to content

feat: add onMenuOpened callback to Tray composable#385

Merged
kdroidFilter merged 4 commits intomasterfrom
feat/on-menu-opened-callback
Apr 13, 2026
Merged

feat: add onMenuOpened callback to Tray composable#385
kdroidFilter merged 4 commits intomasterfrom
feat/on-menu-opened-callback

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

@kdroidFilter kdroidFilter commented Apr 10, 2026

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 4 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>
- Introduced `onMenuOpened` support in `WindowsTrayManager` for detecting menu opening events
- Integrated JNI binding for `tray_set_menu_opened_callback` in native Windows implementation
- Updated initialization and update methods to include the menu-opened callback
- Enhanced tray behavior with improved event handling and callback support
… initializer calls

- Reformatted method calls in NativeTray for better readability and consistency
- Updated Linux, Windows, and macOS initializer and updater invocations with multiline argument structure
@kdroidFilter kdroidFilter merged commit ac5c0c9 into master Apr 13, 2026
5 checks passed
@kdroidFilter kdroidFilter deleted the feat/on-menu-opened-callback branch April 13, 2026 10:43
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