diff --git a/skolehjem/app/Notifications/PushNews.php b/skolehjem/app/Notifications/PushNews.php index 745e75d..de4d6d6 100644 --- a/skolehjem/app/Notifications/PushNews.php +++ b/skolehjem/app/Notifications/PushNews.php @@ -34,7 +34,8 @@ class PushNews extends Notification ->title('Ny Nyhed') ->icon('/images/icons/appIcon.png') ->body('Der er en ny nyhed i ekapp\'en') - ->action('Se nyheder', 'root.index'); + ->badge('/images/icons/appIcon.png') + ->action('Se nyheder', route('root.index')); } /** diff --git a/skolehjem/public/serviceWorkerCachedWebpags.js b/skolehjem/public/serviceWorkerCachedWebpags.js index 279db5c..a2246a1 100644 --- a/skolehjem/public/serviceWorkerCachedWebpags.js +++ b/skolehjem/public/serviceWorkerCachedWebpags.js @@ -25,7 +25,6 @@ const assets = [ '/images/logos/Logo-hvid.svg', '/images/logos/Logo-normal.svg', '/images/icons/Logout.svg' - ]; // install event @@ -58,18 +57,22 @@ self.addEventListener('activate', evt => { self.addEventListener('fetch', evt => { console.log('fetch event'); - evt.respondWith( - caches.match(evt.request).then(cacheRes => { - return cacheRes || fetch(evt.request).then(fetchRes => { + + if(!navigator.onLine) + evt.respondWith( + caches.match(evt.request).then(cacheRes => { + return cacheRes || caches.match('/offline.html'); + }) + ); + else + evt.respondWith( + fetch(evt.request).then(fetchRes => { return caches.open(dynamicCacheName).then(cache => { cache.put(evt.request.url, fetchRes.clone()); return fetchRes; }) - }); - }).catch(function () { - return caches.match('/offline.html'); - }) - ); + }) + ); }); self.addEventListener('push', function(event) { @@ -84,7 +87,18 @@ self.addEventListener('push', function(event) { event.waitUntil(self.registration.showNotification(msg.title, { body: msg.body, icon: msg.icon, + badge: msg.badge, actions: msg.actions })); } }); + +self.addEventListener('notificationclick', (event) => { + event.notification.close(); + + if (event.action === 'some_action') { + self.clients.openWindow('/home'); + } else { + self.clients.openWindow('/') + } +});