如何以电子方式发送通知?

Jam*_*ery 3 node.js electron

将electron/node.js用于桌面应用程序.试图弄清楚如何在桌面上生成通知.它是否内置于电子API中?

Ily*_*rim 8

node-notifier更容易发送本机通知.节点通知器Node.js模块,用于在本机Mac,Windows和Linux上发送通知(或作为后备的Growl).

Github上

安装:

npm install --save node-notifier
Run Code Online (Sandbox Code Playgroud)

例:

const notifier = require('node-notifier');
// String
notifier.notify('Message');

// Object
notifier.notify({
  title: 'My notification',
  message: 'Hello, there!'
});
Run Code Online (Sandbox Code Playgroud)

通知:

在此输入图像描述

  • 从来没有做过这样的任务。但这是可能的。@拉胡尔马特 (3认同)

Rus*_*ust 4

Electron 允许开发人员使用 HTML5 通知 API 推送通知。

例子:

let myNotification = new Notification('Foo', {
  body: 'Lorem Ipsum Dolor Sit Amet'
})

myNotification.onclick = () => {
  console.log('Notification clicked')
}
Run Code Online (Sandbox Code Playgroud)

由于 Windows 7 不支持通知,因此请查看托盘对象文档。

您可以在这里找到更多相关信息

还:

看一下node-notifier插件,它更容易使用,而且是跨平台的。