• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Electron Tray 模块

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

用一个 Tray 来表示一个图标,这个图标处于正在运行的系统的通知区 ,通常被添加到一个 context menu 上.

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);

如果想在所有平台保持完全相同的行为,不应该依赖点击事件,而是一直将一个 context menu 添加到 tray icon.

Class: Tray

Tray 是一个 事件发出者.

new Tray(image)

创建一个与 image 相关的 icon.

事件

Tray 模块可发出下列事件:

注意: 一些事件只能在特定的os中运行,已经标明.

Event: 'click'

  • event Event
    • altKey Boolean
    • shiftKey Boolean
    • ctrlKey Boolean
    • metaKey Boolean
  • bounds Object - tray icon 的 bounds.
    • x Integer
    • y Integer
    • width Integer
    • height Integer

当tray icon被点击的时候发出事件.

注意: bounds 只在 OS X 和 Windows 上起效.

Event: 'right-click' OS X Windows

  • event Event
    • altKey Boolean
    • shiftKey Boolean
    • ctrlKey Boolean
    • metaKey Boolean
  • bounds Object - tray icon 的 bounds.
    • x Integer
    • y Integer
    • width Integer
    • height Integer

当tray icon被鼠标右键点击的时候发出事件.

Event: 'double-click' OS X Windows

  • event Event
    • altKey Boolean
    • shiftKey Boolean
    • ctrlKey Boolean
    • metaKey Boolean
  • bounds Object - tray icon 的 bounds.
    • x Integer
    • y Integer
    • width Integer
    • height Integer

当tray icon被双击的时候发出事件.

Event: 'balloon-show' Windows

当tray 气泡显示的时候发出事件.

Event: 'balloon-click' Windows

当tray 气泡被点击的时候发出事件.

Event: 'balloon-closed' Windows

当tray 气泡关闭的时候发出事件,因为超时或人为关闭.

Event: 'drop' OS X

当tray icon上的任何可拖动项被删除的时候发出事件.

Event: 'drop-files' OS X

  • event
  • files Array - 已删除文件的路径.

当tray icon上的可拖动文件被删除的时候发出事件.

Event: 'drag-enter' OS X

当一个拖动操作进入tray icon的时候发出事件.

Event: 'drag-leave' OS X

当一个拖动操作离开tray icon的时候发出事件. Emitted when a drag operation exits the tray icon.

Event: 'drag-end' OS X

当一个拖动操作在tray icon上或其它地方停止拖动的时候发出事件.

方法

Tray 模块有以下方法:

Note: 一些方法只能在特定的os中运行,已经标明.

Tray.destroy()


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Electron Locales发布时间:2022-02-03
下一篇:
Electron webContents 模块发布时间:2022-02-03
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap