clashmi icon indicating copy to clipboard operation
clashmi copied to clipboard

[BUG][Linux] Tray menu does not open in 1.0.31.1703 on GNOME

Open Rubindai opened this issue 1 month ago • 3 comments

操作系统/Operating System

Linux

系统版本/Operating System Version

Ubuntu 26.04.1 LTS; GNOME Shell 50.1; Wayland; Ubuntu AppIndicator extension enabled; x86_64

App版本/App Version

1.0.31.1703 (Linux amd64 .deb; installed package version 1.0.31+1703). Previously installed: 1.0.29.1503.

描述/Describeption

The top-bar tray icon is visible, but clicking it does not open the menu on Ubuntu/GNOME. I noticed this after upgrading from 1.0.29.1503 to 1.0.31.1703. I recall the older version working, but have not performed a downgrade A/B test.

Expected: clicking the icon shows Connect/Disconnect, Rule, Global, Direct, Open and Exit. Actual: the icon is registered and the menu exists internally, but no menu appears. Restarting the unmodified app does not fix it. This also reproduces with the VPN disconnected.

Root-cause investigation

The tagged dependency files show tray_manager changed from 0.5.3 to 0.8.0. The affected release resolves nativeapi/cnativeapi 0.5.2.

In tray_manager 0.8.0, the legacy TrayManager wrapper creates a native TrayIcon and attaches a context menu without setting its context-menu trigger. In cnativeapi 0.5.2, the trigger defaults to None. On Linux, ShouldExposeMenu() requires both a menu and a Clicked or RightClicked trigger; otherwise MenuObjectPath() returns /NO_DBUSMENU.

That matches the runtime behavior: the StatusNotifierItem advertises Menu=/NO_DBUSMENU and ItemIsMenu=false, although GetLayout on /StatusNotifierItem/Menu returns the complete menu. Ubuntu's AppIndicator extension treats /NO_DBUSMENU as no menu to display.

Verified local workaround / proposed upstream fix

A small process-local compatibility module calls the original native TrayIcon::SetContextMenu and then sets ContextMenuTrigger::Clicked only when a non-null menu is attached and the trigger is still None. Installed Clash Mi binaries, GNOME extensions and network settings remain unchanged.

With this change, Menu becomes /StatusNotifierItem/Menu, ItemIsMenu becomes true, and clicking the icon visibly opens the menu. This was confirmed on the affected machine and through a normal desktop relaunch using the compatibility launcher.

A source-level fix could explicitly set the Linux menu trigger in tray_manager's legacy wrapper, or in Clash Mi after attaching the menu. Clash Mi recreates its Linux tray icon, so the trigger needs to be applied to each newly created icon. Other platforms and explicitly configured trigger behavior should be preserved.

Source references

  • Previous dependencies: https://github.com/KaringX/clashmi/blob/v1.0.29.1503/pubspec.lock
  • Affected dependencies: https://github.com/KaringX/clashmi/blob/v1.0.31.1703/pubspec.lock
  • tray_manager 0.8.0: https://pub.dev/packages/tray_manager/versions/0.8.0
  • cnativeapi 0.5.2: https://pub.dev/packages/cnativeapi/versions/0.5.2

The investigation checked the published package archives for those exact versions, not just the latest source branch.

Manual validation

With the compatibility module enabled, the tray menu and its Rule, Direct, Global, Connect/Disconnect, Open and Exit actions were confirmed working in manual testing. A normal desktop relaunch was separately checked to confirm that the menu still advertises the correct D-Bus path. The workaround is removable and disables itself if an upstream update changes the tested binaries.

复现步骤/Reproduction steps

  1. Run Clash Mi 1.0.31.1703 on Ubuntu/GNOME Wayland with the Ubuntu AppIndicator extension enabled.
  2. Leave the VPN disconnected; the issue does not require a connection.
  3. Click the Clash Mi icon in the top bar.
  4. Observe that the icon is visible but its menu does not open.
  5. Quit and relaunch the unmodified app; the problem remains.

