Skip to content

Commit

Permalink
Merge pull request #306 from Daniihh/master
Browse files Browse the repository at this point in the history
Automagically Bind `notify` Methods
  • Loading branch information
mikaelbr committed Feb 18, 2020
2 parents 2a51128 + bd91b92 commit be3642b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
11 changes: 9 additions & 2 deletions notifiers/balloon.js
Expand Up @@ -50,7 +50,7 @@ function WindowsBalloon(options) {
util.inherits(WindowsBalloon, EventEmitter);

function noop() {}
WindowsBalloon.prototype.notify = function(options, callback) {
function notifyRaw(options, callback) {
var fallback;
var notifierOptions = this.options;
options = utils.clone(options || {});
Expand Down Expand Up @@ -105,7 +105,14 @@ WindowsBalloon.prototype.notify = function(options, callback) {
});

return this;
};
}

Object.defineProperty(WindowsBalloon.prototype, 'notify', {
get: function() {
if (!this._notify) this._notify = notifyRaw.bind(this);
return this._notify;
}
});

var allowedArguments = ['t', 'd', 'p', 'm', 'i', 'e', 'q', 'w', 'xp'];

Expand Down
11 changes: 9 additions & 2 deletions notifiers/growl.js
Expand Up @@ -28,7 +28,7 @@ function Growl(options) {
}
util.inherits(Growl, EventEmitter);

Growl.prototype.notify = function(options, callback) {
function notifyRaw(options, callback) {
growly.setHost(this.options.host, this.options.port);
options = utils.clone(options || {});

Expand Down Expand Up @@ -71,6 +71,13 @@ Growl.prototype.notify = function(options, callback) {
callback();
});
return this;
};
}

Object.defineProperty(Growl.prototype, 'notify', {
get: function() {
if (!this._notify) this._notify = notifyRaw.bind(this);
return this._notify;
}
});

function noop() {}
11 changes: 9 additions & 2 deletions notifiers/notificationcenter.js
Expand Up @@ -31,7 +31,7 @@ util.inherits(NotificationCenter, EventEmitter);
var activeId = null;

function noop() {}
NotificationCenter.prototype.notify = function(options, callback) {
function notifyRaw(options, callback) {
var fallbackNotifier;
var id = identificator();
options = utils.clone(options || {});
Expand Down Expand Up @@ -93,7 +93,14 @@ NotificationCenter.prototype.notify = function(options, callback) {

callback(new Error(errorMessageOsX));
return this;
};
}

Object.defineProperty(NotificationCenter.prototype, 'notify', {
get: function() {
if (!this._notify) this._notify = notifyRaw.bind(this);
return this._notify;
}
});

function identificator() {
return { _ref: 'val' };
Expand Down
11 changes: 9 additions & 2 deletions notifiers/notifysend.js
Expand Up @@ -26,7 +26,7 @@ function NotifySend(options) {
util.inherits(NotifySend, EventEmitter);

function noop() {}
NotifySend.prototype.notify = function(options, callback) {
function notifyRaw(options, callback) {
options = utils.clone(options || {});
callback = callback || noop;

Expand Down Expand Up @@ -70,7 +70,14 @@ NotifySend.prototype.notify = function(options, callback) {
}

return this;
};
}

Object.defineProperty(NotifySend.prototype, 'notify', {
get: function() {
if (!this._notify) this._notify = notifyRaw.bind(this);
return this._notify;
}
});

var allowedArguments = ['urgency', 'expire-time', 'icon', 'category', 'hint'];

Expand Down
11 changes: 9 additions & 2 deletions notifiers/toaster.js
Expand Up @@ -49,7 +49,7 @@ function getPipeName() {
return `${PIPE_PATH_PREFIX}${PIPE_NAME}-${uuid()}`;
}

WindowsToaster.prototype.notify = function(options, callback) {
function notifyRaw(options, callback) {
options = utils.clone(options || {});
callback = callback || noop;
var is64Bit = os.arch() === 'x64';
Expand Down Expand Up @@ -142,4 +142,11 @@ WindowsToaster.prototype.notify = function(options, callback) {
);
});
return this;
};
}

Object.defineProperty(WindowsToaster.prototype, 'notify', {
get: function() {
if (!this._notify) this._notify = notifyRaw.bind(this);
return this._notify;
}
});

0 comments on commit be3642b

Please sign in to comment.