mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
moved to growl
This commit is contained in:
parent
292a54e045
commit
c46e3dd0f2
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="libnotify">
|
||||
<script type="text/x-red" data-template-name="desktopnotify">
|
||||
<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">
|
||||
@ -29,14 +29,14 @@
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="libnotify">
|
||||
<p>Incomming data gets forwarded to your libnotify-compatible desktop notification service.</p>
|
||||
<script type="text/x-red" data-help-name="desktopnotify">
|
||||
<p>Incomming data gets forwarded to your desktopnotify-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>
|
||||
<p>See the <a href="https://github.com/mytrile/node-desktopnotify">desktopnotify 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',{
|
||||
RED.nodes.registerType('desktopnotify',{
|
||||
category: 'output',
|
||||
defaults: {
|
||||
name: {value:"Desktop Notification"},
|
59
io/desktopnotify/42-desktopnotify.js
Normal file
59
io/desktopnotify/42-desktopnotify.js
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.
|
||||
**/
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
var growl = require('growl');
|
||||
var util = require("util");
|
||||
var events = require("events");
|
||||
|
||||
function DesktopNotifyNode(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") {
|
||||
DesktopNotifyNode.send(this, msg.payload);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("desktopnotify",DesktopNotifyNode);
|
||||
|
||||
DesktopNotifyNode.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) +"...";
|
||||
}
|
||||
|
||||
growl(msg, { title: title });
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/**
|
||||
* 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