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:
@@ -9,8 +9,10 @@ import notifier from 'node-notifier';
|
||||
* @param {string} options.title - The notification title.
|
||||
* @param {string} options.message - The notification message.
|
||||
* @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') {
|
||||
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';
|
||||
}
|
||||
|
||||
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