最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

electron notification 通知的使用

业界 admin 4浏览 0评论

electron notification 通知的使用

electron 的 notification 是走的系统通知通道,Windows上表现为从右边弹出的通知,macOS 为从右上角弹出的通知

一、导入 Notification

const {Notification} = require('electron')

二、新建一个 Notification 实例

在使用通知之前,先要确认系统是否支持 notification,使用 Notification 静态方法 .isSupported() 来获取是否可用

然后新建一个 Notification 实例,传递一个配置对象,具体的配置项目看官方文档:
https://www.electronjs/docs/latest/api/notification#event-show

我们主要用的就是

  • title 通知标题
  • subtitle 副标题 macOS
  • body: 通知内容

最后用当前实例 .show() 显示就好了。

 // notification
 if (Notification.isSupported()){
     console.log('notification is suppoerted')
     new Notification({
         title: '已成功导出文件',
         subtitle: `文件路径:${exportFilePath}`, // macOS
         body: `文件路径:${exportFilePath}`
     }).show()
 }

windows 上的效果就是这样

electron notification 通知的使用

electron 的 notification 是走的系统通知通道,Windows上表现为从右边弹出的通知,macOS 为从右上角弹出的通知

一、导入 Notification

const {Notification} = require('electron')

二、新建一个 Notification 实例

在使用通知之前,先要确认系统是否支持 notification,使用 Notification 静态方法 .isSupported() 来获取是否可用

然后新建一个 Notification 实例,传递一个配置对象,具体的配置项目看官方文档:
https://www.electronjs/docs/latest/api/notification#event-show

我们主要用的就是

  • title 通知标题
  • subtitle 副标题 macOS
  • body: 通知内容

最后用当前实例 .show() 显示就好了。

 // notification
 if (Notification.isSupported()){
     console.log('notification is suppoerted')
     new Notification({
         title: '已成功导出文件',
         subtitle: `文件路径:${exportFilePath}`, // macOS
         body: `文件路径:${exportFilePath}`
     }).show()
 }

windows 上的效果就是这样

发布评论

评论列表 (0)

  1. 暂无评论