From b55e62545777177bf4682376bb7eba7f18b75203 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Tue, 12 Oct 2021 16:12:29 -0400 Subject: [PATCH] Improve notification.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added: - Support for passing a callback to node-notifier. - Shorter timeout on notifications (~12 s → ~5 s). --- build/utils/notification.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/build/utils/notification.js b/build/utils/notification.js index 47ced88..a946c35 100644 --- a/build/utils/notification.js +++ b/build/utils/notification.js @@ -5,12 +5,14 @@ import notifier from 'node-notifier'; * * Wraps around node-notifier to assign default values. * - * @param {string|object} options - The notification options or a message. - * @param {string} options.title - The notification title. - * @param {string} options.message - The notification message. - * @param {string} options.icon - The notification icon. + * @param {string|object} options - The notification options or a message. + * @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); };