在main.js里面
①导入Tray
const { app, BrowserWindow, Menu, MenuItem, Tray } = require('electron')
②封装系统托盘函数(png是托盘图标)
// 系统托盘
function tray() {
tray = new Tray('./car.png')
const contextMenu = Menu.buildFromTemplate([
{
role: 'minimize',
label: '最小化',
click: () => {
mainWindow.minimize()
}
}, {
role: 'togglefullscreen',
label: '全屏',
click: () => {
mainWindow.setFullScreen(mainWindow.isFullScreen() !== true);
}
}, {
label: '退出',
role: 'quit',
click: () => {
app.quit()
}
},
])
tray.setToolTip(app.name)
// tray.setContextMenu(contextMenu)
tray.on('right-click', () => {
tray.popUpContextMenu(contextMenu)
})
tray.on('