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 {
|
try {
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
this.checkForUpdates(),
|
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) {
|
} 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
|
// Continue anyway - don't block the initialization
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide spinner once service worker is ready
|
// Hide spinner once service worker is ready
|
||||||
this.hideServiceWorkerSpinner();
|
this.hideServiceWorkerSpinner();
|
||||||
|
console.log('✅ Service worker initialization completed');
|
||||||
|
|
||||||
// Set up a global message listener for responses from the service worker.
|
// Set up a global message listener for responses from the service worker.
|
||||||
navigator.serviceWorker.addEventListener('message', async (event) => {
|
navigator.serviceWorker.addEventListener('message', async (event) => {
|
||||||
@ -161,21 +163,24 @@ export class Database {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Set up a periodic check to ensure the service worker is active and to send a SCAN message.
|
// Set up a periodic check to ensure the service worker is active and to send a SCAN message.
|
||||||
this.serviceWorkerCheckIntervalId = window.setInterval(async () => {
|
// Wait a bit before starting the interval to ensure services are ready
|
||||||
try {
|
setTimeout(() => {
|
||||||
const activeWorker = this.serviceWorkerRegistration?.active || (await this.waitForServiceWorkerActivation(this.serviceWorkerRegistration!));
|
this.serviceWorkerCheckIntervalId = window.setInterval(async () => {
|
||||||
if (activeWorker) {
|
try {
|
||||||
const service = await Services.getInstance();
|
const activeWorker = this.serviceWorkerRegistration?.active || (await this.waitForServiceWorkerActivation(this.serviceWorkerRegistration!));
|
||||||
const payload = await service.getMyProcesses();
|
if (activeWorker) {
|
||||||
if (payload && payload.length != 0) {
|
const service = await Services.getInstance();
|
||||||
activeWorker.postMessage({ type: 'SCAN', payload });
|
const payload = await service.getMyProcesses();
|
||||||
|
if (payload && payload.length != 0) {
|
||||||
|
activeWorker.postMessage({ type: 'SCAN', payload });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Service worker scan failed:', error);
|
||||||
|
// Continue the interval even if one scan fails
|
||||||
}
|
}
|
||||||
} catch (error) {
|
}, 5000);
|
||||||
console.warn('Service worker scan failed:', error);
|
}, 10000); // Wait 10 seconds before starting the interval
|
||||||
// Continue the interval even if one scan fails
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Service Worker registration failed:', error);
|
console.error('Service Worker registration failed:', error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user