mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +03:00
Changes for #1007
This commit is contained in:
parent
b824c394ab
commit
2201060888
1 changed files with 17 additions and 10 deletions
|
|
@ -22,15 +22,19 @@ let DesktopNotifications = false,
|
||||||
WorkerNotifications = navigator.serviceWorker;
|
WorkerNotifications = navigator.serviceWorker;
|
||||||
|
|
||||||
// Are Notifications supported in the service worker?
|
// Are Notifications supported in the service worker?
|
||||||
if (WorkerNotifications && ServiceWorkerRegistration && ServiceWorkerRegistration.prototype.showNotification) {
|
if (WorkerNotifications) {
|
||||||
/* Listen for close requests from the ServiceWorker */
|
if (ServiceWorkerRegistration && ServiceWorkerRegistration.prototype.showNotification) {
|
||||||
WorkerNotifications.addEventListener('message', event => {
|
/* Listen for close requests from the ServiceWorker */
|
||||||
const obj = JSON.parse(event.data);
|
WorkerNotifications.addEventListener('message', event => {
|
||||||
'notificationclick' === obj?.action && dispatchMessage(obj.data);
|
const obj = JSON.parse(event.data);
|
||||||
});
|
'notificationclick' === obj?.action && dispatchMessage(obj.data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('ServiceWorkerRegistration.showNotification undefined');
|
||||||
|
WorkerNotifications = null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
WorkerNotifications = null;
|
console.log('ServiceWorker undefined');
|
||||||
console.log('ServiceWorker Notifications not supported');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NotificationUserStore = new class {
|
export const NotificationUserStore = new class {
|
||||||
|
|
@ -65,7 +69,7 @@ export const NotificationUserStore = new class {
|
||||||
}
|
}
|
||||||
if (WorkerNotifications) {
|
if (WorkerNotifications) {
|
||||||
// Service-Worker-Allowed HTTP header to allow the scope.
|
// Service-Worker-Allowed HTTP header to allow the scope.
|
||||||
WorkerNotifications.register('/serviceworker.js')
|
WorkerNotifications.register('./serviceworker.js')
|
||||||
// WorkerNotifications.register(Links.staticLink('js/serviceworker.js'), {scope:'/'})
|
// WorkerNotifications.register(Links.staticLink('js/serviceworker.js'), {scope:'/'})
|
||||||
.then(() =>
|
.then(() =>
|
||||||
WorkerNotifications.ready.then(registration =>
|
WorkerNotifications.ready.then(registration =>
|
||||||
|
|
@ -80,7 +84,10 @@ export const NotificationUserStore = new class {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.catch(e => console.error(e));
|
.catch(e => {
|
||||||
|
console.error(e);
|
||||||
|
WorkerNotifications = null;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
const notification = new HTML5Notification(title, options);
|
const notification = new HTML5Notification(title, options);
|
||||||
notification.show?.();
|
notification.show?.();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue