Add updateMyProcesses

This commit is contained in:
NicolasCantu 2025-02-11 09:15:01 +01:00
parent cb2fea029e
commit 463f4d952c
2 changed files with 42 additions and 4 deletions

View File

@ -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);

View File

@ -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> {