Skip to content

fix(tray): populate Linux right-click menu via setContextMenu - #2856

Merged
setchy merged 4 commits into
gitify-app:mainfrom
BlueManCZ:fix/linux-tray-menu
May 9, 2026
Merged

fix(tray): populate Linux right-click menu via setContextMenu#2856
setchy merged 4 commits into
gitify-app:mainfrom
BlueManCZ:fix/linux-tray-menu

Conversation

@BlueManCZ

@BlueManCZ BlueManCZ commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Right-clicking the tray icon on Linux opened an empty menu (or nothing at all on some DEs) because the existing right-clickpopUpContextMenu handler doesn't reach libappindicator / StatusNotifierItem (D-Bus). On that path, Electron only emits the right-click event when no context menu is set — setContextMenu instead hands the menu to the host indicator so it renders natively on right-click.

Left-click behavior is unchanged on every platform — menubar's own click handler still toggles the popup. Note that some tray providers (e.g. KStatusNotifier-backed indicators on GNOME) require a double-click to trigger the icon's primary action by design; that's a property of the provider, not something this PR alters either way.

The macOS / Windows code path is intentionally untouched: setContextMenu intercepts left-click on macOS and would break the menubar window toggle, so those platforms keep the existing right-click + popUpContextMenu handler.

This mirrors the approach we took in zoidsh/meru#498.

Show / Hide menu entries

Adds two entries at the top of the right-click menu — Show Gitify and Hide Gitify — whose visibility tracks the popup state via window show/hide events. Only one is ever visible at a time, giving users a guaranteed single-click path to the popup even on tray providers where icon activation needs a double-click.

On Linux, after flipping the items we re-publish the menu via setContextMenu so the change propagates through D-Bus immediately rather than waiting for the next mutation event. macOS / Windows rely on popUpContextMenu reading the latest menu state at right-click time, so no re-publish is needed there.

Test plan

  • Linux: right-click tray icon → menu shows Show Gitify / Check for updates / Developer / Visit Website / Quit Gitify (previously empty).
  • Linux: right-click → Show Gitify shows the popup; right-click again → Hide Gitify hides it.
  • Linux: hide popup via Esc / WM close → right-click still shows Show Gitify (label tracked).
  • Linux: click (or double-click, depending on the tray provider) tray icon → toggles the Gitify popup as before.
  • macOS: right-click tray icon → menu still appears via popUpContextMenu; left-click still toggles popup; Show / Hide labels track visibility.
  • Windows: right-click tray icon → menu still appears; left-click still toggles popup; Show / Hide labels track visibility.
  • pnpm test passes.

May close #1612, #2096 — both threads include the empty/unresponsive right-click menu reported here.

🤖 Generated with Claude Code

On Linux, trays go through libappindicator / StatusNotifierItem
(D-Bus). Electron only emits 'right-click' on that path when no
context menu is set, so the popUpContextMenu call inside our JS
handler showed an empty menu (or nothing) depending on the
desktop environment. Hand the menu to the host indicator
instead so it renders natively on right-click.

Keep the existing right-click + popUpContextMenu path on
macOS / Windows — setContextMenu intercepts left-click on
macOS and would break the menubar window toggle.

Refs gitify-app#1612, gitify-app#2096.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions github-actions Bot added the bug Something isn't working label May 8, 2026
Some Linux tray providers (e.g. KStatusNotifier-backed indicators
on GNOME) require a double-click on the icon to trigger the
primary action. A "Toggle Gitify" menu item gives users a
guaranteed single-click path to show or hide the popup
regardless of the provider's activation behavior.

Static label keeps the menu cheap on Linux — no need to rebuild
and re-call setContextMenu on visibility changes for a Show/Hide
label flip to propagate over D-Bus.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@setchy

setchy commented May 8, 2026

Copy link
Copy Markdown
Member

Can you help me better understand the Toggle Gitify option....

@BlueManCZ

Copy link
Copy Markdown
Contributor Author

It's just Show/Hide for the Gitify window. Applications usually have this in tray menu, I thought Gitify may have this as well.

@setchy

setchy commented May 8, 2026

Copy link
Copy Markdown
Member

It's just Show/Hide for the Gitify window. Applications usually have this in tray menu, I thought Gitify may have this as well.

Gotcha

Is this a common context menu in each Linux app? What would the experience be like if this was left out?

@BlueManCZ

Copy link
Copy Markdown
Contributor Author
obrazek
Out of 14 applications with a tray menu currently installed on my system, only Gitify lacks a "Show window" option. I was so used to this pattern that it never occurred to me it might vary, but as it turns out, there's no real standardization. From this small sample, the most common labels for the entry are:

I went with "Toggle Gitify" as the best compromise between functionality and brevity. From a UX standpoint, though, the ideal solution would be a dynamic entry that reads "Show Gitify" when the window is hidden and "Hide Gitify" when it's visible, giving the user clear, context-aware feedback at a glance.

It's also worth noting that this entry carries real accessibility value: for users who rely on keyboard navigation or assistive technologies, the tray menu may be the only reliable way to interact with the application, making a clearly labeled show/hide entry not just convenient but essential. The dynamic label also has a subtle debugging benefit. If the entry reads "Hide Gitify" but the window is nowhere to be seen, that's an immediate signal that something has gone wrong, such as the window being off-screen or on a different workspace.

@setchy

setchy commented May 9, 2026

Copy link
Copy Markdown
Member

Super thorough analysis @BlueManCZ, thank you!!!

"Show ([app name])" when hidden, "Hide ([app name])" when visible (Meru, Spotify, VLC)

Let's go forward with this variant then

Replaces the static "Toggle Gitify" entry with two MenuItems
whose visibility tracks the popup window state — the menu now
shows "Show Gitify" when the popup is hidden and "Hide Gitify"
when it's visible.

The window's show/hide events are forwarded to MenuBuilder.
On Linux the indicator caches the menu over D-Bus, so after
flipping visibility we re-publish via setContextMenu to push
the change through immediately rather than wait for the next
mutation event.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@setchy
setchy merged commit 24ceb67 into gitify-app:main May 9, 2026
13 checks passed
@setchy setchy added this to the Release 7.0.0 milestone May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Development

Successfully merging this pull request may close these issues.

Unable to open Gitify on Pop!_OS 22.04

3 participants