fix(macos): system tray left click menu

This commit is contained in:
Dave Lane committed 2026-09-28 23:18:23 -04:00
1 parent 08131c5e27
commit 455c8a4910
2 files changed
+29

No files matched your search

+16
View File
@@ -291,10 +291,26 @@ namespace system_tray {
static auto virtualhid_license_menu = initial_virtualhid_license_menu(); ///< Virtual HID Broker license submenu.
#endif
#ifdef __APPLE__
/**
* @brief Leave macOS tray menu presentation to Qt's native status item.
*
* Qt opens an attached context menu on mouse press. Supplying a callback
* prevents the tray library from opening a second popup on activation.
*
* @param tray_icon Tray icon that received the click.
*/
void tray_native_menu_click_cb([[maybe_unused]] struct tray *tray_icon) {
}
#endif
// Tray menu
static struct tray tray = {
.icon = TRAY_ICON,
.tooltip = PROJECT_NAME,
#ifdef __APPLE__
.cb = tray_native_menu_click_cb,
#endif
.menu =
(struct tray_menu[]) {
// Tray menu labels currently use the project's English source strings.
+13
View File
@@ -339,6 +339,19 @@ TEST_F(SystemTrayTest, UpdatesAreIgnoredBeforeInitialization) {
EXPECT_EQ(system_tray::end_tray(), 0);
}
#ifdef __APPLE__
TEST_F(SystemTrayTest, LeftClickUsesNativeMacOSMenu) {
const auto &tray_data = system_tray::tray_data_for_testing();
ASSERT_NE(tray_data.cb, nullptr);
ASSERT_NE(tray_data.menu, nullptr);
tray_data.cb(nullptr);
EXPECT_STREQ(tray_data.menu[0].text, "Open Sunshine");
EXPECT_FALSE(system_tray::tray_initialized_for_testing());
}
#endif
#ifdef _WIN32
TEST_F(SystemTrayTest, ResolvesDevelopmentTrayIconsFromExecutableDirectory) {
EXPECT_EQ(system_tray::resource_path_for_testing(nullptr), nullptr);