Diagnostic check: query the app's org.kde.StatusNotifierItem Menu property on /StatusNotifierItem, then call com.canonical.dbusmenu.GetLayout on /StatusNotifierItem/Menu. The former says /NO_DBUSMENU while the latter returns the expected entries.

日志/Log

Targeted D-Bus observations (no private configuration or network logs):

Before the workaround:
  Menu: /NO_DBUSMENU
  ItemIsMenu: false
  /StatusNotifierItem/Menu GetLayout: Connect/Disconnect, Rule, Global, Direct, Open, Exit

After setting the attached menu's trigger to Clicked:
  Menu: /StatusNotifierItem/Menu
  ItemIsMenu: true
  The menu visibly opens when the top-bar icon is clicked.

网络检测结果/Network Check Results

Not applicable: this is a tray UI issue and reproduces with the VPN disconnected. No network check is needed to reproduce it.

Rubindai avatar Oct 18 '26 16:10 Rubindai

https://github.com/KaringX/clashmi/releases/tag/v1.0.32.1800

GooRingX avatar Oct 19 '26 05:10 GooRingX

1.0.32.1800 still reproduces this / 1.0.32.1800 仍然复现

验证环境 / Environment: Ubuntu 26.04 LTS, GNOME Shell 50.1, Wayland, Ubuntu AppIndicators enabled; ClashMi 1.0.32+1800 installed from .deb (installed package sha256 51e6697e30d7066917cdd71b04e3dafd1f4fd42bbb16425a29dd15c0b948a2da, identical to the official clashmi_1.0.32.1800_linux_amd64.deb asset).

Observed on the running app, no relaunch needed / 运行中的实例上直接观察到:

  • Menu = /NO_DBUSMENU, ItemIsMenu = false on both registered items (org.kde.StatusNotifierItem-<pid>-1 / -2; the -2 one is Status=Passive and gets hidden by GNOME, so only one icon is visible).
  • com.canonical.dbusmenu.GetLayout on /StatusNotifierItem/Menu still returns the complete menu (断开 / 规则 / 全局 / 直连 / 打开 / 退出, with correct toggle-state), i.e. the menu data is fine — only its exposure is broken.
  • Ubuntu's AppIndicators extension turns /NO_DBUSMENU into menuPath = null (appIndicator.js:626), so it attaches no menu and clicking the icon does nothing.
  • Control group on the same session: ToDesk exposes Menu=/org/ayatana/NotificationItem/ToDesk/Menu, Snipaste exposes Menu=/MenuBar. So the shell/extension side is fine.

Dependency check / 依赖对照: both v1.0.31.1703 and v1.0.32.1800 lock tray_manager 0.8.0 + cnativeapi 0.5.2. So the "Adapted for version 0.8 of TrayManager" change in 1.0.32.1800 did not make Menu point at /StatusNotifierItem/Menu; the Linux context-menu trigger still ends up as None.

Upstream status / 上游现状: leanflutter/tray_manager#107 "Fix the tray icon menu not working on Linux" is still open, so the fix is not in the published 0.8.0 either.

Suggested fix / 建议修法: after attaching the menu (and whenever the Linux tray icon is recreated — this app recreates it), explicitly call native_tray_icon_set_context_menu_trigger(icon, ContextMenuTrigger::Clicked) when the trigger is still None. That is what made the menu work in the report above, and it's also what a D-Bus side workaround has to compensate for today.

Verified from the D-Bus side that the menu content and Event handling are complete (forwarding GetLayout/Event to /StatusNotifierItem/Menu produces a fully working tray menu), so no change is needed to the menu itself — only to the SNI exposure.

If useful, I can also share the small local D-Bus workaround (it re-exposes the existing menu under its own StatusNotifierItem, without modifying ClashMi) — but a one-line trigger fix in the app would be much cleaner and would also drop that extra icon.

kaijia323 avatar Oct 26 '26 17:10 kaijia323

https://github.com/KaringX/clashmi/releases/tag/v1.0.33.1900

GooRingX avatar Nov 17 '26 04:11 GooRingX