[英]Electron (Windows) not showing the menu when tray icon is clicked
我想创建一个托盘应用程序,然后我尝试创建一个简单的图标,显示一个带有无线电输入的菜单,以测试电子托盘应用程序的确切文档示例如何显示。 但是当我点击图标时什么也没有发生。
const { app, Menu, Tray } = require('electron')
const { resolve } = require('path')
app.on('ready', () => {
createTray()
})
const createTray = () => {
const tray = new Tray(resolve(__dirname, 'assets', 'tray-icon.png'))
const contextMenu = Menu.buildFromTemplate([
{ label: 'Item1', type: 'radio' },
{ label: 'Item2', type: 'radio' },
{ label: 'Item3', type: 'radio', checked: true },
{ label: 'Item4', type: 'radio' }
])
tray.setToolTip('This is my application.')
tray.setContextMenu(contextMenu)
// using this to check if the click event is working
tray.on('click', () => {
console.log('clicked')
})
}
在 Windows 上,菜单通常通过右键单击托盘图标打开。
您还可以通过在您拥有的click
事件处理程序中使用tray.popUpContextMenu()
来触发它。
tray.on("click", ()=>{
tray.popUpContextMenu();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.