Skip to content

[v3] refresh systray menus on Menu.Update - #6314

Merged
leaanthony merged 2 commits into
wailsapp:masterfrom
DefinedNet:fix/linux-systray-menu-update
Nov 2, 2026
Merged

leaanthony merged 2 commits into
wailsapp:masterfrom
DefinedNet:fix/linux-systray-menu-update

Conversation

@johnmaguire

@johnmaguire johnmaguire commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

On Linux, Menu.Update() does not refresh a system tray menu built from that Menu.

The tray shows a StatusNotifierItem/dbusmenu layout that linuxSystemTray.setMenu builds from the Menu (it rebuilds itemMap, binds each item to a systrayMenuItem, and calls refreshLocked to bump the dbusmenu revision and emit LayoutUpdated). linuxMenu.update() only rebuilt the native GMenu/GtkMenu, so an app that does tray.SetMenu(menu) once and later menu.Clear(); menu.Add(...); menu.Update() keeps showing the first menu forever. Item setters (SetLabel, SetEnabled, ...) also stop reaching the tray after Update, because the native rebuild rebinds item.impl to the GTK item.

#6301 fixed the same gap on Windows by having windowsMenu.update() defer to refreshSystemTrayMenus(menu), which rebuilds every tray popup built from that menu; Linux was left out. This does the same on Linux: refreshSystemTrayMenus (in systemtray_linux.go, shared by the default and gtk3 builds) rebuilds the dbusmenu layout of every tray whose menu is the updated one, via the existing setMenu, and both linuxMenu.update() variants defer to it. A menu attached to no tray, or Update before the app runs, behave as before.

This is the Update half of #4604 (closed by #4615, which fixed SetMenu).

The tray rebuild binds each item.impl to the tray. On the gtk3 build, the destroy hook that releases a removed item's gtkSignalToMenuItem entry only did so when the native item still owned item.impl, so items removed from a tray menu would have leaked on every Update; the hook now releases the entry unless a newer native item has taken it over.

Known limits:

  • Same as Windows: Update() on a submenu Menu does not refresh the tray; call it on the root menu.
  • A single Menu shown by both a tray and a native menu (menubar or context menu) was already unsupported: item.impl is one slot, and whichever renderer rebuilt last owns it, so item setters reach only that one and a native checkbox/radio activation panics on item.impl.(*linuxMenuItem) when the tray owns it. Before, that depended on whether the tray's Run or the window's Update ran last; now Update always leaves the tray as the owner. For the same reason, Menu.Destroy() on a gtk3 menu the tray owns does not destroy the native widgets until the next rebuild. A tolerant native callback or a tray-side item mapping like the Windows popup would lift this; out of scope here.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • WEP (proposal only; no implementation)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Windows
  • macOS
  • Linux

Ubuntu 24.04 (container; Go 1.26.9, libgtk-4-dev, libwebkitgtk-6.0-dev, libgtk-3-dev, libwebkit2gtk-4.1-dev).

New test TestLinuxSystemTrayMenuUpdate builds a tray from a menu, then does Clear/Add/Update and checks the tray's itemMap, dbusmenu revision, and the item binding. On master it fails:

--- FAIL: TestLinuxSystemTrayMenuUpdate (0.00s)
    systemtray_linux_update_test.go:37: tray itemMap [0 1] lacks item 2 added before Menu.Update

With this branch it passes, and go test -race ./pkg/application/ passes with and without -tags gtk3. The gtk3 integration test TestGTK3MenuRebuild (-tags "gtk3 wailsintegration", under xvfb-run) gained a tray-bound segment: it fails without the destroy-hook change (item removed from a tray menu retains an activation handler) and passes with it. go build ./pkg/application/ passes for darwin and windows (cross-compiled) and GOOS=linux -tags server.

Not run on a desktop against a live StatusNotifierItem host; the dbusmenu side (refreshLocked) is the same code path SetMenu already uses.

Test Configuration

