8889841cPK@[8n(( README.mdnuW+A# Growly # Simple zero-dependency Growl notifications using GNTP. ## Installation ## Install growly using `npm`: ``` npm install growly ``` And then require it: ```javascript var growly = require('growly'); ``` This module uses the Growl Network Transport Protocol (GNTP) which was implemented in Growl since version 1.3, so you **must have an appropriate version of Growl installed** for Growly to work. ## Example ## Sending a minimal Growl notification: ```javascript var growly = require('growly'); growly.notify('This is as easy as it gets', { title: 'Hello, World!' }); ``` More examples can be found in the *example/* directory. ## Usage ## The growly module exposes only three methods: `Growly.register()`, `Growly.notify()`, and `Growly.setHost()`. ### Growly.register(appname, [appicon], [notifications], [callback]) ### Registers a new application with Growl. Registration is completely optional since it will be performed automatically for you with sensible defaults. Useful if you want your application, with its own icon and types of notifications, to show up in Growl's prefence panel. - `appname` the name of the application (required.) - `appicon` url, file path, or Buffer instance for an application icon image. - `notifications` a list of defined notification types with the following properties: - `.label` name used to identify the type of notification being used (required.) - `.dispname` name users will see in Growl's preference panel (defaults to `.label`.) - `.enabled` whether or not notifications of this type are enabled (defaults to true.) - `callback` called when the registration completes; if registration fails, the first argument will be an Error object. An example: ```javascript growly.register('My Application', 'path/to/icon.png', [ { label: 'success', dispname: 'Success' }, { label: 'warning', dispname: 'Warning', enabled: false } ], function(err) { console.log(err || 'Registration successful!'); }); ``` ### Growly.notify(text, [opts], [callback]) ### Sends a Growl notification. If an application wasn't registered beforehand with `growly.register()`, a default application will automatically be registered beforesending the notification. - `text` the body of the notification. - `opts` an object with the following properties: - `.title` title of the notification. - `.icon` url, file path, or Buffer instance for the notification's icon. - `.sticky` whether or not to sticky the notification (defaults to false.) - `.label` type of notification to use (defaults to the first registered notification type.) - `.priority` the priority of the notification from lowest (-2) to highest (2). - `.coalescingId` replace/update the matching previous notification. May be ignored. - `callback` called when the user has closed/clicked the notification. The callback is passed an Error object `err` as the first argument when the notification fails; otherwise, the second argument `action` is a string that'll describe which action has been taken by the user (either 'closed' or 'clicked'.) An example: ```javascript /* Assuming an application was registered with a notification type labeled 'warning'. */ growly.notify('Stuffs broken!', { label: 'warning' }, function(err, action) { console.log('Action:', action); }); ``` ### Growly.setHost(host, port) ### Set the host and port that Growl (GNTP) requests will be sent to. Using this method is optional since GNTP defaults to using host 'localhost' and port 23053. ## License ## Copyright (C) 2014 Ibrahim Al-Rajhi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK@[,99example/cake.pngnuW+APNG  IHDRddpTtEXtSoftwareAdobe ImageReadyqe< riTXtXML:com.adobe.xmp ֵL,IDATx} UkoZێxSDvg0&!akN’0p9 C` daɘ8$^ؖٲikm-7uۗkW8,m^zU$Ihy(k!xe=MoQ _ll 6Sc/=xq]sک qlo; ~^FMBM4--&.0W5 FIL~o~N>[?m>j) SO1@"0k\zPZ %'¿DjLI:!c0w^+ג܋o?U}n^R U 9:QEe%.[+cBg4yZ6{Q~R,QŔQH0@ɬri/ €xꋴe|<=&T.~~Ə;%s_P#qh׷O?.z!,yv^{!-hwyi~gFpFGnݺ)[w*?U۷~_ݱwVvh<iF-qg>Dǧ8I^dlپm'6f)Pc}ЎhI;kN;ϒ#zWm{{K>7OS ==F9E"$3/#() em??J gpZP_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BTt@ރ؃nېr>ۓa {^ &yWTZC*i|3 #(?t hK>Kw] [γd ,!#BQop&q)b& 7KdAt@[]Hi3TtE}c}hߵzRM'h \y <Zr9dҮO+yh3yan,/3)]nRuNoG&OI_ }^`'bj^.0aR+E 5gQ+>?Oِ)FģBwex4sؖx~K2%F(!Bd`l(SMKՆf~P7 {6Od3Q:c֪B1A4](  ˣP{d&] p[0|X;?W>@_wtM\21>BoAV's2Eֵ˦(ɓe?Xt|L^LB_W?^-u;N溑ѵH;Ff±Ba8:>)q.y zI0viYeM|N3,[ՌX7̬QQ ToM7QZ'j2,ݶ wqeZY2LKY^M2PigTٜcڎőbgr$U'[ΩZeD7c-j8+<f1wjk\XA tl4rbGDac'(o77Ĝ_ɈJ&g%EːoՉ,&r/?q|(9L sjMmpljd\tݮݬ.r(ձ U7S*G~Gu];*^(@G2L %EҖJ |_!o/'+@1W뷀HwU|&6)Qhq 0cӲu>Y{nGԗbm1 K6U LrA,q@Ҭ-//IJO+J.y!]wE+ Ȼ{U"JmqV>|pei:ox-ϝ5Ldp|p$9>U_6VZ}qLD ;5??,cuPߋw#^ҧ$+UE!.f ; $?oP=^nc 5@kXd k5@Y{z?K5bIENDB`PK@[KKexample/simple.jsnuW+Avar growly = require('../lib/growly.js'); growly.notify('Hello, world!'); PK@[Yexample/bakery.jsnuW+Avar growly = require('../lib/growly.js'); var notifications = [ { label: 'muffin', dispname: 'Muffin' }, { label: 'cake', dispname: 'Cake' } ], muffinopts = { label: 'muffin', icon: 'muffin.png' }, cakeopts = { label: 'cake', title: 'Cake is ready!', icon: 'cake.png', sticky: true }; growly.register('Bakery', 'muffin.png', notifications, function(err) { if (err) { console.log(err); return; } growly.notify('Looks like it is half past muffin time!', muffinopts); growly.notify('Click to deliver', cakeopts, function(err, action) { console.log('You', action, 'the notification, so the cake is on its way!'); }); }); PK@[cRBRBexample/muffin.pngnuW+APNG  IHDRddpTtEXtSoftwareAdobe ImageReadyqe< riTXtXML:com.adobe.xmp ֵL4vI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M2+!b}JE:؋lJaH CLW"G7oёxgNTB~zb&|_@ǹUПnb⮶>+AT=]\véI鯑ZuV^sOY Uc׉;V j.Q.J]Z2|VTbphĚjCEX Tե6BR02U(%yv iST6e^V8?2p\.SZjĒN}Bv^fx,Ce(m3dA$PZMjr._{dSe1U5ϯZ`)ByNui[TLE"uR/BeՑVS&^cʓڈd4KUS#lJTt=MwY.mUʹK0zbHCӞ\}Fj*h]^E?4i_{Ayua>Cy@9oYыW7O坷zQW!ZKAԍ܌- HrY;r™GG!S<Պ'Wf&0"<~͒(&|JK«u5h]#(Ho Oeժ)S3.21Rk4m jtHzW-U/1+Blb^ZY6,iiI.)å`XʸacV= 4P~UcHC-JYc̤37wJu$f ]ؚ  }  ЇP*(f&Nv$Bki"NmfU8G&.̞(OPl\--nL74CDʫsg&ZKS!Yp[J榘϶vPj}1 ™<)?:ޓ eAF /  t7+4Ҭ)-TK2B% tl7qTBhm[ZuCzLUgH0!"7ܢ'QR[ DBt$' kY,h/ܢC@mFx4H$ 9d$//M(I-j:&@λbpxiu%ʖ+r3d0ro5.Q?3ΐj5C18UϽ\X;\ݦ9sƿE= 0) { if (self.attempts <= self.maxAttempts) { self.retry(callback); } else { var msg = 'GNTP request to "%s:%d" failed with error code %s (%s)'; callback(new Error(format(msg, self.host, self.port, resp['Error-Code'], resp['Error-Description']))); } } else { callback(undefined, resp); } }); socket.on('error', function() { callback(new Error(format('Error while sending GNTP request to "%s:%d"', self.host, self.port))); socket.destroy(); }); }; module.exports = GNTP; PK@[8]» lib/growly.jsnuW+Avar GNTP = require('./gntp.js'); /** * Interface for registering Growl applications and sending Growl notifications. * * @api private */ function Growly() { this.appname = 'Growly'; this.notifications = undefined; this.labels = undefined; this.count = 0; this.registered = false; this.host = undefined; this.port = undefined; } /** * Returns an array of label strings extracted from each notification object in * `Growly.notifications`. * * @param {Array} notifications * @return {Array} notification labels * @api private */ Growly.prototype.getLabels = function() { return this.notifications.map(function(notif) { return notif.label; }); }; /** * Set the host to be used by GNTP requests. * * @param {String} host * @param {Number} port * @api public */ Growly.prototype.setHost = function(host, port) { this.host = host; this.port = port; }; /** * Register an application with the name `appname` (required), icon `appicon`, and * a list of notification types `notifications`. If provided, `callback` will be * called when the request completes with the first argument being an `err` error * object if the request failed. * * Each object in the `notifications` array defines a type of notification the * application will have with the following properties: * * - `.label` name used to identify the type of notification being used (required) * - `.dispname` name users will see in Growl's preference panel (defaults to `.label`) * - `.enabled` whether or not notifications of this type are enabled (defaults to true) * - `.icon` default icon notifications of this type should use (url, file path, or Buffer object) * * Example registration: * * growl.register('My Application', 'path/to/icon.png', [ * { label: 'success', dispname: 'Success', icon: 'path/to/success.png' }, * { label: 'warning', dispname: 'Warning', icon: 'path/to/warning.png', enabled: false } * ], function(err) { console.log(err || 'Registration successful!'); }); * * @param {String} appname * @param {String|Buffer} appicon * @param {Array} notifications * @param {Function} callback * @api public */ Growly.prototype.register = function(appname, appicon, notifications, callback) { var gntp; if (typeof appicon === 'object') { notifications = appicon; appicon = undefined; } if (notifications === undefined || !notifications.length) { notifications = [{ label: 'default', dispname: 'Default Notification', enabled: true }]; } if (typeof arguments[arguments.length - 1] === 'function') { callback = arguments[arguments.length - 1]; } else { callback = function() {}; } this.appname = appname; this.notifications = notifications; this.labels = this.getLabels(); this.registered = true; gntp = new GNTP('REGISTER', { host: this.host, port: this.port }); gntp.add('Application-Name', appname); gntp.add('Application-Icon', appicon); gntp.add('Notifications-Count', notifications.length); gntp.newline(); notifications.forEach(function(notif) { if (notif.enabled === undefined) notif.enabled = true; gntp.add('Notification-Name', notif.label); gntp.add('Notification-Display-Name', notif.dispname); gntp.add('Notification-Enabled', notif.enabled ? 'True' : 'False'); gntp.add('Notification-Icon', notif.icon); gntp.newline(); }); gntp.send(callback); }; /** * Send a notification with `text` content. Growly will lazily register itself * if the user hasn't already before sending the notification. * * A notification can have the following `opts` options: * * - `.label` type of notification to use (defaults to the first registered type) * - `.title` title of the notification * - `.icon` url, file path, or Buffer instance for the notification's icon. * - `.sticky` whether or not to sticky the notification (defaults to false) * - `.priority` the priority of the notification from lowest (-2) to highest (2) * - `.coalescingId` replace/update the matching previous notification. May be ignored. * * If provided, `callback` will be called when the user interacts with the notification. * The first argument will be an `err` error object, and the second argument an `action` * string equal to either 'clicked' or 'closed' (whichever action the user took.) * * Example notification: * * growl.notify('Stuffs broken!', { label: 'warning' }, function(err, action) { * console.log('Action:', action); * }); * * @param {String} text * @param {Object} opts * @param {Function} callback * @api public */ Growly.prototype.notify = function(text, opts, callback) { var self = this, gntp; /* Lazy registration. */ if (!this.registered) { this.register(this.appname, function(err) { if (err) console.log(err); self.notify.call(self, text, opts, callback); }); return; } opts = opts || {}; if (typeof opts === 'function') { callback = opts; opts = {}; } gntp = new GNTP('NOTIFY', { host: this.host, port: this.port }); gntp.add('Application-Name', this.appname); gntp.add('Notification-Name', opts.label || this.labels[0]); gntp.add('Notification-ID', ++this.count); gntp.add('Notification-Title', opts.title); gntp.add('Notification-Text', text); gntp.add('Notification-Sticky', opts.sticky ? 'True' : 'False'); gntp.add('Notification-Priority', opts.priority); gntp.add('Notification-Icon', opts.icon); gntp.add('Notification-Coalescing-ID', opts.coalescingId || undefined); gntp.add('Notification-Callback-Context', callback ? 'context' : undefined); gntp.add('Notification-Callback-Context-Type', callback ? 'string' : undefined); gntp.add('Notification-Callback-Target', undefined); gntp.newline(); gntp.send(function(err, resp) { if (callback && err) { callback(err); } else if (callback && resp.state === 'CALLBACK') { callback(undefined, resp['Notification-Callback-Result'].toLowerCase()); } }); }; /** * Expose an instance of the Growly object. */ module.exports = new Growly(); PK@[zE HISTORY.mdnuW+A1.1.0 / 2012-12-12 ================== - Default registration work lazily, and is performed on the first call to `Growly.notify()`. - Added callback to `Growly.register()`. PK@[.   package.jsonnuW+A{ "name": "growly", "version": "1.3.0", "description": "Simple zero-dependency Growl notifications using GNTP.", "keywords": ["growl", "growly", "snarl", "notifications", "gntp", "messages"], "author": "Ibrahim Al-Rajhi (http://ibrahimalrajhi.com/)", "repository": "http://github.com/theabraham/growly", "bugs": "http://github.com/theabraham/growly/issues", "main": "lib/growly.js", "directories": { "example": "example", "lib": "lib" }, "license": "MIT" } PK@[8n(( README.mdnuW+APK@[,99aexample/cake.pngnuW+APK@[KK~Lexample/simple.jsnuW+APK@[Y Mexample/bakery.jsnuW+APK@[cRBRBPexample/muffin.pngnuW+APK@[(( lib/gntp.jsnuW+APK@[8]» lib/growly.jsnuW+APK@[zE HISTORY.mdnuW+APK@[.   package.jsonnuW+APK 5