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) {
|
if (payload && payload.length != 0) {
|
||||||
activeWorker?.postMessage({ type: 'SCAN', payload });
|
activeWorker?.postMessage({ type: 'SCAN', payload });
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Service Worker registration failed:', error);
|
console.error('Service Worker registration failed:', error);
|
||||||
}
|
}
|
||||||
@ -219,8 +219,8 @@ export class Database {
|
|||||||
// Save data to db
|
// Save data to db
|
||||||
const blob = new Blob([valueBytes], {type: "application/octet-stream"});
|
const blob = new Blob([valueBytes], {type: "application/octet-stream"});
|
||||||
await service.saveBlobToDb(hash, blob);
|
await service.saveBlobToDb(hash, blob);
|
||||||
document.dispatchEvent(new CustomEvent('newDataReceived', {
|
document.dispatchEvent(new CustomEvent('newDataReceived', {
|
||||||
detail: {
|
detail: {
|
||||||
processId,
|
processId,
|
||||||
stateId,
|
stateId,
|
||||||
hash,
|
hash,
|
||||||
@ -308,8 +308,28 @@ export class Database {
|
|||||||
|
|
||||||
// Check if the service worker is active
|
// Check if the service worker is active
|
||||||
if (!this.serviceWorkerRegistration) {
|
if (!this.serviceWorkerRegistration) {
|
||||||
// console.warn('Service worker registration is not ready. Waiting...');
|
try {
|
||||||
this.serviceWorkerRegistration = await navigator.serviceWorker.ready;
|
// 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);
|
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}`));
|
reject(new Error(`Failed to send message to service worker: ${error}`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public batchWriting(payload: { storeName: string; objects: { key: any; object: any }[] }): Promise<void> {
|
public batchWriting(payload: { storeName: string; objects: { key: any; object: any }[] }): Promise<void> {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user