From d75c0d7c8ca98f62c85a7ee8e8973826ab876085 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Wed, 26 Mar 2025 12:05:35 +0330 Subject: [PATCH] fix build --- frontend/public/sw.js | 128 +++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/frontend/public/sw.js b/frontend/public/sw.js index f0dceab..3b750c8 100644 --- a/frontend/public/sw.js +++ b/frontend/public/sw.js @@ -1,64 +1,64 @@ -// import { precacheAndRoute } from "workbox-precaching"; -// -// // Precaching configuration for PWA assets -// precacheAndRoute(self.__WB_MANIFEST); -// -// // Version -// -// const VERSION = "1.0.4"; -// -// // Service Worker Installation -// self.addEventListener("install", (event) => { -// self.skipWaiting(); -// }); -// -// // Service Worker Activation -// self.addEventListener("activate", (event) => { -// event.waitUntil( -// (async () => { -// const clients = await self.clients.matchAll({ type: "window" }); -// -// // Notify all open clients about the version -// clients.forEach((client) => -// client.postMessage({ type: "VERSION_CHECK", version: VERSION }) -// ); -// -// self.clients.claim(); -// console.log("Service Worker Activated (Version: " + VERSION + ")"); -// })() -// ); -// }); -// -// // Push Notification Handler for Django Web Push -// self.addEventListener("push", (event) => { -// try { -// const payload = event.data?.json() || { -// title: "New Notification", -// body: "You have a new message", -// icon: "/logo-192x192.png", -// data: { url: "/" }, -// }; -// -// event.waitUntil( -// self.registration.showNotification(payload.title, { -// body: payload.body, -// icon: payload.icon || "/logo-192x192.png", -// data: payload.data, -// }) -// ); -// } catch (error) { -// console.error("Push handling failed:", error); -// } -// }); -// -// // Notification Click Handler -// self.addEventListener("notificationclick", (event) => { -// event.notification.close(); -// event.waitUntil(clients.openWindow(event.notification.data?.url || "/")); -// }); -// -// self.addEventListener("message", (event) => { -// if (event.data === "SKIP_WAITING") { -// self.skipWaiting(); -// } -// }); +import { precacheAndRoute } from "workbox-precaching"; + +// Precaching configuration for PWA assets +precacheAndRoute(self.__WB_MANIFEST); + +// Version + +const VERSION = "1.0.4"; + +// Service Worker Installation +self.addEventListener("install", (event) => { + self.skipWaiting(); +}); + +// Service Worker Activation +self.addEventListener("activate", (event) => { + event.waitUntil( + (async () => { + const clients = await self.clients.matchAll({ type: "window" }); + + // Notify all open clients about the version + clients.forEach((client) => + client.postMessage({ type: "VERSION_CHECK", version: VERSION }) + ); + + self.clients.claim(); + console.log("Service Worker Activated (Version: " + VERSION + ")"); + })() + ); +}); + +// Push Notification Handler for Django Web Push +self.addEventListener("push", (event) => { + try { + const payload = event.data?.json() || { + title: "New Notification", + body: "You have a new message", + icon: "/logo-192x192.png", + data: { url: "/" }, + }; + + event.waitUntil( + self.registration.showNotification(payload.title, { + body: payload.body, + icon: payload.icon || "/logo-192x192.png", + data: payload.data, + }) + ); + } catch (error) { + console.error("Push handling failed:", error); + } +}); + +// Notification Click Handler +self.addEventListener("notificationclick", (event) => { + event.notification.close(); + event.waitUntil(clients.openWindow(event.notification.data?.url || "/")); +}); + +self.addEventListener("message", (event) => { + if (event.data === "SKIP_WAITING") { + self.skipWaiting(); + } +});