TIM截图20191017150511.png
设置窗口图标,在窗口初始时加入icon参数即可
win = new BrowserWindow({
icon: './src/img/icon.png',
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
系统托盘图标与菜单
const { app, BrowserWindow, Menu, shell, ipcMain, Tray } = require('electron')
//创建任务栏图标、菜单
const tray = new Tray('./src/img/icon.png');
const trayContextMenu = Menu.buildFromTemplate([
{
label: '打开',
click: () => {
win.show();
}
}, {
label: '退出',
click: () => {
app.quit();
}
}
]);
tray.setToolTip('myApp');
tray.on('click', () => {
win.show();
});
tray.on('right-click', () => {
tray.popUpContextMenu(trayContextMenu);
});