retry voor web push
This commit is contained in:
parent
bcf583866a
commit
5ad018ed6e
38
public/sw.js
Normal file
38
public/sw.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
self.addEventListener('push', function (event) {
|
||||||
|
let data = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
data = event.data?.json() ?? {};
|
||||||
|
} catch (e) {
|
||||||
|
data = { title: 'Notification', body: event.data?.text() ?? '' };
|
||||||
|
}
|
||||||
|
|
||||||
|
event.waitUntil(
|
||||||
|
self.registration.showNotification(data.title, {
|
||||||
|
body: data.body,
|
||||||
|
icon: data.icon,
|
||||||
|
badge: data.badge,
|
||||||
|
data: data.data,
|
||||||
|
actions: data.actions,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('notificationclick', function (event) {
|
||||||
|
event.notification.close();
|
||||||
|
|
||||||
|
const url = event.notification.data?.url ?? '/';
|
||||||
|
|
||||||
|
event.waitUntil(
|
||||||
|
self.clients
|
||||||
|
.matchAll({ type: 'window', includeUncontrolled: true })
|
||||||
|
.then(function (clientList) {
|
||||||
|
for (const client of clientList) {
|
||||||
|
if (client.url === url && 'focus' in client) {
|
||||||
|
return client.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self.clients.openWindow(url);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
@ -35,27 +35,27 @@ export default defineConfig({
|
|||||||
wayfinder({
|
wayfinder({
|
||||||
formVariants: true,
|
formVariants: true,
|
||||||
}),
|
}),
|
||||||
VitePWA({
|
// VitePWA({
|
||||||
registerType: 'autoUpdate',
|
// registerType: 'autoUpdate',
|
||||||
injectRegister: 'auto',
|
// injectRegister: 'auto',
|
||||||
workbox: {
|
// workbox: {
|
||||||
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
|
// globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
|
||||||
runtimeCaching: [
|
// runtimeCaching: [
|
||||||
{
|
// {
|
||||||
urlPattern: ({ url }) => url.pathname.startsWith('/'),
|
// urlPattern: ({ url }) => url.pathname.startsWith('/'),
|
||||||
handler: 'NetworkFirst',
|
// handler: 'NetworkFirst',
|
||||||
options: {
|
// options: {
|
||||||
cacheName: 'api-cache',
|
// cacheName: 'api-cache',
|
||||||
cacheableResponse: {
|
// cacheableResponse: {
|
||||||
statuses: [0, 200],
|
// statuses: [0, 200],
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
srcDir: 'resources/js',
|
// srcDir: 'resources/js',
|
||||||
filename: 'sw.js',
|
// filename: 'sw.js',
|
||||||
outDir: 'public',
|
// outDir: 'public',
|
||||||
}),
|
// }),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user