Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick successive clicks on tray do not fire clicked event #1825

Closed
davej opened this issue May 31, 2015 · 11 comments
Closed

Quick successive clicks on tray do not fire clicked event #1825

davej opened this issue May 31, 2015 · 11 comments

Comments

@davej
Copy link
Contributor

davej commented May 31, 2015

I have only tested this on OS X. But I consistently see the same result. OS X 10.10.3, Electron 0.27.1.

Here's a quick video demonstrating the issue (~300KB).

menubar.tray = new Tray(iconPath);
menubar.tray.on('clicked', function (e, bounds) {
  console.log('clicked'); // doesn't fire after quick successive clicks
});
@davej davej changed the title Quick successive clicks on tray do not fired clicked event Quick successive clicks on tray do not fire clicked event May 31, 2015
@zcbenz
Copy link
Member

zcbenz commented Jun 3, 2015

You should turn off highlight mode, otherwise OS X would try to toggle between different states during your clicks.

@zcbenz zcbenz closed this as completed Jun 3, 2015
@davej
Copy link
Contributor Author

davej commented Jun 3, 2015

@zcbenz: Thanks, I will do that.

Is this not a bug though? Native apps are able to highlight the icon and still respond to clicks.

@zcbenz
Copy link
Member

zcbenz commented Jun 3, 2015

It is an expected behavior of OS X.

@davej
Copy link
Contributor Author

davej commented Jun 3, 2015

Sorry for labouring the issue and thank you for replying but could you explain why it is expected behaviour?

@zcbenz
Copy link
Member

zcbenz commented Jun 3, 2015

You can write a simple Cocoa app to reproduce this behavior, no one knows the reason of it except for the Apple devs.

@davej
Copy link
Contributor Author

davej commented Jun 3, 2015

@zcbenz Thanks!

Would it be possible to implement this by introducing a stateChanged event that listens for changes in the tray's state (instead of listening for clicks)? This could be Mac OS X only (or it could probably be easily polyfilled on other platforms by listening for clicks and toggling a 'pseudo-state' internally in Electron).

HighlightMode is necessary for a native feel on Mac, it would be very nice to have it.

@davej
Copy link
Contributor Author

davej commented Jun 3, 2015

I have tried tray.setHighlightMode(false) and the issue is still there. The icon no longer highlights but it still doesn't respond to clicks in quick succession.

@zcbenz
Copy link
Member

zcbenz commented Jun 4, 2015

Your clicks might have been trapped as double-clicked:
https://github.com/atom/electron/blob/master/docs/api/tray.md#event-double-clicked

@davej
Copy link
Contributor Author

davej commented Jun 4, 2015

That was the issue, huge thanks! I'm now performing the show/hide action on double-click also and it works perfectly.

Should the tray icon be trapping double-clicks if the app doesn't use them? Could Electron listen for new double-clicked listeners and add a double click action dynamically to the tray button, instead of always adding a double click action? Perhaps this could be done by listening for newListener events on the EventEmitter?

@zcbenz
Copy link
Member

zcbenz commented Jun 4, 2015

Should the tray icon be trapping double-clicks if the app doesn't use them? Could Electron listen for new double-clicked listeners and add a double click action dynamically to the tray button, instead of always adding a double click action? Perhaps this could be done by listening for newListener events on the EventEmitter?

This behavior has been there for quite a long time, changing it would break existing apps. So no matter whether it is a good behavior or not, I think we should stick to it.

@davej
Copy link
Contributor Author

davej commented Jun 4, 2015

I think the behaviour I have suggested should be backwards compatible with existing Electron apps though, I don't understand how it would break them if they're not listening for the double-clicked event. It's also possible to have a more explicit Tray.setIgnoreDoubleClicks() method but this introduces API bloat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants