Fix addObject
This commit is contained in:
parent
9dda743ba0
commit
d6de96910a
@ -229,13 +229,15 @@ export class Database {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public addObject(payload: { storeName: string; object: any; key: any }): Promise<void> {
|
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
|
// Check if the service worker is active
|
||||||
if (!this.serviceWorkerRegistration?.active) {
|
if (!this.serviceWorkerRegistration) {
|
||||||
reject(new Error('Service worker is not active'));
|
// console.warn('Service worker registration is not ready. Waiting...');
|
||||||
return;
|
this.serviceWorkerRegistration = await navigator.serviceWorker.ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const activeWorker = await this.waitForServiceWorkerActivation(this.serviceWorkerRegistration);
|
||||||
|
|
||||||
// Create a message channel for communication
|
// Create a message channel for communication
|
||||||
const messageChannel = new MessageChannel();
|
const messageChannel = new MessageChannel();
|
||||||
|
|
||||||
@ -251,7 +253,7 @@ export class Database {
|
|||||||
|
|
||||||
// Send the add object request to the service worker
|
// Send the add object request to the service worker
|
||||||
try {
|
try {
|
||||||
this.serviceWorkerRegistration.active.postMessage(
|
activeWorker?.postMessage(
|
||||||
{
|
{
|
||||||
type: 'ADD_OBJECT',
|
type: 'ADD_OBJECT',
|
||||||
payload,
|
payload,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user