[PR #2941] [MERGED] fix: use native NSStatusItem for the macOS tray menu (#2759) #3019

Closed
opened 2026-10-14 21:06:56 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/2941
Author: @vkamn
Created: 8/5/2026
Status: ✅ Merged
Merged: 8/5/2026
Merged by: @vkamn

Base: dev ← Head: fix/macos-native-tray-menu


📝 Commits (2)

  • b08a596 fix: use native NSStatusItem for the macOS tray menu (#2759)
  • eb2b764 chore: return error messages

📊 Changes

6 files changed (+75 additions, -209 deletions)

View changed files

📝 client/cmake/macos_ne.cmake (+0 -2)
📝 client/platforms/macos/macosstatusicon.h (+8 -6)
📝 client/platforms/macos/macosstatusicon.mm (+32 -154)
➖ client/ui/utils/neNotificationHandler.h (+0 -36)
📝 client/ui/utils/systemTrayNotificationHandler.cpp (+29 -11)
📝 client/ui/utils/systemTrayNotificationHandler.h (+6 -0)

📄 Description

On macOS 14+ the status-item menu is tracked out of process, so Qt's QCocoaSystemTrayIcon menu-tracking observer (installed by setContextMenu) fires asynchronously and calls emitActivated(), which reads -[NSEvent clickCount] when NSApp.currentEvent is no longer a mouse event. clickCount then raises NSInternalInconsistencyException, crashing the app the first time the tray menu is opened.

Stop using QSystemTrayIcon on macOS and own the NSStatusItem ourselves (MacOSStatusIcon), attaching the menu's backing native NSMenu via QMenu::toNSMenu(). AppKit shows the menu natively - with menu-bar highlight and correct anchoring - without registering the crashing observer, and Qt keeps the NSMenu in sync with the QActions so the existing menu logic (enable/disable, translations) is reused. The icon stays colored per state and notifications go through UNUserNotificationCenter. Windows and Linux keep QSystemTrayIcon unchanged.

This also wires up the previously-unused MacOSStatusIcon and removes the orphaned neNotificationHandler.h.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amnezia-client/pull/2941 **Author:** [@vkamn](https://github.com/vkamn) **Created:** 8/5/2026 **Status:** ✅ Merged **Merged:** 8/5/2026 **Merged by:** [@vkamn](https://github.com/vkamn) **Base:** `dev` ← **Head:** `fix/macos-native-tray-menu` --- ### 📝 Commits (2) - [`b08a596`](https://github.com/amnezia-vpn/amnezia-client/commit/b08a5969ac8bd8012f7e6cbaf135fa19244f761b) fix: use native NSStatusItem for the macOS tray menu (#2759) - [`eb2b764`](https://github.com/amnezia-vpn/amnezia-client/commit/eb2b76479fa19deadb3ababfc94f0c4ace58ed35) chore: return error messages ### 📊 Changes **6 files changed** (+75 additions, -209 deletions) <details> <summary>View changed files</summary> 📝 `client/cmake/macos_ne.cmake` (+0 -2) 📝 `client/platforms/macos/macosstatusicon.h` (+8 -6) 📝 `client/platforms/macos/macosstatusicon.mm` (+32 -154) ➖ `client/ui/utils/neNotificationHandler.h` (+0 -36) 📝 `client/ui/utils/systemTrayNotificationHandler.cpp` (+29 -11) 📝 `client/ui/utils/systemTrayNotificationHandler.h` (+6 -0) </details> ### 📄 Description On macOS 14+ the status-item menu is tracked out of process, so Qt's QCocoaSystemTrayIcon menu-tracking observer (installed by setContextMenu) fires asynchronously and calls emitActivated(), which reads -[NSEvent clickCount] when NSApp.currentEvent is no longer a mouse event. clickCount then raises NSInternalInconsistencyException, crashing the app the first time the tray menu is opened. Stop using QSystemTrayIcon on macOS and own the NSStatusItem ourselves (MacOSStatusIcon), attaching the menu's backing native NSMenu via QMenu::toNSMenu(). AppKit shows the menu natively - with menu-bar highlight and correct anchoring - without registering the crashing observer, and Qt keeps the NSMenu in sync with the QActions so the existing menu logic (enable/disable, translations) is reused. The icon stays colored per state and notifications go through UNUserNotificationCenter. Windows and Linux keep QSystemTrayIcon unchanged. This also wires up the previously-unused MacOSStatusIcon and removes the orphaned neNotificationHandler.h. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-14 21:06:56 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#3019
No description provided.