Permalink
Browse files

Add Notification Center support

  • Loading branch information...
1 parent 281aeb7 commit d9563bfb6f41d8f27f641573b62d8305c48d5188 @drudge drudge committed Sep 6, 2012
Showing with 63 additions and 27 deletions.
  1. +56 −24 lib/growl.js
  2. +7 −3 package.json
View
@@ -5,33 +5,48 @@
*/
var exec = require('child_process').exec
+ , execSync = require('execSync')
, path = require('path')
, os = require('os')
, cmd;
switch(os.type()) {
case 'Darwin':
- cmd = {
- type: "Darwin"
- , pkg: "growlnotify"
- , msg: '-m'
- , sticky: '--sticky'
- , priority: {
- cmd: '--priority'
- , range: [
- -2
- , -1
- , 0
- , 1
- , 2
- , "Very Low"
- , "Moderate"
- , "Normal"
- , "High"
- , "Emergency"
- ]
- }
- };
+ if (execSync.stdout('which terminal-notifier')) {
+ cmd = {
+ type: "Darwin-NotificationCenter"
+ , pkg: "terminal-notifier"
+ , msg: '-message'
+ , title: '-title'
+ , subtitle: '-subtitle'
+ , priority: {
+ cmd: '-execute'
+ , range: []
+ }
+ };
+ } else {
+ cmd = {
+ type: "Darwin-Growl"
+ , pkg: "growlnotify"
+ , msg: '-m'
+ , sticky: '--sticky'
+ , priority: {
+ cmd: '--priority'
+ , range: [
+ -2
+ , -1
+ , 0
+ , 1
+ , 2
+ , "Very Low"
+ , "Moderate"
+ , "Normal"
+ , "High"
+ , "Emergency"
+ ]
+ }
+ };
+ }
break;
case 'Linux':
cmd = {
@@ -127,7 +142,7 @@ function growl(msg, options, fn) {
// image
if (image = options.image) {
switch(cmd.type) {
- case 'Darwin':
+ case 'Darwin-Growl':
var flag, ext = path.extname(image).substr(1)
flag = flag || ext == 'icns' && 'iconpath'
flag = flag || /^[A-Z]/.test(image) && 'appIcon'
@@ -158,12 +173,29 @@ function growl(msg, options, fn) {
}
// name
- if (options.name && cmd.type === "Darwin") {
+ if (options.name && cmd.type === "Darwin-Growl") {
args.push('--name', options.name);
}
switch(cmd.type) {
- case 'Darwin':
+ case 'Darwin-Growl':
+ args.push(cmd.msg);
+ args.push('"' + msg + '"');
+ if (options.title) args.push('"' + options.title + '"');
+ break;
+ case 'Darwin-NotificationCenter':
+ args.push(cmd.msg);
+ args.push('"' + msg + '"');
+ if (options.title) {
+ args.push(cmd.title);
+ args.push('"' + options.title + '"');
+ }
+ if (options.subtitle) {
+ args.push(cmd.subtitle);
+ args.push('"' + options.subtitle + '"');
+ }
+ break;
+ case 'Darwin-Growl':
args.push(cmd.msg);
args.push('"' + msg + '"');
if (options.title) args.push('"' + options.title + '"');
View
@@ -1,6 +1,10 @@
-{ "name": "growl",
+{
+ "name": "growl",
"version": "1.5.1",
"description": "Growl unobtrusive notifications",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
- "main": "./lib/growl.js"
-}
+ "main": "./lib/growl.js",
+ "dependencies": {
+ "execSync": "0.0.1"
+ }
+}

0 comments on commit d9563bf

Please sign in to comment.