1.自定义菜单
// 自定义菜单 var templateMenu = [{ label: "首页", submenu: [{ label: "111" }, { label: '9089' }] }, , { label: "编辑", submenu: [{ label: '123' }] }] testmenu = Menu.buildFromTemplate(templateMenu);
2. 在鼠标经过托盘事件中展示自定义菜单
//isLeave 是自定义是否鼠标离开字段,默认为true, tray是托盘
tray.on('mouse-move', () => { if (isLeave) { //触发mouse-enter isLeave = false; checkTrayLeave();//检查是否离开 testmenu.popup();//打开 } })
3.检查方法
//检查是否离开 function checkTrayLeave(){ clearInterval(leaveInter) leaveInter = setInterval(function(){ trayBounds = tray.getBounds(); point = screen.getCursorScreenPoint(); if(!(trayBounds.x < point.x && trayBounds.y < point.y && point.x < (trayBounds.x + trayBounds.width) && point.y < (trayBounds.y + trayBounds.height))){//触发mouse-leave clearInterval(leaveInter); isLeave = true; testmenu.closePopup(); } }, 100) }
标签:菜单,鼠标,自定义,point,trayBounds,label,electron,isLeave From: https://www.cnblogs.com/zhangyouwu/p/17349504.html