-> Refonte du design de sélection d'afficheurs -> Ajout du Mode PiP -> Patch du bug du logo de l'horaire pas affiché. Corrigé pour les Horaires TER à 6 numéros.
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
const CACHE_NAME = 'ferrovia-pwa-v1';
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
return cache.addAll([
|
|
'./',
|
|
'./index.html',
|
|
'./manifest.json',
|
|
'./favicon.ico',
|
|
'./logo192.png',
|
|
'./logo512.png'
|
|
]);
|
|
})
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((cacheNames) => {
|
|
return Promise.all(
|
|
cacheNames.filter((name) => name !== CACHE_NAME).map((name) => caches.delete(name))
|
|
);
|
|
})
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
// Ignorer les requêtes non-GET et les requêtes vers d'autres origines ou APIs
|
|
if (event.request.method !== 'GET' || !event.request.url.startsWith(self.location.origin)) {
|
|
return;
|
|
}
|
|
|
|
event.respondWith(
|
|
caches.match(event.request).then((cachedResponse) => {
|
|
if (cachedResponse) {
|
|
return cachedResponse;
|
|
}
|
|
return fetch(event.request).then((networkResponse) => {
|
|
return caches.open(CACHE_NAME).then((cache) => {
|
|
cache.put(event.request, networkResponse.clone());
|
|
return networkResponse;
|
|
});
|
|
}).catch(() => {
|
|
// En cas d'échec réseau total, on pourrait retourner un fallback hors-ligne
|
|
return caches.match('./index.html');
|
|
});
|
|
})
|
|
);
|
|
});
|