Improve notification.js
Added: - Support for passing a callback to node-notifier. - Shorter timeout on notifications (~12 s → ~5 s).
This commit is contained in:
@@ -5,12 +5,14 @@ import notifier from 'node-notifier';
|
|||||||
*
|
*
|
||||||
* Wraps around node-notifier to assign default values.
|
* Wraps around node-notifier to assign default values.
|
||||||
*
|
*
|
||||||
* @param {string|object} options - The notification options or a message.
|
* @param {string|object} options - The notification options or a message.
|
||||||
* @param {string} options.title - The notification title.
|
* @param {string} options.title - The notification title.
|
||||||
* @param {string} options.message - The notification message.
|
* @param {string} options.message - The notification message.
|
||||||
* @param {string} options.icon - The notification icon.
|
* @param {string} options.icon - The notification icon.
|
||||||
|
* @param {function} callback - The notification callback.
|
||||||
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
export default function notification(options) {
|
export default function notification(options, callback) {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = {
|
options = {
|
||||||
message: options
|
message: options
|
||||||
@@ -25,5 +27,15 @@ export default function notification(options) {
|
|||||||
options.icon = 'https://user-images.githubusercontent.com/4596862/54868065-c2aea200-4d5e-11e9-9ce3-e0013c15f48c.png';
|
options.icon = 'https://user-images.githubusercontent.com/4596862/54868065-c2aea200-4d5e-11e9-9ce3-e0013c15f48c.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
notifier.notify(options);
|
// If notification does not use a callback,
|
||||||
|
// shorten the wait before timing out.
|
||||||
|
if (typeof callback === 'undefined') {
|
||||||
|
if (typeof options.wait === 'undefined') {
|
||||||
|
if (typeof options.timeout === 'undefined') {
|
||||||
|
options.timeout = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifier.notify(options, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user