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

问题描述 投票:3回答:2

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

node.js electron
2个回答
3
投票

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

例:

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

myNotification.onclick = () => {
  console.log('Notification clicked')
}

由于Windows 7不支持通知,请查看tray对象文档。

你可以找到更多关于这个here的信息

也:

看看node-notifier插件,它更易于使用,也是跨平台的。


7
投票

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

Github

Install:

npm install --save node-notifier

Example:

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

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

Notification:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.