Skip to content

Commit

Permalink
Extra notification check for Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
Minishlink committed Feb 23, 2019
1 parent 2596a1d commit 085fa6c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 085fa6c

Please sign in to comment.