feat(sw.js): Ajoute la gestion des notifications push et simplifie le SW.
🔧 chore(framework.yaml): Configure les proxies de confiance pour Cloudflare.
```
This commit is contained in:
Serreau Jovann
2025-11-22 21:01:25 +01:00
parent a3dc9f5801
commit 5aaac0aa3b
2 changed files with 8 additions and 31 deletions

View File

@@ -1,40 +1,16 @@
// This is the service worker with the combined offline experience (Offline page + Offline copy of pages)
const CACHE = "pwabuilder-offline-page";
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html";
const offlineFallbackPage = "offline.html";
// --- Service Worker pour la gestion des Notifications Push ---
// Permet au Service Worker de s'activer immédiatement après l'installation
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
self.addEventListener('install', async (event) => {
event.waitUntil(
caches.open(CACHE)
.then((cache) => cache.add(offlineFallbackPage))
);
});
if (workbox.navigationPreload.isSupported()) {
workbox.navigationPreload.enable();
}
workbox.routing.registerRoute(
new RegExp('/*'),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE
})
);
// --- GESTION DES NOTIFICATIONS PUSH (Réception) ---
self.addEventListener('push', (event) => {
if (event.data) {
// Assurez-vous que le payload JSON envoyé par votre serveur contient
// Le payload JSON envoyé par votre serveur doit contenir
// 'title', 'message' et 'link'.
const data = event.data.json();
@@ -44,7 +20,7 @@ self.addEventListener('push', (event) => {
const options = {
body: message,
// PATH MIS À JOUR ICI
// PATH MIS À JOUR ICI : Assurez-vous que l'icône est accessible
icon: data.icon || '/assets/notif.png',
data: {
link: link // On stocke le lien pour le réutiliser au clic
@@ -70,9 +46,9 @@ self.addEventListener('notificationclick', (event) => {
event.waitUntil(
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => {
// Tente de trouver un client existant pour naviguer
// Tente de trouver un client existant pour naviguer (si l'URL est déjà ouverte)
for (const client of clientList) {
if (client.url.endsWith(urlToOpen) && 'focus' in client) {
if (client.url.includes(urlToOpen) && 'focus' in client) {
return client.focus();
}
}