electron: tray click is not executed and it shows the context menu instead

  • Output of node_modules/.bin/electron --version: v3.0.2 and v4.0.0

  • Operating System (Platform and Version): Linux bitang 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

  • Output of node_modules/.bin/electron --version on last known working Electron version (if applicable): v2

Expected Behavior

I used the toggle show/hide of the window on the tray click and in v2 it was working.

Actual behavior

When I click now on the tray, it opens the context menu - which was working on right click only.

To Reproduce

If you provide a URL, please list the commands required to clone/setup/run your repo e.g.

$ git clone https://github.com/patrikx3/onenote
$ npm install
$ ./bin/p3x-onenote.js

Screenshots not applicable

Additional Information i suppose it is informative.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 36
  • Comments: 89 (1 by maintainers)

Most upvoted comments

Looks like the proper left/primary mouse click behavior is getting back with electron version 8, see https://github.com/electron/electron/issues/21445#issuecomment-565061274 for details (tested using 8-beta4). But it seems that Linux users are going to face new tray icon related curse 😃

@rwwagner90 I’m just tricking electron to think libappindicator is not there. In this case, it falls back to the old behaviour. It can be easily added as a switch.

The relevant code is here:

https://github.com/electron/electron/blob/8798571a77a4d2a7e073b046d2e8b56caa4d1e68/shell/browser/ui/gtk/app_indicator_icon.cc#L98-L106

The code tries to load libappindicator with/without a trailing ā€œ.1ā€. If that fails, it returns.

So what I do is to create libappindicator3.so and libappindicator3.so.1 in the program folder - that’s the location where it’s first looked for. This causes both dlopen to fail.

If libappindicator is not loaded, the condition here is false:

https://github.com/electron/electron/blob/d8594f7a782418d2da3351541b170d047392277b/shell/browser/ui/gtk/status_icon.cc#L46

In this case, it falls back to ā€œGtkStatusIconā€:

https://github.com/electron/electron/blob/d8594f7a782418d2da3351541b170d047392277b/shell/browser/ui/gtk/status_icon.cc#L53-L54

So in gtk/status_icon.cc#L46 should be an extra condition, something like ā€œif getenv(…)ā€ or better, add a config setting that is tested at this location.

Hello, I cannot believe that this is still unresolved after years 😦

The docs at https://www.electronjs.org/docs/api/tray states: ā€œOn Linux the app indicator will be used if it is supported, otherwise GtkStatusIcon will be used insteadā€. So I uninstalled libindicator to check if it works better with GtkStatusIcon. But in this case no status icon at all occurs. Did I miss something? And if it would work, maybe an option to enforce GtkStatusIcon could help to workarount this issue?

@micw that seems reasonable. Definitely need some kind of workaround.

Get rid of electron? šŸ˜‰

Just more proof, ubuntu is the worst desktop…

Not to pile on here, but… yeah, this is an issue. Users do typically expect left- and right-click actions to do different things.

Also, when libappindicator is not installed, this works the ā€œrightā€ way (i.e. left-click detection works), but installing it ­— even as a dependency for an unrelated package — breaks existing Electron tray icons, as described above. This, in itself, is incredibly annoying.

It should definitely be added to electron. There’s no guarantee that the workaround will work in later releases. If you ask me, the old behavior should be the default until the new implementation works properly.

This is annoying af. Makes using apps such as slack-desktop or discord real pain. 😦

This is still an issue with:

  • Element Desktop 1.10.6, Electron 17
  • Skype 8.81.0.268, Electron 15.3.4
  • Signal Desktop Beta 5.35.0-beta.1, Electron 17.1.0

Sounds like you do, thanks!

I don’t, tray plugins for Linux do.

Reproducible with libappindicator3 (libappindicator-gtk3) package installed with any electron version including latest. Reproducible with Riot for ex. Works fine if package is not installed. However icon looks weird, see: vector-im/riot-web#7553

Happens also on Xubuntu 18.04.

The libappindicator is not implementing ā€œActivateā€ method. But then there is not handler to call in Electron by that ā€œActivateā€ There is code for creating a dummy MenuItem that will represent the left-click action, but it is not really created because HasClickAction returns false https://github.com/electron/electron/blob/8532e1239ec929e31b764ffcd314c8db3e09a19f/shell/browser/ui/tray_icon_gtk.cc#L64

It needs to be fixed both in AppIndicator and Electron

For more details, see: https://bugs.launchpad.net/ubuntu/+source/libappindicator/+bug/1910521/comments/8

@micw should we add this to Electron itself or suggest this workaround?

The proper left/primary mouse click behavior is going to be broken again, see #23674. This is just a guess though.

Hi, are there any updates on a possible solution to this problem…?

I don’t know the v2 Version, but i would asume leftClick on trayIcon is show/hide (or show and go to new message if there is an indicator), rightClick is the context menue. This leftClick visibility toggle would help a lot on tiling window managers, since you can pull in rocketchat on whatever workspace your on when you need it 😃

Now on 2.15.3 its both clicks context menue on ubuntu x86 I3wm

This Electron version has less functions on the tray. We like more functions not less. Although, Electron is one if the best platform, i have to stay.

it is 100%, that the tray will come back with right left and right click as it should. unity is not the best desktop. i am certain.

now on this line: https://github.com/patrikx3/onenote/blob/master/src/electron/main/create/tray.js#L11

when i click on the tray, it should show on the console, but it is not shown and instead on the click it shows to context menu, here: https://github.com/patrikx3/onenote/blob/master/src/electron/main/create/tray.js#L16

Why does it show the context menu when i click on it, when i never requested it? THANKS VERY MUCH!