2018-11-08 19:23:39 +05:30
|
|
|
/* eslint-disable func-names, no-var, consistent-return, prefer-arrow-callback, no-return-assign, object-shorthand, comma-dangle, max-len */
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
function notificationGranted(message, opts, onclick) {
|
|
|
|
var notification;
|
|
|
|
notification = new Notification(message, opts);
|
|
|
|
setTimeout(function() {
|
|
|
|
// Hide the notification after X amount of seconds
|
|
|
|
return notification.close();
|
|
|
|
}, 8000);
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
return notification.onclick = onclick || notification.close;
|
|
|
|
}
|
|
|
|
|
|
|
|
function notifyPermissions() {
|
|
|
|
if ('Notification' in window) {
|
|
|
|
return Notification.requestPermission();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function notifyMe(message, body, icon, onclick) {
|
|
|
|
var opts;
|
|
|
|
opts = {
|
|
|
|
body: body,
|
|
|
|
icon: icon
|
|
|
|
};
|
|
|
|
// Let's check if the browser supports notifications
|
|
|
|
if (!('Notification' in window)) {
|
|
|
|
// do nothing
|
|
|
|
} else if (Notification.permission === 'granted') {
|
|
|
|
// If it's okay let's create a notification
|
|
|
|
return notificationGranted(message, opts, onclick);
|
|
|
|
} else if (Notification.permission !== 'denied') {
|
|
|
|
return Notification.requestPermission(function(permission) {
|
|
|
|
// If the user accepts, let's create a notification
|
|
|
|
if (permission === 'granted') {
|
2016-09-13 17:45:13 +05:30
|
|
|
return notificationGranted(message, opts, onclick);
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const notify = {
|
|
|
|
notificationGranted,
|
|
|
|
notifyPermissions,
|
|
|
|
notifyMe,
|
|
|
|
};
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
export default notify;
|