This commit is contained in:
victor 2020-12-01 09:17:25 +01:00
commit 330cb62fd0
2 changed files with 25 additions and 10 deletions

View File

@ -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'));
}
/**

View File

@ -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('/')
}
});