mac electron 中想实现, 在点击鼠左键弹出弹出程序界面,右键弹出托盘选项,查了良久发现没有办法捕获到左键点击事件,google了好久,把结果贴出来吧,方便后来人,希望能省点事件;
https://github.com/electron/electron/issues/2830
原来是当调用了setContextMenu()导致的,具体的源码我没有再往底层跟了,原因是:调用了了setContextMenu(),会走系统默认的托盘点击事件(mac 默认是左键点击显示托盘选项);
最后为了满足需求我的实现如下:
this.tray = new Tray(trayIcon);
// setContextMenu will display the tray menu to default click, like "left mouse click on mac"
// referce https://github.com/electron/electron/issues/2830
// this.tray.setContextMenu(this.menu);
this.tray.on('click', () => {
global.application && global.application.showPage('main');
})
this.tray.on('right-click', () => {
this.tray.popUpContextMenu(this.menu);
})