Comparing version 1.3.0 to 1.4.0
1.4.0 / 2011-12-17 | ||
================== | ||
* Changed API: `growl.notify()` -> `growl()` | ||
1.3.0 / 2011-12-17 | ||
@@ -3,0 +8,0 @@ ================== |
121
lib/growl.js
@@ -59,21 +59,12 @@ | ||
/** | ||
* Node-growl version. | ||
* Expose `growl`. | ||
*/ | ||
exports.version = '1.3.0' | ||
exports = module.exports = growl; | ||
/** | ||
* Fetch the binary version when available. | ||
* | ||
* @param {function} fn | ||
* @api public | ||
* Node-growl version. | ||
*/ | ||
exports.binVersion = function(fn) { | ||
exec(cmd.pkg + ' -v', function(err, stdout) { | ||
if (err) return fn(err); | ||
var version = /(\d+\.\d+(?:\.\d+)?)/.exec(stdout)[1]; | ||
fn(null, parseFloat(version)); | ||
}); | ||
}; | ||
exports.version = '1.4.0' | ||
@@ -98,5 +89,5 @@ /** | ||
* | ||
* growl.notify('New email') | ||
* growl.notify('5 new emails', { title: 'Thunderbird' }) | ||
* growl.notify('Email sent', function(){ | ||
* growl('New email') | ||
* growl('5 new emails', { title: 'Thunderbird' }) | ||
* growl('Email sent', function(){ | ||
* // ... notification sent | ||
@@ -111,3 +102,3 @@ * }) | ||
exports.notify = function(msg, options, fn) { | ||
function growl(msg, options, fn) { | ||
var image | ||
@@ -118,60 +109,56 @@ , args = [cmd.pkg] | ||
exports.binVersion(function(err, version){ | ||
if (err) return fn(err); | ||
// image | ||
if (image = options.image) { | ||
switch(cmd.type) { | ||
case 'Darwin': | ||
var flag, ext = path.extname(image).substr(1) | ||
flag = flag || ext == 'icns' && 'iconpath' | ||
flag = flag || /^[A-Z]/.test(image) && 'appIcon' | ||
flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image' | ||
flag = flag || ext && (image = ext) && 'icon' | ||
flag = flag || 'icon' | ||
args.push('--' + flag, image) | ||
break; | ||
case 'Linux': | ||
args.push('-i ' + image); | ||
break; | ||
} | ||
// image | ||
if (image = options.image) { | ||
switch(cmd.type) { | ||
case 'Darwin': | ||
var flag, ext = path.extname(image).substr(1) | ||
flag = flag || ext == 'icns' && 'iconpath' | ||
flag = flag || /^[A-Z]/.test(image) && 'appIcon' | ||
flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image' | ||
flag = flag || ext && (image = ext) && 'icon' | ||
flag = flag || 'icon' | ||
args.push('--' + flag, image) | ||
break; | ||
case 'Linux': | ||
args.push('-i ' + image); | ||
break; | ||
} | ||
} | ||
// sticky | ||
if (options.sticky) args.push(cmd.sticky); | ||
// sticky | ||
if (options.sticky) args.push(cmd.sticky); | ||
// priority | ||
if (options.priority) { | ||
var priority = options.priority + ''; | ||
var checkindexOf = cmd.priority.range.indexOf(priority); | ||
if (~cmd.priority.range.indexOf(priority)) { | ||
args.push(cmd.priority, options.priority); | ||
} | ||
// priority | ||
if (options.priority) { | ||
var priority = options.priority + ''; | ||
var checkindexOf = cmd.priority.range.indexOf(priority); | ||
if (~cmd.priority.range.indexOf(priority)) { | ||
args.push(cmd.priority, options.priority); | ||
} | ||
} | ||
// name | ||
if (options.name && cmd.type === "Darwin") { | ||
args.push('--name', options.name); | ||
} | ||
// name | ||
if (options.name && cmd.type === "Darwin") { | ||
args.push('--name', options.name); | ||
} | ||
switch(cmd.type) { | ||
case 'Darwin': | ||
switch(cmd.type) { | ||
case 'Darwin': | ||
args.push(cmd.msg); | ||
args.push('"' + msg + '"'); | ||
if (options.title) args.push(options.title); | ||
break; | ||
case 'Linux': | ||
if (options.title) { | ||
args.push("'" + options.title + "'"); | ||
args.push(cmd.msg); | ||
args.push('"' + msg + '"'); | ||
if (options.title) args.push(options.title); | ||
break; | ||
case 'Linux': | ||
if (options.title) { | ||
args.push("'" + options.title + "'"); | ||
args.push(cmd.msg); | ||
args.push("'" + msg + "'"); | ||
} else { | ||
args.push("'" + msg + "'"); | ||
} | ||
break; | ||
} | ||
args.push("'" + msg + "'"); | ||
} else { | ||
args.push("'" + msg + "'"); | ||
} | ||
break; | ||
} | ||
// execute | ||
exec(args.join(' '), fn); | ||
}); | ||
// execute | ||
exec(args.join(' '), fn); | ||
}; |
{ "name": "growl", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Growl unobtrusive notifications", | ||
@@ -4,0 +4,0 @@ "author": "TJ Holowaychuk <tj@vision-media.ca>", |
@@ -28,13 +28,13 @@ # Growl for nodejs | ||
var growl = require('growl') | ||
growl.notify('You have mail!') | ||
growl.notify('5 new messages', { sticky: true }) | ||
growl.notify('5 new emails', { title: 'Email Client', image: 'Safari', sticky: true }) | ||
growl.notify('Message with title', { title: 'Title'}) | ||
growl.notify('Set priority', { priority: 2 }) | ||
growl.notify('Show Safari icon', { image: 'Safari' }) | ||
growl.notify('Show icon', { image: 'path/to/icon.icns' }) | ||
growl.notify('Show image', { image: 'path/to/my.image.png' }) | ||
growl.notify('Show png filesystem icon', { image: 'png' }) | ||
growl.notify('Show pdf filesystem icon', { image: 'article.pdf' }) | ||
growl.notify('Show pdf filesystem icon', { image: 'article.pdf' }, function(){ | ||
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 | ||
@@ -61,7 +61,2 @@ }) | ||
Fetch the current version of 'growlnotify': | ||
growl.binVersion(function(err, version){ ... }) | ||
// => 'n.n.n' | ||
## License | ||
@@ -68,0 +63,0 @@ |
22
test.js
var growl = require('./lib/growl') | ||
growl.notify('You have mail!') | ||
growl.notify('5 new messages', { sticky: true }) | ||
growl.notify('5 new emails', { title: 'Email Client', image: 'Safari', sticky: true }) | ||
growl.notify('Message with title', { title: 'Title'}) | ||
growl.notify('Set priority', { priority: 2 }) | ||
growl.notify('Show Safari icon', { image: 'Safari' }) | ||
growl.notify('Show icon', { image: 'path/to/icon.icns' }) | ||
growl.notify('Show image', { image: 'path/to/my.image.png' }) | ||
growl.notify('Show png filesystem icon', { image: 'png' }) | ||
growl.notify('Show pdf filesystem icon', { image: 'article.pdf' }) | ||
growl.notify('Show pdf filesystem icon', { image: 'article.pdf' }, function(){ | ||
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(){ | ||
console.log('callback'); | ||
}) |
7723
158
84