const electron = require('electron');
const app = electron.app;
const Menu = electron.Menu;
const Tray = electron.Tray;
var appIcon = null;
app.on('ready', function(){
appIcon = new Tray('/path/to/my/icon');
var contextMenu = Menu.buildFromTemplate([
{ label: 'Item1', type: 'radio' },
{ label: 'Item2', type: 'radio' },
{ label: 'Item3', type: 'radio', checked: true },
{ label: 'Item4', type: 'radio' }
]);
appIcon.setToolTip('This is my application.');
appIcon.setContextMenu(contextMenu);
});
- 在 Linux, 如果支持应用指示器则使用它,否则使用
GtkStatusIcon
代替. - 在 Linux ,配置了只有有了应用指示器的支持, 你必须安装
libappindicator1
来让 tray icon 执行. - 应用指示器只有在它拥有 context menu 时才会显示.
- 当在linux 上使用了应用指示器,将忽略点击事件.
- 在 Linux,为了让单独的
MenuItem
起效,需要再次调用 setContextMenu
.例如:
contextMenu.items[2].checked = false;
appIcon.setContextMenu(contextMenu);
Class: Tray
new Tray(image)
事件
Event: 'click'
event
EventaltKey
BooleanshiftKey
BooleanctrlKey
BooleanmetaKey
Boolean
bounds
Object - tray icon 的 bounds.x
Integery
Integerwidth
Integerheight
Integer
Event: 'right-click' OS X Windows
event
EventaltKey
BooleanshiftKey
BooleanctrlKey
BooleanmetaKey
Boolean
bounds
Object - tray icon 的 bounds.x
Integery
Integerwidth
Integerheight
Integer
Event: 'double-click' OS X Windows
event
EventaltKey
BooleanshiftKey
BooleanctrlKey
BooleanmetaKey
Boolean
bounds
Object - tray icon 的 bounds.x
Integery
Integerwidth
Integerheight
Integer
Event: 'balloon-show' Windows
Event: 'balloon-click' Windows
Event: 'balloon-closed' Windows
Event: 'drop' OS X
Event: 'drop-files' OS X
event
files
Array - 已删除文件的路径.
Event: 'drag-enter' OS X
Event: 'drag-leave' OS X
Event: 'drag-end' OS X
方法
Tray.destroy()
请发表评论