We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
窗口最小化或者关闭的情况下,进程未退出,需要通过系统托盘来查看,当然还需要托盘菜单。这里就用最简单的菜单实现,加上点击事件触发。
const { app, Menu, Tray } = require('electron') let tray = null app.whenReady().then(() => { tray = new Tray('/path/to/my/icon') 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) })
let tray = null; app.whenReady().then(() => { const iconUrl = process.env.NODE_ENV === "development" ? path.join(__dirname, "../build/favicon.ico") : path.join(__dirname, "favicon.ico"); tray = new Tray(nativeImage.createFromPath(iconUrl)); let trayMenuTemplate = [ { label: "显示/隐藏", click: function() { return win.isVisible() ? win.hide() : win.show(); } }, { label: "退出", click: function() { app.quit(); } } ]; const contextMenu = Menu.buildFromTemplate(trayMenuTemplate); tray.setToolTip("kuari"); tray.setContextMenu(contextMenu); });
The text was updated successfully, but these errors were encountered:
No branches or pull requests
简述
窗口最小化或者关闭的情况下,进程未退出,需要通过系统托盘来查看,当然还需要托盘菜单。这里就用最简单的菜单实现,加上点击事件触发。
官方文档
实现
参考文档
The text was updated successfully, but these errors were encountered: