feat: add service worker
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 1m24s

This commit is contained in:
Nathan Lamy 2025-08-19 22:56:00 +02:00
parent 65e9c0fc19
commit 660017edda
3 changed files with 24 additions and 4 deletions

View file

@ -127,7 +127,7 @@ export default function NotificationSettings() {
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
<CardContent className="space-y-4"> <CardContent className="space-y-4">
{!isInstalled() ? ( {isInstalled() ? (
pushEnabled ? ( pushEnabled ? (
<div className="flex items-start sm:items-center justify-between gap-4"> <div className="flex items-start sm:items-center justify-between gap-4">
<div className="space-y-1 flex-1"> <div className="space-y-1 flex-1">

20
public/sw/push.js Normal file
View file

@ -0,0 +1,20 @@
self.addEventListener("push", onPush);
async function onPush(event) {
if (event.data) {
const data = event.data.json();
const { title, ...rest } = data;
// Send the push data to the application
const clients = await self.clients.matchAll();
clients.forEach((client) => client.postMessage(data));
await event.waitUntil(
self.registration.showNotification(title, {
...rest,
})
);
}
}
// self.addEventListener("notificationclick", function (event) {});

View file

@ -1,7 +1,7 @@
export default { export default {
// workbox: { workbox: {
// importScripts: ["/sw/push.js"], importScripts: ["/sw/push.js"],
// }, },
includeAssets: [ includeAssets: [
"favicon.ico", "favicon.ico",
"favicon-96x96.png", "favicon-96x96.png",