我正在尝试捕获点击,甚至在托盘图标上单击OSX上的上下文菜单,但根据文档,这在OSX中由于某种原因被禁用:
Platform limitations:
On OS X clicked event will be ignored if the tray icon has context menu.
我想知道是否有另一种方法可以知道带有上下文菜单的托盘图标何时与之交互?
相关代码:
var app = require('app');
var path = require('path')
var Menu = require('menu');
var MenuItem = require('menu-item');
var Tray = require('tray');
var appIcon = null;
var menu = null;
app.on('ready', function(){
appIcon = new Tray(path.join(__dirname, 'images/icon.png'));
appIcon.on('clicked', function(event, bounds) {
console.log('clicked');
});
menu = new Menu();
menu.append(new MenuItem({ label: 'Quit', id: 'quit', click: function() { app.quit(); } }));
appIcon.setContextMenu(menu);
});
答案 0 :(得分:1)
现在它适用于OS X(10.11.4)。
请检查。 main.js:
// Load in dependencies
var app = require('app');
var Tray = require('tray');
// When the Electron has loaded
app.on('ready', function onready () {
// Log to the console to verify logging works
console.log('Hello World!');
// Create a tray
var tray = new Tray(__dirname + '/icon.png');
// When the tray icon is clicked, log to our console
tray.on('click', function handleClicked () {
console.log('Tray clicked');
});
});
执行命令
electron main.js