Refactor tray logic for improved cross-platform consistency#234
Merged
Conversation
…proach with LibTray integration.
…g and streamline submenu and menu item building process.
…e thread wait, extend cleanup timeouts for better reliability, and refine logging.
- Replace existing Linux tray implementation with a Qt-based system tray solution. - Add `CMakeLists.txt` for building the new tray system (`libtray`). - Implement cross-platform `tray.h` API with Linux-specific logic. - Provide `build.sh` for building libraries on Linux. - Add example app (`example.c`) demonstrating tray usage. - Enhance Gradle build scripts to include a Linux-specific build target (`buildNativeLinux`).
…d-safety, enhance initialization with `QtAppManager`, and improve cleanup flow for reliability.
…line initialization, reduce threading complexity, and improve code maintainability.
…nd delete tray icon to prevent GLib main context issues.
…y icon cleanup, replace `exitRequested` signal with direct method calls, and address GLib context termination issues.
…ycle management. - Add `update()` method for Linux, Windows, and macOS tray initializers. - Refactor `NativeTray` to manage initialization and update logic. - Enhance lifecycle handling with `LaunchedEffect` for Compose-based APIs. - Refine disposable and initialization behaviors for increased reliability.
…`deleteLater`, extending event processing time, and ensuring proper disposal of `trayMenuInstance`.
…om message handler to suppress expected harmless messages during cross-thread cleanup.
…e `processEvents` usage for reliable GLib context cleanup, and remove outdated `exitRequested` signal handling.
… remove unnecessary cleanup steps, and streamline event loop handling for improved efficiency.
- Introduce `initialize` and `update` methods to enhance initialization and update workflows. - Replace blocking tray loop with coroutine-based message processing for improved efficiency. - Improve menu and callback management by adding cleanup mechanisms and ensuring proper lifecycle handling. - Enhance error handling during tray initialization and updates.
- Add `menuKey` parameter to force recompositions when state variables change. - Update `LaunchedEffect` dependency arrays to include `menuKey` across platforms. - Extend demo menu with dynamic items and visibility toggling for improved interactivity.
Introduced `MacTrayManager` and native components for macOS system tray integration, allowing dynamic tray updates, menu handling, and improved cross-platform behavior consistency. Added associated build tasks in Gradle.
- Replace `menuKey` with hash-based change detection for improved reliability. - Introduce `MenuContentHash` utility to calculate menu state changes. - Update `LaunchedEffect` dependencies to use `menuHash`. - Enhance demo menus with dynamic content, conditional visibility, and advanced options.
- Introduce `onCheckedChange` for improved state handling and Compose idiomaticity. - Mark legacy `onToggle` API as deprecated and provide migration path. - Update platform-specific tray menu implementations to support the new API. - Enhance demo with updated `CheckableItem` usage and additional features.
…tter readability and state handling
Implemented dark mode support by introducing `MacOSMenuBarThemeDetector` to detect menu bar theme changes in real-time. Updated tray rendering logic to respond to theme changes dynamically. Added related native library updates and utilities.
Eliminated the outdated `MenuBarModeObserver` class and its related logic as the functionality is now superseded by more efficient and unified theme detection mechanisms.
Added support for detecting dark mode on Windows and Linux systems using `platformtools.darkmodedetector`. Updated `isMenuInDarkMode` to handle cross-platform detection. Adjusted Gradle dependencies to include `platformtools.darkmodedetector:0.4.0`.
…dependency management.
- Integrate detailed desktop environment checks for GNOME, KDE, XFCE, Cinnamon, MATE, and others. - Refine `DarkModeDetector` logic to improve accuracy across Linux distributions.
- Rename `isMenuInDarkMode` to `isMenuBarInDarkMode` for clarity and alignment with functionality. - Update references across `NativeTray`, demo, and `DarkModeDetector`.
- Introduce `DemoWithImageVector` showcasing tray icons using `ImageVector` API with customizable tint and menu interaction. - Add `DemoWithPainter` demonstrating tray icons based on `Painter` API with dynamic icon switching. - Update `Tray` API to support both `ImageVector` and `Painter` configurations with enhanced customization. - Provide sample SVG resources (`AcademicCap` and `Deployed_code_update`) for `ImageVector` tray demo. - Extend `build.gradle.kts` to include required dependencies for new demos.
…ctor` tray icon.
- Migrate all logging calls from `Log` to `Kermit` for consistency and modern best practices. - Add `DebugLn` utility with leveled logging support (`debug`, `info`, `warn`, `error`). - Remove unused `kmp.log` dependency from project and demos. - Update `build.gradle.kts` to include `Kermit` dependency. - Enhance demo logging, supporting conditional log output with `allowComposeNativeTrayLogging`.
…ration: - Introduce `ComposeNativeTrayLoggingLevel.DEBUG` and enable it across demos. - Simplify `publishToMavenCentral` call by removing explicit `SonatypeHost` parameter.
…nfigurations Complete cleanup of obsolete LinuxLib and LinuxDBus modules, including build scripts, library files, Kotlin implementations, and auxiliary files. Adjustments made to streamline the codebase and remove legacy components.
…`LinuxTrayManager` for improved thread safety and resource initialization: - Mark example code in `SNIWrapper` as comments for clarity and modularity. - Enhance `LinuxTrayManager` initialization process using `CountDownLatch` for thread-safe tray startup. - Refactor callback storage to prevent premature garbage collection of critical resources. - Simplify menu recreation logic to avoid redundant operations and ensure clean updates.
…ent: - Uncomment and restore the example Kotlin code in `SNIWrapper` for testing and reference purposes. - Add JVM shutdown hook in `LinuxTrayManager` to ensure proper cleanup on application exit. - Improve thread handling with safer `join` logic and better interruption support. - Update tray resource cleanup to include shutdown hook removal and detailed logging.
Complete removal of LinuxLib module, including its source, headers, and examples, to streamline the codebase and eliminate obsolete components.
- Use mutable references for menu item states to ensure accurate toggling. - Introduce `taskQueue` in `LinuxTrayManager` for thread-safe UI updates. - Refactor menu recreation logic to enqueue updates for GLib tray thread. - Optimize main event loop with non-blocking GLib processing and queued tasks.
- Halve sleep duration in the main loop for improved responsiveness. - Handle `InterruptedException` during shutdown gracefully by restoring the interrupt flag. - Add clarification comments for unexpected exception logging.
- Introduce `schedule` utility for task queuing in the tray thread. - Refactor menu state updates to defer recreation calls via `taskQueue`. - Optimize icon, tooltip, and menu updates for better modularity. - Adjust sleep durations for improved responsiveness in DBus handling and event loop.
…xTrayManager`: - Prevent potential crash by catching `IllegalStateException` if the JVM is already shutting down. - Ensure `shutdownHook` cleanup and null assignment are performed safely.
…indowsTrayManager`: - Switch to `infoln`, `warnln`, `errorln`, and `debugln` for consistent and structured logging. - Update comments in `LinuxTrayManager` for improved clarity by translating French to English. - Ensure logging improvements across key tray management methods and event handling.
- Complete removal of `linuxlib` module, including all source files, headers, and examples. - Streamline the codebase by eliminating unused and redundant components.
…nu updates: - Consolidate duplicate `recreateMenu` calls into a single `requestMenuRefresh` method. - Implement atomic `refreshPending` flag to reduce redundant refresh executions. - Enhance menu refresh logic for improved efficiency and thread safety. - Update comments and add helper functions for better code readability.
…ates: - Expose new native method `set_menu_item_checked` in `SNIWrapper` for individual menu item updates. - Refactor `updateMenuItemCheckedState` to allow incremental updates without full menu rebuild. - Introduce debounce window in `LinuxTrayManager` to optimize frequent refresh requests. - Improve fallback logic for menu refresh in case of unsupported native calls.
- Introduce `getCurrentTimestamp` utility using `LocalDateTime` and `DateTimeFormatter`. - Update all logging functions (`debugln`, `verboseln`, `infoln`, `warnln`, `errorln`) to include timestamps.
- Integrate `isSystemInDarkMode` for automatic system theme detection. - Enhance Material3 Theme with dynamic light/dark color schemes. - Add `darkmodedetector` library to dependencies for improved theme support.
…initialization: - Expose new native method `sni_set_debug_mode` in `SNIWrapper` for debug mode management. - Automatically configure debug mode during `LinuxSNITrayInitializer` class loading. - Update `libtray.so` binary to include the new debug handling functionality.
- Remove `co.touchlab.kermit.Logger` references across all demo files. - Replace Kermit-based log calls with `println` for simplicity. - Update `libtray.so` binary for Linux x86-64.
- Add `TrayClickTracker` to manage and store last tray click coordinates. - Use click position for improved `getTrayWindowPosition` logic. - Enhance `LinuxTrayManager` with click position tracking in callbacks. - Introduce file persistence for tray click positions to ensure availability across sessions. - Refactor position calculation to handle both corner-based and click-based methods.
Improved message handling in native code by replacing `hwnd` with `NULL` for better thread-wide message processing and ensuring proper cleanup. Refactored `WindowsTrayManager` to use a dedicated thread, enhance concurrency safety with `CountDownLatch` and atomic references, and optimize updates via a queue. Updated Windows tray resources with a new `tray.dll` for ARM64 and removed unused x86-64 variant.
Changed `tray_loop` mode to non-blocking for better responsiveness and added a delay in the loop to improve CPU efficiency. Updated Windows tray DLLs with the latest functionality.
Updated the native library and logic to retrieve the notification area coordinates with higher accuracy using modern APIs when available. Added fallback mechanisms for compatibility and adjusted window positioning logic accordingly.
Standardized and translated comments in `LinuxTrayManager` and related classes to English, ensuring consistency across the codebase. Improved documentation and fixed minor typos in `TrayPosition` logic.
Enhanced macOS support with accurate tray icon positioning and region detection. Introduced new native APIs (`tray_get_status_item_position` and `tray_get_status_item_region`) for precise geometry retrieval. Updated Kotlin logic in `TrayPosition` to integrate these functionalities. Standardized native C functions in `tray.h` and updated Swift implementations to improve compatibility and performance.
- Add detection for Linux desktop environments (GNOME, KDE, XFCE, CINNAMON, MATE). - Define environment-specific tray position defaults for improved fallback behavior. - Update `getTrayPosition` to incorporate new desktop environment logic.
This was referenced Aug 7, 2025
Closed
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.
Description
This pull request refines and enhances the cross-platform system tray management logic. Key changes include:
Linux Enhancements :
libtray.Windows Enhancements:
macOS Enhancements:
MacTrayManager) for dynamic menu updates and event handling.General Improvements:
Checklist
Testing
Extensively tested on Linux (GNOME, KDE, etc.), Windows, and macOS for expected functionality, reliability, and improved performance.