×

Electron 教程

Electron 教程简介Electron 快速入门Electron 桌面环境集成Electron 在线/离线事件探测Electron 进程支持的 Chrome 命令行开关Electron 环境变量Electron 支持的平台Electron 应用部署Mac App Store 应用提交向导Electron 应用打包Electron 使用原生模块Electron 主进程调试使用 Selenium 和 WebDriverElectron DevTools扩展使用 Pepper Flash 插件使用 Widevine CDM 插件Electron 术语表Electron 离屏渲染Electron 交互式解释器 (REPL)Electron 自动更新功能autoUpdater

Electron API

Electron DOM File对象Electron DOM <webview>Electron window.open 函数

在主进程内可用的模块

Electron app 模块Electron autoUpdater 模块Electron BrowserWindow 模块Electron contentTracing 模块Electron dialog 模块Electron global-shortcut 模块Electron ipcMain 模块Electron menu 模块Electron MenuItem 模块Electron powerMonitor 模块Electron powerSaveBlockerElectron protocol 模块Electron session 模块Electron webContents 模块Electron Tray 模块Electron Locales

在渲染进程(网页)可用模块

Electron desktopCapturer模块Electron ipcRenderer 模块Electron remote 模块Electron webFrame 模块

两种进程都可用的模块

Electron clipboard 模块Electron crashReporter 模块Electron nativeImage 模块Electron screen 模块Electron shell 模块

Electron 开发

Electron 编码规范Electron 源码目录结构Electron 和 NW.js技术上的差异Electron 构建系统概览Electron 构建步骤 (OS X)Electron 构建步骤 (Windows)Electron 构建步骤 (Linux)调试中使用 Symbol ServerElectron 常见问题Electron 版本管理electron window 提交指南自动化持续集成系统(CI)测试Electron 文档风格指南

Electron Tray 模块


用一个 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()

立刻删除 tray icon.

Tray.setImage(image)

 image 与 tray icon 关联起来.

Tray.setPressedImage(image) OS X

当在 OS X 上按压 tray icon 的时候, 让 image 与 tray icon 关联起来.

Tray.setToolTip(toolTip)

  • toolTip String

为 tray icon 设置 hover text.

Tray.setTitle(title) OS X

  • title String

在状态栏沿着 tray icon 设置标题.

Tray.setHighlightMode(highlight) OS X

  • highlight Boolean

当 tray icon 被点击的时候,是否设置它的背景色变为高亮(blue).默认为 true.

Tray.displayBalloon(options) Windows

  • options Object

展示一个 tray balloon.

Tray.popUpContextMenu([menu, position]) OS X Windows

  • menu Menu (optional)
  • position Object (可选) - 上托位置.
    • x Integer
    • y Integer

从 tray icon 上托出 context menu . 当划过 menu 的时候, menu 显示,代替 tray 的 context menu .

position 只在 windows 上可用,默认为 (0, 0) .

Tray.setContextMenu(menu)

  • menu Menu

为这个 icon 设置 context menu .


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)