Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automagically Bind notify Methods #306

Merged
merged 2 commits into from Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
});