wails doctor was not run in the container (no desktop). Environment: Ubuntu 24.04 x86_64 container, Go 1.26.9 linux/amd64, GTK 4.14.5 / WebKitGTK 6.0 (2.52.6), GTK 3.24.41 / WebKit2GTK 4.1 (2.52.6) from the Ubuntu repos.

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (v3 changelog entries are added automatically)
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Linux system tray menus now reflect menu changes after an update, including added and removed items.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: wailsapp/wails/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ffcf1e2e-f379-497a-8d98-fff548d9d644
📥 Commits

Reviewing files that changed from the base of the PR and between b710765 and 773e65a.

📒 Files selected for processing: 6
  • v3/pkg/application/menu_linux.go
  • v3/pkg/application/menu_linux_gtk3.go
  • v3/pkg/application/menu_linux_gtk3_test.go
  • v3/pkg/application/menuitem_linux_gtk3.go
  • v3/pkg/application/systemtray_linux.go
  • v3/pkg/application/systemtray_linux_update_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Linux menu updates now refresh system-tray menus backed by the updated menu. GTK3 destroy callbacks preserve signal mappings owned by newer native menu items. Tests cover tray item updates and activation-handler cleanup.

Changes

Linux system-tray menu updates

Layer / File(s) Summary
Refresh trays after menu updates
v3/pkg/application/menu_linux.go, v3/pkg/application/menu_linux_gtk3.go, v3/pkg/application/systemtray_linux.go, v3/pkg/application/systemtray_linux_update_test.go
Linux menu updates defer a refresh for matching system trays. The tray update test checks the new item, menu revision, and item implementation.
Preserve GTK3 handler ownership
v3/pkg/application/menuitem_linux_gtk3.go, v3/pkg/application/menu_linux_gtk3_test.go
GTK3 destroy callbacks preserve a signal mapping when another native menu item owns the handler. The integration test checks item addition and activation-handler removal across updates.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: leaanthony

Merge Risk: Minimal · previous review 773e6

The tray refresh follows the existing DBus notification path. No merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description provides detailed motivation, implementation context, known limits, test coverage, environment details, and checklist status. It does not provide a separate “Fixes #” issue reference o…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: refreshing system tray menus when Menu.Update runs.
Full details: Description check

Explanation

The description provides detailed motivation, implementation context, known limits, test coverage, environment details, and checklist status. It does not provide a separate “Fixes #” issue reference or wails doctor output, but it is otherwise complete and directly related to the change.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit taps the menu twice,
New tray items hop in sight.
Old handlers leave when items go,
Fresh mappings stay with those they know.
The burrow updates, neat and right.

@github-actions github-actions Bot added Bug Something isn't working v3 Linux labels Oct 19, 2026
@johnmaguire
johnmaguire marked this pull request as ready for review October 19, 2026 22:47
@johnmaguire
johnmaguire force-pushed the fix/linux-systray-menu-update branch from 773e65a to 17aacb2 Compare October 25, 2026 03:37
On Linux a tray shows a dbusmenu layout that linuxSystemTray.setMenu
builds from the Menu. linuxMenu.update() only rebuilt the native menu, so
after tray.SetMenu(menu) a later menu.Clear(); menu.Add(...);
menu.Update() left the tray on the first menu forever. Windows already
rebuilds every tray popup built from the menu in update(); do the same on
Linux by rebuilding the layout of every tray whose menu is the updated
one, under the tray's itemMapLock as setMenu does.

The tray rebuild binds item.impl to the tray, so the gtk3 destroy hook no
longer saw itself as the owner and kept the activation handler entries of
items removed from a tray menu. Release them unless a newer native item
has taken the entry over.
@johnmaguire
johnmaguire force-pushed the fix/linux-systray-menu-update branch from 17aacb2 to cc28190 Compare October 26, 2026 15:50
@johnmaguire johnmaguire changed the title fix(v3/linux): refresh systray menus on Menu.Update [v3] refresh systray menus on Menu.Update Oct 26, 2026
@leaanthony
leaanthony merged commit fb7ab68 into wailsapp:master Nov 2, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Linux v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants