0

How can I open the tray menu by left-click?

By default the menu opened up by hitting right-click.

CODE:

// Load native UI library
var gui = require('nw.gui');

// Create a tray icon
var tray = new gui.Tray({
    title: 'Tray',
    icon: 'img/icon.png',
    click: function(){
        // Open tray menu here!!
        console.log('READY!!!');
    }
});

// Give it a menu
var menu = new gui.Menu();
menu.append(new gui.MenuItem({ type: 'checkbox', label: 'box1' }));
tray.menu = menu;
Kuf
  • 17,318
  • 6
  • 67
  • 91
  • Have you tried listening to the tray click event, and manually calling the menu click event? ` tray.on('click', function(click) { tray.menu.popup(click.x, click.y); }); ` should do the trick, but I haven't tested it. You might have to play with the click event to get the location. Convert it to JSON and print it if it doesn't work. – Luke Adams Mar 27 '15 at 00:01
  • @LukeAdams I've tried that but the x and y aren't relative to the window so the popup opens in the wrong place – Kuf Mar 27 '15 at 07:30

2 Answers2

0

Tray.menu

Get or Set the menu of Tray, menu will be showed when you click on the Tray icon.

On Mac OS X the menu will be showed when you click on the tray (which is the only action available for tray icons on Mac OS X). On Windows and Linux, the menu will be showed when you single click on the tray with right mouse button, clicking with left mouse button sends the click event and does not show a menu.

In order to reduce differences from different platforms, setting menu property is the only way to bind a menu to tray, there's no way to popup a menu with left mouse button click on Linux and Windows.

https://github.com/nwjs/nw.js/wiki/Tray

However, you can make a custom tray menu, check this out: Create window-like menu on OS X

Community
  • 1
  • 1
CRQ
  • 357
  • 2
  • 4
  • 14
0

as for me, this was ok (CoffeeScript):

tray.on "click",
  (clickEvent) =>
    win.focus()
    tray.menu.popup(clickEvent.x - win.x - (window.screen.width - window.screen.availWidth), clickEvent.y - win.y - (window.screen.height - window.screen.availHeight))
    return false

win is:

win = gui.Window.get()
lex
  • 1