[PR #2759] [MERGED] fix: use native NSStatusItem for the macOS tray menu #2935

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

📋 Pull Request Information

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

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


📝 Commits (5)

  • e5c62b6 fix: use native NSStatusItem for the macOS tray menu
  • e1fa036 Merge branch 'amnezia-vpn:dev' into fix/macos-native-tray-menu
  • a51f304 merge: origin/dev into fix/macos-native-tray-menu
  • cb83205 merge: origin/dev into fix/macos-native-tray-menu
  • 02ff3ed merge: origin/dev into fix/macos-native-tray-menu

📊 Changes

5 files changed (+68 additions, -215 deletions)

View changed files

📝 client/platforms/macos/macosstatusicon.h (+8 -6)
📝 client/platforms/macos/macosstatusicon.mm (+25 -162)
➖ 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/2759 **Author:** [@real-alexei](https://github.com/real-alexei) **Created:** 6/21/2026 **Status:** ✅ Merged **Merged:** 8/5/2026 **Merged by:** [@vkamn](https://github.com/vkamn) **Base:** `fix/macos-native-tray-menu` ← **Head:** `fix/macos-native-tray-menu` --- ### 📝 Commits (5) - [`e5c62b6`](https://github.com/amnezia-vpn/amnezia-client/commit/e5c62b6346662298c4b303a1b07734b142c45fa6) fix: use native NSStatusItem for the macOS tray menu - [`e1fa036`](https://github.com/amnezia-vpn/amnezia-client/commit/e1fa036329ad9638698dc7deaca42d3928dd507d) Merge branch 'amnezia-vpn:dev' into fix/macos-native-tray-menu - [`a51f304`](https://github.com/amnezia-vpn/amnezia-client/commit/a51f304c6c878fb5f2b70f1e9e46ddfe8fc34728) merge: origin/dev into fix/macos-native-tray-menu - [`cb83205`](https://github.com/amnezia-vpn/amnezia-client/commit/cb83205e430ce89980615185239fd8c9a152a4f4) merge: origin/dev into fix/macos-native-tray-menu - [`02ff3ed`](https://github.com/amnezia-vpn/amnezia-client/commit/02ff3ed9831202e81b9d654bf12c195560b39f5e) merge: origin/dev into fix/macos-native-tray-menu ### 📊 Changes **5 files changed** (+68 additions, -215 deletions) <details> <summary>View changed files</summary> 📝 `client/platforms/macos/macosstatusicon.h` (+8 -6) 📝 `client/platforms/macos/macosstatusicon.mm` (+25 -162) ➖ `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:19 +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#2935
No description provided.