Add updateMyProcesses
This commit is contained in:
parent
cb2fea029e
commit
463f4d952c
@ -62,10 +62,10 @@ self.addEventListener('message', async (event) => {
|
||||
|
||||
if (data.type === 'UPDATE_PROCESSES') {
|
||||
try {
|
||||
const { processIds } = data.payload;
|
||||
console.log(processIds);
|
||||
if (processIds && processIds.length != 0) {
|
||||
for (const processId of processIds) {
|
||||
const { myProcessesId } = data.payload;
|
||||
console.log(myProcessesId);
|
||||
if (myProcessesId && myProcessesId.length != 0) {
|
||||
for (const processId of myProcessesId) {
|
||||
processesToScan.add(processId);
|
||||
}
|
||||
console.log(processesToScan);
|
||||
|
@ -200,6 +200,44 @@ class Database {
|
||||
reject(new Error(`Failed to send message to service worker: ${error}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public updateMyProcesses(payload: { myProcessesId: string[] }): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Check if the service worker is active
|
||||
if (!this.serviceWorkerRegistration?.active) {
|
||||
reject(new Error('Service worker is not active'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a message channel for communication
|
||||
const messageChannel = new MessageChannel();
|
||||
|
||||
// Handle the response from the service worker
|
||||
messageChannel.port1.onmessage = (event) => {
|
||||
if (event.data.status === 'success') {
|
||||
resolve();
|
||||
} else {
|
||||
const error = event.data.message;
|
||||
reject(new Error(error || 'Unknown error occurred while scanning our processes'));
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
console.log('Sending UPDATE_PROCESSES msg with payload', payload);
|
||||
this.serviceWorkerRegistration.active.postMessage(
|
||||
{
|
||||
type: 'UPDATE_PROCESSES',
|
||||
|
||||
payload,
|
||||
},
|
||||
[messageChannel.port2],
|
||||
|
||||
);
|
||||
} catch (error) {
|
||||
reject(new Error(`Failed to send message to service worker: ${error}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async getObject(storeName: string, key: string): Promise<any | null> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user