update notify package to use a more cross platform library

This commit is contained in:
Dave Conway-Jones
2018-09-10 11:37:20 -04:00
parent 949bbe95cd
commit 8acc5064d0
4 changed files with 29 additions and 19 deletions

View File

@@ -1,26 +1,35 @@
module.exports = function(RED) {
"use strict";
var growl = require('growl');
var imagefile = process.env.NODE_RED_HOME+"/public/node-red.png";
var notifier = require('node-notifier');
var path = require('path');
var fs = require('fs');
var image = path.join(__dirname, "/node-red.png");
function NotifyNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var node = this;
node.on("input",function(msg) {
var titl = node.title || msg.topic;
if (typeof(msg.payload) == 'object') {
var title = node.title || msg.topic;
if (typeof msg.payload === 'object') {
msg.payload = JSON.stringify(msg.payload);
}
if (typeof(titl) != 'undefined') {
growl(msg.payload, { title: titl, image: imagefile });
var icon = image;
if (msg.icon) {
if (fs.existsSync(msg.icon)) { icon = msg.icon; }
else { node.error("Bad Icon file: "+msg.icon,msg); }
}
var icon = msg.icon || image;
if (typeof(title) !== 'undefined') {
notifier.notify({ message:msg.payload, title:title, icon:icon });
}
else {
growl(msg.payload, { image: imagefile });
notifier.notify({ message:msg.payload, icon:imagefile });
}
});
}
RED.nodes.registerType("notify",NotifyNode);
RED.nodes.registerType("nnotify",NotifyNode);
}