fix: Amélioration de la gestion du Service Worker
- Réduction du timeout des updates de 10s à 5s - Délai de 10s avant de démarrer l'intervalle de scan - Logs améliorés pour diagnostiquer les blocages - Cache Vite nettoyé pour éviter les erreurs TypeScript - Meilleure gestion des erreurs dans l'intervalle de scan - Service Worker plus robuste et moins bloquant
This commit is contained in:
parent
9ec97e1787
commit
ca4e580a95
@ -144,15 +144,17 @@ export class Database {
|
||||
try {
|
||||
await Promise.race([
|
||||
this.checkForUpdates(),
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error('Update timeout')), 10000))
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error('Update timeout')), 5000))
|
||||
]);
|
||||
console.log('✅ Service worker updates completed');
|
||||
} catch (error) {
|
||||
console.warn('Service worker update failed or timed out:', error);
|
||||
console.warn('⚠️ Service worker update failed or timed out:', error);
|
||||
// Continue anyway - don't block the initialization
|
||||
}
|
||||
|
||||
// Hide spinner once service worker is ready
|
||||
this.hideServiceWorkerSpinner();
|
||||
console.log('✅ Service worker initialization completed');
|
||||
|
||||
// Set up a global message listener for responses from the service worker.
|
||||
navigator.serviceWorker.addEventListener('message', async (event) => {
|
||||
@ -161,6 +163,8 @@ export class Database {
|
||||
});
|
||||
|
||||
// Set up a periodic check to ensure the service worker is active and to send a SCAN message.
|
||||
// Wait a bit before starting the interval to ensure services are ready
|
||||
setTimeout(() => {
|
||||
this.serviceWorkerCheckIntervalId = window.setInterval(async () => {
|
||||
try {
|
||||
const activeWorker = this.serviceWorkerRegistration?.active || (await this.waitForServiceWorkerActivation(this.serviceWorkerRegistration!));
|
||||
@ -176,6 +180,7 @@ export class Database {
|
||||
// Continue the interval even if one scan fails
|
||||
}
|
||||
}, 5000);
|
||||
}, 10000); // Wait 10 seconds before starting the interval
|
||||
} catch (error) {
|
||||
console.error('Service Worker registration failed:', error);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user