Merge branch 'main' of https://git.d-popov.com/popov/mwhitnessing
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -35,4 +35,4 @@ certificates
|
|||||||
content/output/*
|
content/output/*
|
||||||
public/content/output/*
|
public/content/output/*
|
||||||
public/content/output/shifts 2024.1.json
|
public/content/output/shifts 2024.1.json
|
||||||
!public/content/uploads/*
|
!public/content/uploads/*
|
||||||
|
71
worker.js
Normal file
71
worker.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// 'use strict'
|
||||||
|
// // currently not used as we ise next-pwa and in next.config.js we have withPWA.
|
||||||
|
// // maybe we can have withPWA({sw: './worker.js'}) ?
|
||||||
|
// console.log('Service Worker worker/index.js Loaded...')
|
||||||
|
// workbox.precaching.precacheAndRoute(self.__WB_MANIFEST);
|
||||||
|
|
||||||
|
|
||||||
|
// self.addEventListener('install', () => {
|
||||||
|
// console.log('service worker installed')
|
||||||
|
// });
|
||||||
|
|
||||||
|
// self.addEventListener('activate', () => {
|
||||||
|
// console.log('service worker activated')
|
||||||
|
// });
|
||||||
|
|
||||||
|
// self.addEventListener('fetch', (event) => {
|
||||||
|
// try {
|
||||||
|
// console.log('Fetch event for ', event.request.url);
|
||||||
|
// if (event.request.url.includes('/api/auth/callback/')) {
|
||||||
|
// // Use network only strategy for auth routes, or bypass SW completely
|
||||||
|
// event.respondWith(fetch(event.request));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// // other caching strategies...
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error(error)
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// self.addEventListener('push', function (event) {
|
||||||
|
// console.log('Push message', event)
|
||||||
|
// if (!(self.Notification && self.Notification.permission === 'granted')) {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// const data = JSON.parse(event.data.text())
|
||||||
|
// event.waitUntil(
|
||||||
|
// registration.showNotification(data.title, {
|
||||||
|
// body: data.message,
|
||||||
|
// icon: '/icons/android-chrome-192x192.png'
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
// })
|
||||||
|
|
||||||
|
// self.addEventListener('notificationclick', function (event) {
|
||||||
|
// console.log('Notification click: tag', event.notification.tag)
|
||||||
|
// event.notification.close()
|
||||||
|
// event.waitUntil(
|
||||||
|
// clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (clientList) {
|
||||||
|
// if (clientList.length > 0) {
|
||||||
|
// let client = clientList[0]
|
||||||
|
// for (let i = 0; i < clientList.length; i++) {
|
||||||
|
// if (clientList[i].focused) {
|
||||||
|
// client = clientList[i]
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return client.focus()
|
||||||
|
// }
|
||||||
|
// return clients.openWindow('/')
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
// })
|
||||||
|
|
||||||
|
// // self.addEventListener('pushsubscriptionchange', function(event) {
|
||||||
|
// // event.waitUntil(
|
||||||
|
// // Promise.all([
|
||||||
|
// // Promise.resolve(event.oldSubscription ? deleteSubscription(event.oldSubscription) : true),
|
||||||
|
// // Promise.resolve(event.newSubscription ? event.newSubscription : subscribePush(registration))
|
||||||
|
// // .then(function(sub) { return saveSubscription(sub) })
|
||||||
|
// // ])
|
||||||
|
// // )
|
||||||
|
// // })
|
@ -1,59 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
console.log('Service Worker Loaded...')
|
|
||||||
|
|
||||||
self.addEventListener('fetch', (event) => {
|
|
||||||
try {
|
|
||||||
if (event.request.url.includes('/api/auth/callback/')) {
|
|
||||||
// Use network only strategy for auth routes, or bypass SW completely
|
|
||||||
event.respondWith(fetch(event.request));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// other caching strategies...
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('push', function (event) {
|
|
||||||
console.log('Push message', event)
|
|
||||||
if (!(self.Notification && self.Notification.permission === 'granted')) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const data = JSON.parse(event.data.text())
|
|
||||||
event.waitUntil(
|
|
||||||
registration.showNotification(data.title, {
|
|
||||||
body: data.message,
|
|
||||||
icon: '/icons/android-chrome-192x192.png'
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
self.addEventListener('notificationclick', function (event) {
|
|
||||||
console.log('Notification click: tag', event.notification.tag)
|
|
||||||
event.notification.close()
|
|
||||||
event.waitUntil(
|
|
||||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (clientList) {
|
|
||||||
if (clientList.length > 0) {
|
|
||||||
let client = clientList[0]
|
|
||||||
for (let i = 0; i < clientList.length; i++) {
|
|
||||||
if (clientList[i].focused) {
|
|
||||||
client = clientList[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return client.focus()
|
|
||||||
}
|
|
||||||
return clients.openWindow('/')
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
// self.addEventListener('pushsubscriptionchange', function(event) {
|
|
||||||
// event.waitUntil(
|
|
||||||
// Promise.all([
|
|
||||||
// Promise.resolve(event.oldSubscription ? deleteSubscription(event.oldSubscription) : true),
|
|
||||||
// Promise.resolve(event.newSubscription ? event.newSubscription : subscribePush(registration))
|
|
||||||
// .then(function(sub) { return saveSubscription(sub) })
|
|
||||||
// ])
|
|
||||||
// )
|
|
||||||
// })
|
|
Reference in New Issue
Block a user