托盘
import { Tray, Menu } from 'electron'
let iconTray = null // 要创建全局的变量,不然会几秒后消失
创建托盘函数
async function createTray() {
const trayMenuItem = [{ // 右击显示的菜单
label: '最小化',
click: function () {
mainWindow.minimize()
}
},
{
label: '退出',
click: function () {
mainWindow.destroy();
app.quit()
}
}]
iconTray = new Tray(path.join(__static, '/favicon.ico'));// 托盘的图标
iconTray.setToolTip('测试');// 托盘的名字
const trayMenu = Menu.buildFromTemplate(trayMenuItem)
iconTray.setContextMenu(trayMenu);
iconTray.on('click', () => { // 点击托盘执行的事件
mainWindow.show()
})
}
标签:function,创建,托盘,mainWindow,electron,iconTray,click
From: https://www.cnblogs.com/lixiaotian/p/16969264.html