mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
added libnotify node
This commit is contained in:
parent
508ad7c3af
commit
d7d305ff60
59
io/libnotify/42-libnotify.html
Normal file
59
io/libnotify/42-libnotify.html
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<!--
|
||||||
|
Copyright 2013 IBM Corp.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<script type="text/x-red" data-template-name="libnotify">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-title"><i class="icon-tag"></i> Title</label>
|
||||||
|
<input type="text" id="node-input-title" placeholder="Title">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-maxlength"><i class="icon-tag"></i> Maximum Length</label>
|
||||||
|
<input type="text" id="node-input-maxlength" placeholder="Maximum Length">
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/x-red" data-help-name="libnotify">
|
||||||
|
<p>Incomming data gets forwarded to your libnotify-compatible desktop notification service.</p>
|
||||||
|
<p>Messages longer than maxlength get truncated.</p>
|
||||||
|
<p>See the <a href="https://github.com/mytrile/node-libnotify">libnotify node module</a> and <a href="https://wiki.archlinux.org/index.php/Desktop_Notifications">this wiki</a> for more information.</p>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
RED.nodes.registerType('libnotify',{
|
||||||
|
category: 'output',
|
||||||
|
defaults: {
|
||||||
|
name: {value:"Desktop Notification"},
|
||||||
|
maxlength: {value:"200"},
|
||||||
|
title: {value:"RED"},
|
||||||
|
active: {value:true}
|
||||||
|
},
|
||||||
|
label: function() {
|
||||||
|
return this.name || "Desktop Notificaton";
|
||||||
|
},
|
||||||
|
labelStyle: function() {
|
||||||
|
return this.name?"node_label_italic":"";
|
||||||
|
},
|
||||||
|
color:"#BDFF59",
|
||||||
|
inputs:1,
|
||||||
|
outputs:0,
|
||||||
|
icon: "debug.png",
|
||||||
|
align: "right"
|
||||||
|
});
|
||||||
|
</script>
|
57
io/libnotify/42-libnotify.js
Normal file
57
io/libnotify/42-libnotify.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
**/
|
||||||
|
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||||
|
var ln = require('libnotify');
|
||||||
|
var util = require("util");
|
||||||
|
var events = require("events");
|
||||||
|
|
||||||
|
function LibnotifyNode(n) {
|
||||||
|
RED.nodes.createNode(this, n);
|
||||||
|
this.name = n.name;
|
||||||
|
this.title = n.title;
|
||||||
|
this.active = (n.active == null)||n.active;
|
||||||
|
this.maxlength = parseInt(n.maxlength) || 200;
|
||||||
|
|
||||||
|
this.on("input",function(msg) {
|
||||||
|
if (this.active) {
|
||||||
|
if (msg.payload instanceof Buffer) {
|
||||||
|
msg.payload = "(Buffer) "+msg.payload.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof msg.payload !== "undefined") {
|
||||||
|
LibnotifyNode.send(this, msg.payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
RED.nodes.registerType("libnotify",LibnotifyNode);
|
||||||
|
|
||||||
|
LibnotifyNode.send = function(self, msg) {
|
||||||
|
var title = self.title;
|
||||||
|
if (msg instanceof Error) {
|
||||||
|
title += " [ERROR]: ";
|
||||||
|
} else if (typeof msg === 'object') {
|
||||||
|
title += " [OBJECT]: ";
|
||||||
|
}
|
||||||
|
msg = msg.toString();
|
||||||
|
|
||||||
|
if (msg.length > self.maxlength) {
|
||||||
|
msg = msg.substr(0,self.maxlength) +"...";
|
||||||
|
}
|
||||||
|
|
||||||
|
ln.notify(msg, { title: title });
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user