始终显示托盘图标

我正在使用Electron编写OSX应用程序,主要关注托盘。 基本上,它只显示当前应用程序正在使用,我怎么能设置它,使其独立于窗口?

你可以在主进程中创build你的托盘,不要创build一个窗口。

const {app, Menu, Tray} = require('electron') let tray = null app.on('ready', () => { 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) })