非常教程

Electron参考手册

通知 | Notification

通知 | Notification

创建 OS 桌面通知

Process: Main

在渲染器进程中使用

如果您想要显示来自渲染器进程的通知,则应使用HTML5通知API

Class: Notification

创建 OS 桌面通知

Process: Main

Notification是一个 EventEmitter。

它创建一个新的Notification具有原生属性的设置options

Static Methods

Notification班有下列静态方法:

Notification.isSupported()

返回Boolean- 当前系统是否支持桌面通知

new Notification([options]) Experimental

  • options 目的
    • title 字符串 - 通知的标题,当通知窗口显示时,它将显示在通知窗口的顶部
    • subtitle字符串 - (可选)通知的副标题,将显示在标题下方。苹果系统
    • body 字符串 - 通知的正文文本,将显示在标题或副标题下方
    • silent 布尔值 - (可选)显示通知时是否发出操作系统通知噪音
    • icon NativeImage - (可选)通知中使用的图标
    • hasReply布尔值 - (可选)是否向通知添加内联回复选项。苹果系统
    • replyPlaceholder字符串 - (可选)要在联机回复输入字段中写入的占位符。苹果系统
    • sound字符串 - (可选)显示通知时播放的声音文件的名称。苹果系统
    • actionsNotificationAction [] - (可选)添加到通知的操作。请阅读NotificationAction文档macOS中的可用操作和限制

Instance Events

创建的对象new Notification会发出以下事件:

注意:某些事件仅在特定的操作系统上可用,并且被标记为这样。

Event: ‘show’

返回:

  • event Event

当通知显示给用户时发出,注意这可能会被多次触发,因为可以通过该show()方法多次显示通知。

Event: ‘click’

返回:

  • event Event

当用户点击通知时发出。

Event: ‘close’

返回:

  • event Event

当通过用户的手动干预关闭通知时发出。

在通知结束的所有情况下,此事件不能保证排除。

Event: ‘reply’ macOS

返回:

  • event 事件
  • reply 字符串 - 用户在内嵌回复字段中输入的字符串

当用户点击通知时的“回复”按钮时发出hasReply: true

Event: ‘action’ macOS

返回:

  • event 事件
  • index Number - 已激活的操作的索引

Instance Methods

创建的对象new Notification具有以下实例方法:

notification.show()

立即向用户显示通知,请注意这与HTML5 Notification实现不同,只是实例化new Notification并不立即向用户显示,您需要在OS显示之前调用此方法。

Playing Sounds

在macOS上,您可以指定显示通知时要播放的声音的名称。除了自定义声音文件之外,还可以使用任何默认声音(在系统偏好设置>声音下)。确保声音文件在应用程序包(例如,YourApp.app/Contents/Resources)或以下位置之一下复制:

  • ~/Library/Sounds
  • /Library/Sounds
  • /Network/Library/Sounds
  • /System/Library/Sounds

通知 | Notification相关

Electron

Electron 是一个使用 JavaScript, HTML 和 CSS 等 Web 技术创建原生程序的框架,它负责比较难搞的部分,你只需把精力放在你的应用的核心上即可。

主页 https://electron.atom.io/
源码 https://github.com/electron/electron
发布版本 1.7.9

Electron目录

1.指南 | Guides
2.指南·开发 | Guides: Development
3.Webview 组件 |
4.加速器 | Accelerator
5.API
6.API·对象 | API·Objects
7.app
8.autoUpdater
9.浏览器总览 | BrowserView
10.浏览器窗口 | BrowserWindow
11.浏览器窗口代理 | BrowserWindowProxy)
12.ClientRequest
13.剪贴板 | clipboard
14.内容追踪 | contentTracing
15.小型文字档案 | Cookies
16.crashReporter
17.调试器 | Debugger
18.desktopCapturer
19.dialog
20.电子下载 | DownloadItem
21.环境变量 | Environment Variables
22.无框窗口 | Frameless Window
23.globalShortcut
24.IncomingMessage
25.ipcMain
26.IPC渲染器 | ipcRenderer
27.语言环境 | Locales
28.画面 | Menu
29.MenuItem
30.本地图像 | nativeImage
31.net
32.通知 | Notification
33.权限监控 | powerMonitor
34.权限存储拦截器 | powerSaveBlocker
35.处理 | process
36.协议 | protocol
37.远程 | remote
38.sandbox
39.屏幕 | screen
40.会话 | session
41.shell
42.系统表现 | systemPreferences
43.触摸板 | TouchBar
44.触摸板按钮 | TouchBarButton
45.触摸板颜色选择器 | TouchBarColorPicker
46.触摸板组 | TouchBarGroup
47.触摸板标签 | TouchBarLabel
48.触摸板弹出框 | TouchBarPopover
49.触摸板清理 | TouchBarScrubber
50.触摸板分段控制 | TouchBarSegmentedControl
51.触摸板滑块 | TouchBarSlider
52.触摸板间隔 | TouchBarSpacer
53.Tray
54.网页内容 | webContents
55.网页框架 | webFrame
56.网页要求 | WebRequest
57.窗口开启 | window.open