Network fixes

This commit is contained in:
RobinLinus 2018-09-21 19:51:29 +02:00
parent 10196cdf33
commit 23e7c04393
5 changed files with 46 additions and 55 deletions

View file

@ -335,8 +335,8 @@ class Notifications {
constructor() {
// Check if the browser supports notifications
if (!('Notification' in window)) return;
// Check whether notification permissions have already been granted
if (Notification.permission !== 'granted') {
this.$button = $('notification');
this.$button.removeAttribute('hidden');
@ -358,12 +358,17 @@ class Notifications {
}
_notify(message, body) {
var img = '/images/logo_transparent_128x128.png';
return new Notification(message, {
const config = {
body: body,
icon: img,
icon: '/images/logo_transparent_128x128.png',
vibrate: [200, 100, 200, 100, 200, 100, 400],
});
}
if (serviceWorker && serviceWorker.showNotification) {
// android doesn't support "new Notification" if service worker is installed
return serviceWorker.showNotification(message, config);
} else {
return new Notification(message, config);
}
}
_messageNotification(message) {
@ -434,10 +439,14 @@ document.copy = text => {
return success;
}
if ('serviceWorker' in navigator && isProductionEnvironment) {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/service-worker.js')
.then(e => console.log("Service Worker Registered"));
.then(serviceWorker => {
console.log('Service Worker registered');
window.serviceWorker = serviceWorker
});
}
// Background Animation