feat: add service worker
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 1m24s
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 1m24s
This commit is contained in:
parent
65e9c0fc19
commit
660017edda
3 changed files with 24 additions and 4 deletions
|
|
@ -127,7 +127,7 @@ export default function NotificationSettings() {
|
|||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{!isInstalled() ? (
|
||||
{isInstalled() ? (
|
||||
pushEnabled ? (
|
||||
<div className="flex items-start sm:items-center justify-between gap-4">
|
||||
<div className="space-y-1 flex-1">
|
||||
|
|
|
|||
20
public/sw/push.js
Normal file
20
public/sw/push.js
Normal 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) {});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
export default {
|
||||
// workbox: {
|
||||
// importScripts: ["/sw/push.js"],
|
||||
// },
|
||||
workbox: {
|
||||
importScripts: ["/sw/push.js"],
|
||||
},
|
||||
includeAssets: [
|
||||
"favicon.ico",
|
||||
"favicon-96x96.png",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue