2022-03-22 16:32:06 -04:00
|
|
|
/**
|
|
|
|
|
* @file Provides a decorator for cross-platform notification.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-12-11 10:41:07 -05:00
|
|
|
import notifier from 'node-notifier';
|
|
|
|
|
|
2021-09-16 23:46:20 -04:00
|
|
|
/**
|
|
|
|
|
* Sends a cross-platform native notification.
|
|
|
|
|
*
|
|
|
|
|
* Wraps around node-notifier to assign default values.
|
|
|
|
|
*
|
2021-10-12 16:12:29 -04:00
|
|
|
* @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}
|
2021-09-16 23:46:20 -04:00
|
|
|
*/
|
2022-10-13 14:42:22 -04:00
|
|
|
function notification(options, callback) {
|
2021-09-16 23:46:20 -04:00
|
|
|
if (typeof options === 'string') {
|
|
|
|
|
options = {
|
|
|
|
|
message: options
|
|
|
|
|
};
|
|
|
|
|
} else if (!options.title && !options.message) {
|
|
|
|
|
throw new TypeError(
|
|
|
|
|
'Notification expects at least a \'message\' parameter'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof options.icon === 'undefined') {
|
|
|
|
|
options.icon = 'https://user-images.githubusercontent.com/4596862/54868065-c2aea200-4d5e-11e9-9ce3-e0013c15f48c.png';
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 16:12:29 -04:00
|
|
|
// 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);
|
2022-10-13 14:42:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default notification;
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
notification,
|
2021-09-15 17:24:33 -04:00
|
|
|
};
|