Fix addObject

This commit is contained in:
NicolasCantu 2025-02-13 10:20:12 +01:00
parent 9dda743ba0
commit d6de96910a

View File

@ -229,13 +229,15 @@ export class Database {
};
public addObject(payload: { storeName: string; object: any; key: any }): Promise<void> {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
// Check if the service worker is active
if (!this.serviceWorkerRegistration?.active) {
reject(new Error('Service worker is not active'));
return;
if (!this.serviceWorkerRegistration) {
// console.warn('Service worker registration is not ready. Waiting...');
this.serviceWorkerRegistration = await navigator.serviceWorker.ready;
}
const activeWorker = await this.waitForServiceWorkerActivation(this.serviceWorkerRegistration);
// Create a message channel for communication
const messageChannel = new MessageChannel();
@ -251,7 +253,7 @@ export class Database {
// Send the add object request to the service worker
try {
this.serviceWorkerRegistration.active.postMessage(
activeWorker?.postMessage(
{
type: 'ADD_OBJECT',
payload,