如何通过左键单击打开tray menu?
默认情况下,通过单击鼠标右键打开菜单。
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;
答案 0 :(得分:0)
Tray.menu
获取或设置托盘菜单,单击托盘图标时将显示菜单。
在Mac OS X上,单击托盘时将显示菜单(这是Mac OS X上托盘图标可用的唯一操作)。在Windows和Linux上,当您用鼠标右键单击托盘时,将显示菜单,单击鼠标左键发送单击事件,但不显示菜单。
为了减少与不同平台的差异,设置菜单属性是将菜单绑定到托盘的唯一方法,无法在Linux和Windows上单击鼠标左键弹出菜单。
https://github.com/nwjs/nw.js/wiki/Tray
但是,您可以制作自定义托盘菜单,请查看:Create window-like menu on OS X
答案 1 :(得分: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()