我正在使用 Electron 编写一个 OSX 应用程序, 它主要集中在托盘上。基本上,它只显示应用程序当前正在使用的时间,我如何设置它以使其独立于窗口?
最佳答案
您可以只在主进程中创建托盘,而不创建窗口。
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)
})
关于javascript - [Electron][OSX] 始终显示托盘图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39430208/