From 085fa6c8414cc45c51738a04d27f7659d7eb167d Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Sat, 23 Feb 2019 19:12:58 +0100 Subject: [PATCH] Extra notification check for Edge --- src/app.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index 08efb43..072c1f9 100644 --- a/src/app.js +++ b/src/app.js @@ -91,10 +91,33 @@ document.addEventListener("DOMContentLoaded", () => { return outputArray; } + function checkNotificationPermission() { + return new Promise((resolve, reject) => { + if (Notification.permission === 'denied') { + return reject(new Error('Push messages are blocked.')); + } + + if (Notification.permission === 'granted') { + return resolve(); + } + + if (Notification.permission === 'default') { + return Notification.requestPermission().then(result => { + if (result !== 'granted') { + reject(new Error('Bad permission result')); + } + + resolve(); + }); + } + }); + } + function push_subscribe() { changePushButtonState('computing'); - navigator.serviceWorker.ready + return checkNotificationPermission() + .then(() => navigator.serviceWorker.ready) .then(serviceWorkerRegistration => serviceWorkerRegistration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: urlBase64ToUint8Array(applicationServerKey),