Comparing version 1.8.1 to 1.9.0
102
lib/growl.js
@@ -18,3 +18,3 @@ // Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed) | ||
var loc; | ||
for (var i = 0, len = paths.length; i < len; ++i) { | ||
@@ -35,2 +35,5 @@ loc = path.join(paths[i], name); | ||
, subtitle: '-subtitle' | ||
, icon: '-appIcon' | ||
, sound: '-sound' | ||
, url: '-open' | ||
, priority: { | ||
@@ -66,17 +69,31 @@ cmd: '-execute' | ||
case 'Linux': | ||
cmd = { | ||
type: "Linux" | ||
, pkg: "notify-send" | ||
, msg: '' | ||
, sticky: '-t 0' | ||
, icon: '-i' | ||
, priority: { | ||
cmd: '-u' | ||
, range: [ | ||
"low" | ||
, "normal" | ||
, "critical" | ||
] | ||
} | ||
}; | ||
if (which('growl')) { | ||
cmd = { | ||
type: "Linux-Growl" | ||
, pkg: "growl" | ||
, msg: '-m' | ||
, title: '-title' | ||
, subtitle: '-subtitle' | ||
, host: { | ||
cmd: '-H' | ||
, hostname: '192.168.33.1' | ||
} | ||
}; | ||
} else { | ||
cmd = { | ||
type: "Linux" | ||
, pkg: "notify-send" | ||
, msg: '' | ||
, sticky: '-t 0' | ||
, icon: '-i' | ||
, priority: { | ||
cmd: '-u' | ||
, range: [ | ||
"low" | ||
, "normal" | ||
, "critical" | ||
] | ||
} | ||
}; | ||
} | ||
break; | ||
@@ -91,2 +108,3 @@ case 'Windows_NT': | ||
, icon: '/i:' | ||
, url: '/cu:' | ||
, priority: { | ||
@@ -127,2 +145,3 @@ cmd: '/p:' | ||
* - name Application name (defaults to growlnotify) | ||
* - sound Sound efect ( in OSx defined in preferences -> sound -> effects) * works only in OSX > 10.8x | ||
* - image | ||
@@ -139,2 +158,3 @@ * - path to an icon sets --iconpath | ||
* growl('5 new emails', { title: 'Thunderbird' }) | ||
* growl('5 new emails', { title: 'Thunderbird', sound: 'Purr' }) | ||
* growl('Email sent', function(){ | ||
@@ -156,2 +176,10 @@ * // ... notification sent | ||
if (options.exec) { | ||
cmd = { | ||
type: "Custom" | ||
, pkg: options.exec | ||
, range: [] | ||
}; | ||
} | ||
// noop | ||
@@ -173,2 +201,5 @@ if (!cmd) return fn(new Error('growl not supported on this platform')); | ||
break; | ||
case 'Darwin-NotificationCenter': | ||
args.push(cmd.icon, quote(image)); | ||
break; | ||
case 'Linux': | ||
@@ -197,2 +228,7 @@ args.push(cmd.icon, quote(image)); | ||
//sound | ||
if(options.sound && cmd.type === 'Darwin-NotificationCenter'){ | ||
args.push(cmd.sound, options.sound) | ||
} | ||
// name | ||
@@ -206,3 +242,3 @@ if (options.name && cmd.type === "Darwin-Growl") { | ||
args.push(cmd.msg); | ||
args.push(quote(msg)); | ||
args.push(quote(msg).replace(/\\n/g, '\n')); | ||
if (options.title) args.push(quote(options.title)); | ||
@@ -212,3 +248,5 @@ break; | ||
args.push(cmd.msg); | ||
args.push(quote(msg)); | ||
var stringifiedMsg = quote(msg); | ||
var escapedMsg = stringifiedMsg.replace(/\\n/g, '\n'); | ||
args.push(escapedMsg); | ||
if (options.title) { | ||
@@ -222,7 +260,14 @@ args.push(cmd.title); | ||
} | ||
if (options.url) { | ||
args.push(cmd.url); | ||
args.push(quote(options.url)); | ||
} | ||
break; | ||
case 'Darwin-Growl': | ||
case 'Linux-Growl': | ||
args.push(cmd.msg); | ||
args.push(quote(msg)); | ||
args.push(quote(msg).replace(/\\n/g, '\n')); | ||
if (options.title) args.push(quote(options.title)); | ||
if (cmd.host) { | ||
args.push(cmd.host.cmd, cmd.host.hostname) | ||
} | ||
break; | ||
@@ -233,11 +278,22 @@ case 'Linux': | ||
args.push(cmd.msg); | ||
args.push(quote(msg)); | ||
args.push(quote(msg).replace(/\\n/g, '\n')); | ||
} else { | ||
args.push(quote(msg)); | ||
args.push(quote(msg).replace(/\\n/g, '\n')); | ||
} | ||
break; | ||
case 'Windows': | ||
args.push(quote(msg)); | ||
args.push(quote(msg).replace(/\\n/g, '\n')); | ||
if (options.title) args.push(cmd.title + quote(options.title)); | ||
if (options.url) args.push(cmd.url + quote(options.url)); | ||
break; | ||
case 'Custom': | ||
args[0] = (function(origCommand) { | ||
var message = options.title | ||
? options.title + ': ' + msg | ||
: msg; | ||
var command = origCommand.replace(/(^|[^%])%s/g, '$1' + quote(message)); | ||
if (command === origCommand) args.push(quote(message)); | ||
return command; | ||
})(args[0]); | ||
break; | ||
} | ||
@@ -244,0 +300,0 @@ |
{ | ||
"name": "growl", | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"description": "Growl unobtrusive notifications", | ||
@@ -13,3 +13,4 @@ "author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
}, | ||
"main": "./lib/growl.js" | ||
"main": "./lib/growl.js", | ||
"license": "MIT" | ||
} |
# Growl for nodejs | ||
Growl support for Nodejs. This is essentially a port of my [Ruby Growl Library](http://github.com/visionmedia/growl). Ubuntu/Linux support added thanks to [@niftylettuce](http://github.com/niftylettuce). | ||
Growl support for Nodejs. This is essentially a port of my [Ruby Growl Library](http://github.com/visionmedia/growl). Ubuntu/Linux support added thanks to [@niftylettuce](http://github.com/niftylettuce). | ||
## Installation | ||
### Install | ||
### Install | ||
@@ -12,9 +12,9 @@ ### Mac OS X (Darwin): | ||
Install [growlnotify(1)](http://growl.info/extras.php#growlnotify). On OS X 10.8, Notification Center is supported using [terminal-notifier](https://github.com/alloy/terminal-notifier). To install: | ||
$ sudo gem install terminal-notifier | ||
$ sudo gem install terminal-notifier | ||
Install [npm](http://npmjs.org/) and run: | ||
$ npm install growl | ||
$ npm install growl | ||
### Ubuntu (Linux): | ||
@@ -24,8 +24,8 @@ | ||
$ sudo apt-get install libnotify-bin | ||
$ sudo apt-get install libnotify-bin | ||
Install [npm](http://npmjs.org/) and run: | ||
$ npm install growl | ||
$ npm install growl | ||
### Windows: | ||
@@ -38,5 +38,5 @@ | ||
Install [npm](http://npmjs.org/) and run: | ||
$ npm install growl | ||
$ npm install growl | ||
## Examples | ||
@@ -46,16 +46,18 @@ | ||
var growl = require('growl') | ||
growl('You have mail!') | ||
growl('5 new messages', { sticky: true }) | ||
growl('5 new emails', { title: 'Email Client', image: 'Safari', sticky: true }) | ||
growl('Message with title', { title: 'Title'}) | ||
growl('Set priority', { priority: 2 }) | ||
growl('Show Safari icon', { image: 'Safari' }) | ||
growl('Show icon', { image: 'path/to/icon.icns' }) | ||
growl('Show image', { image: 'path/to/my.image.png' }) | ||
growl('Show png filesystem icon', { image: 'png' }) | ||
growl('Show pdf filesystem icon', { image: 'article.pdf' }) | ||
growl('Show pdf filesystem icon', { image: 'article.pdf' }, function(err){ | ||
// ... notified | ||
}) | ||
```javascript | ||
var growl = require('growl') | ||
growl('You have mail!') | ||
growl('5 new messages', { sticky: true }) | ||
growl('5 new emails', { title: 'Email Client', image: 'Safari', sticky: true }) | ||
growl('Message with title', { title: 'Title'}) | ||
growl('Set priority', { priority: 2 }) | ||
growl('Show Safari icon', { image: 'Safari' }) | ||
growl('Show icon', { image: 'path/to/icon.icns' }) | ||
growl('Show image', { image: 'path/to/my.image.png' }) | ||
growl('Show png filesystem icon', { image: 'png' }) | ||
growl('Show pdf filesystem icon', { image: 'article.pdf' }) | ||
growl('Show pdf filesystem icon', { image: 'article.pdf' }, function(err){ | ||
// ... notified | ||
}) | ||
``` | ||
@@ -79,5 +81,11 @@ ## Options | ||
- otherwise treated as --icon | ||
## License | ||
- exec | ||
- manually specify a shell command instead | ||
- appends message to end of shell command | ||
- or, replaces `%s` with message | ||
- optionally prepends title (example: `title: message`) | ||
- examples: `{exec: 'tmux display-message'}`, `{exec: 'echo "%s" > messages.log}` | ||
## License | ||
(The MIT License) | ||
@@ -84,0 +92,0 @@ |
11
test.js
var growl = require('./lib/growl') | ||
growl('Support sound notifications', {title: 'Make a sound', sound: 'purr'}); | ||
growl('You have mail!') | ||
@@ -21,1 +22,11 @@ growl('5 new messages', { sticky: true }) | ||
}) | ||
growl('Allow custom notifiers', { exec: 'echo XXX %s' }, function(error, stdout, stderr) { | ||
console.log(stdout); | ||
}) | ||
growl('Allow custom notifiers', { title: 'test', exec: 'echo YYY' }, function(error, stdout, stderr) { | ||
console.log(stdout); | ||
}) | ||
growl('Allow custom notifiers', { title: 'test', exec: 'echo ZZZ %s' }, function(error, stdout, stderr) { | ||
console.log(stdout); | ||
}) | ||
growl('Open a URL', { url: 'https://npmjs.org/package/growl' }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
13693
0
299
108