Skip to content

Commit be3642b

Browse files
authored
Merge pull request #306 from Daniihh/master
Automagically Bind `notify` Methods
2 parents 2a51128 + bd91b92 commit be3642b

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

notifiers/balloon.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function WindowsBalloon(options) {
5050
util.inherits(WindowsBalloon, EventEmitter);
5151

5252
function noop() {}
53-
WindowsBalloon.prototype.notify = function(options, callback) {
53+
function notifyRaw(options, callback) {
5454
var fallback;
5555
var notifierOptions = this.options;
5656
options = utils.clone(options || {});
@@ -105,7 +105,14 @@ WindowsBalloon.prototype.notify = function(options, callback) {
105105
});
106106

107107
return this;
108-
};
108+
}
109+
110+
Object.defineProperty(WindowsBalloon.prototype, 'notify', {
111+
get: function() {
112+
if (!this._notify) this._notify = notifyRaw.bind(this);
113+
return this._notify;
114+
}
115+
});
109116

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

notifiers/growl.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Growl(options) {
2828
}
2929
util.inherits(Growl, EventEmitter);
3030

31-
Growl.prototype.notify = function(options, callback) {
31+
function notifyRaw(options, callback) {
3232
growly.setHost(this.options.host, this.options.port);
3333
options = utils.clone(options || {});
3434

@@ -71,6 +71,13 @@ Growl.prototype.notify = function(options, callback) {
7171
callback();
7272
});
7373
return this;
74-
};
74+
}
75+
76+
Object.defineProperty(Growl.prototype, 'notify', {
77+
get: function() {
78+
if (!this._notify) this._notify = notifyRaw.bind(this);
79+
return this._notify;
80+
}
81+
});
7582

7683
function noop() {}

notifiers/notificationcenter.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ util.inherits(NotificationCenter, EventEmitter);
3131
var activeId = null;
3232

3333
function noop() {}
34-
NotificationCenter.prototype.notify = function(options, callback) {
34+
function notifyRaw(options, callback) {
3535
var fallbackNotifier;
3636
var id = identificator();
3737
options = utils.clone(options || {});
@@ -93,7 +93,14 @@ NotificationCenter.prototype.notify = function(options, callback) {
9393

9494
callback(new Error(errorMessageOsX));
9595
return this;
96-
};
96+
}
97+
98+
Object.defineProperty(NotificationCenter.prototype, 'notify', {
99+
get: function() {
100+
if (!this._notify) this._notify = notifyRaw.bind(this);
101+
return this._notify;
102+
}
103+
});
97104

98105
function identificator() {
99106
return { _ref: 'val' };

notifiers/notifysend.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function NotifySend(options) {
2626
util.inherits(NotifySend, EventEmitter);
2727

2828
function noop() {}
29-
NotifySend.prototype.notify = function(options, callback) {
29+
function notifyRaw(options, callback) {
3030
options = utils.clone(options || {});
3131
callback = callback || noop;
3232

@@ -70,7 +70,14 @@ NotifySend.prototype.notify = function(options, callback) {
7070
}
7171

7272
return this;
73-
};
73+
}
74+
75+
Object.defineProperty(NotifySend.prototype, 'notify', {
76+
get: function() {
77+
if (!this._notify) this._notify = notifyRaw.bind(this);
78+
return this._notify;
79+
}
80+
});
7481

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

notifiers/toaster.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function getPipeName() {
4949
return `${PIPE_PATH_PREFIX}${PIPE_NAME}-${uuid()}`;
5050
}
5151

52-
WindowsToaster.prototype.notify = function(options, callback) {
52+
function notifyRaw(options, callback) {
5353
options = utils.clone(options || {});
5454
callback = callback || noop;
5555
var is64Bit = os.arch() === 'x64';
@@ -142,4 +142,11 @@ WindowsToaster.prototype.notify = function(options, callback) {
142142
);
143143
});
144144
return this;
145-
};
145+
}
146+
147+
Object.defineProperty(WindowsToaster.prototype, 'notify', {
148+
get: function() {
149+
if (!this._notify) this._notify = notifyRaw.bind(this);
150+
return this._notify;
151+
}
152+
});

0 commit comments

Comments
 (0)