Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ASoldo committed Jan 8, 2024
1 parent f880537 commit 2da706c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions components/PWA.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ onMounted(() => {
</script>

<template>
<!-- <VitePwaManifest /> -->
<NuxtPwaManifest />
<VitePwaManifest />
<!-- <NuxtPwaManifest /> -->
<ClientOnly>
<!-- You can use $pwa directly in templates! -->
<!-- <div v-show="$pwa.needRefresh" -->
Expand Down
114 changes: 57 additions & 57 deletions public/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,60 @@ clientsClaim();

console.log("Custom Service Worker");

// // Skip Waiting Listener for reloading the page when a new version is available
// self.addEventListener("message", (event) => {
// if (event.data && event.data.type === "SKIP_WAITING") self.skipWaiting();
// });
//
// // Push Notification Listener
// self.addEventListener("push", (event: PushEvent) => {
// console.log("Sansoldino:push", event);
// const data: NotificationData = event.data
// ? event.data.json()
// : { title: "", body: "" };
//
// const notificationOptions = {
// body: data.body,
// };
//
// event.waitUntil(
// self.registration.showNotification(data.title, notificationOptions),
// );
// });
//
// self.addEventListener("notificationclick", (event: NotificationEvent) => {
// console.log("Sansoldino:click", event);
//
// // Close the notification.
// event.notification.close();
//
// // Extract the URL to navigate to from the event, or use a default.
// const targetUrl = event.notification.data?.url || "/";
//
// // Use self.clients.matchAll() to get all of our service worker's clients
// event.waitUntil(
// self.clients
// .matchAll({ type: "window", includeUncontrolled: true })
// .then((clientList: readonly WindowClient[]) => {
// // If a client matching the URL already exists, focus it.
// for (const client of clientList) {
// if (client.url === targetUrl && "focus" in client) {
// return client.focus();
// }
// }
//
// // If no matching clients exist, open a new one.
// if (self.clients.openWindow) {
// return self.clients.openWindow(targetUrl);
// }
// }),
// );
// });
//
// // Message Listener in the Service Worker
// self.addEventListener("message", (event) => {
// if (event.data && event.data.type === "SHOW_NOTIFICATION") {
// const { title, options } = event.data;
// self.registration.showNotification(title, options);
// }
// });
// Skip Waiting Listener for reloading the page when a new version is available
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") self.skipWaiting();
});

// Push Notification Listener
self.addEventListener("push", (event: PushEvent) => {
console.log("Sansoldino:push", event);
const data: NotificationData = event.data
? event.data.json()
: { title: "", body: "" };

const notificationOptions = {
body: data.body,
};

event.waitUntil(
self.registration.showNotification(data.title, notificationOptions),
);
});

self.addEventListener("notificationclick", (event: NotificationEvent) => {
console.log("Sansoldino:click", event);

// Close the notification.
event.notification.close();

// Extract the URL to navigate to from the event, or use a default.
const targetUrl = event.notification.data?.url || "/";

// Use self.clients.matchAll() to get all of our service worker's clients
event.waitUntil(
self.clients
.matchAll({ type: "window", includeUncontrolled: true })
.then((clientList: readonly WindowClient[]) => {
// If a client matching the URL already exists, focus it.
for (const client of clientList) {
if (client.url === targetUrl && "focus" in client) {
return client.focus();
}
}

// If no matching clients exist, open a new one.
if (self.clients.openWindow) {
return self.clients.openWindow(targetUrl);
}
}),
);
});

// Message Listener in the Service Worker
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SHOW_NOTIFICATION") {
const { title, options } = event.data;
self.registration.showNotification(title, options);
}
});
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
// "compilerOptions": {
// "lib": [
// "WebWorker"
// ]
// }
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
"lib": [
"WebWorker"
]
}
}

0 comments on commit 2da706c

Please sign in to comment.