fix(ihm_client): double fallback IndexedDB si service worker.ready échoue
All checks were successful
Build and Push Docker image (ext) / docker (push) Successful in 52s
All checks were successful
Build and Push Docker image (ext) / docker (push) Successful in 52s
This commit is contained in:
parent
c21eb9170a
commit
a40416a248
@ -150,7 +150,7 @@ export class Database {
|
||||
if (payload && payload.length != 0) {
|
||||
activeWorker?.postMessage({ type: 'SCAN', payload });
|
||||
}
|
||||
}, 5000);
|
||||
}, 5000);
|
||||
} catch (error) {
|
||||
console.error('Service Worker registration failed:', error);
|
||||
}
|
||||
@ -219,8 +219,8 @@ export class Database {
|
||||
// Save data to db
|
||||
const blob = new Blob([valueBytes], {type: "application/octet-stream"});
|
||||
await service.saveBlobToDb(hash, blob);
|
||||
document.dispatchEvent(new CustomEvent('newDataReceived', {
|
||||
detail: {
|
||||
document.dispatchEvent(new CustomEvent('newDataReceived', {
|
||||
detail: {
|
||||
processId,
|
||||
stateId,
|
||||
hash,
|
||||
@ -308,8 +308,28 @@ export class Database {
|
||||
|
||||
// Check if the service worker is active
|
||||
if (!this.serviceWorkerRegistration) {
|
||||
// console.warn('Service worker registration is not ready. Waiting...');
|
||||
this.serviceWorkerRegistration = await navigator.serviceWorker.ready;
|
||||
try {
|
||||
// console.warn('Service worker registration is not ready. Waiting...');
|
||||
this.serviceWorkerRegistration = await navigator.serviceWorker.ready;
|
||||
} catch (error) {
|
||||
// Si le service worker n'est pas disponible, fallback vers IndexedDB direct
|
||||
console.warn('Service worker not available, falling back to direct IndexedDB');
|
||||
try {
|
||||
const db = await this.getDb();
|
||||
const tx = (db as any).transaction(payload.storeName, 'readwrite');
|
||||
const store = tx.objectStore(payload.storeName);
|
||||
if (payload.key) {
|
||||
await store.put(payload.object, payload.key);
|
||||
} else {
|
||||
await store.put(payload.object);
|
||||
}
|
||||
resolve();
|
||||
return;
|
||||
} catch (dbError: any) {
|
||||
reject(new Error(dbError?.message || 'IndexedDB write failed'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const activeWorker = await this.waitForServiceWorkerActivation(this.serviceWorkerRegistration);
|
||||
@ -340,7 +360,7 @@ export class Database {
|
||||
reject(new Error(`Failed to send message to service worker: ${error}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public batchWriting(payload: { storeName: string; objects: { key: any; object: any }[] }): Promise<void> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user