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') {
|
if (data.type === 'UPDATE_PROCESSES') {
|
||||||
try {
|
try {
|
||||||
const { processIds } = data.payload;
|
const { myProcessesId } = data.payload;
|
||||||
console.log(processIds);
|
console.log(myProcessesId);
|
||||||
if (processIds && processIds.length != 0) {
|
if (myProcessesId && myProcessesId.length != 0) {
|
||||||
for (const processId of processIds) {
|
for (const processId of myProcessesId) {
|
||||||
processesToScan.add(processId);
|
processesToScan.add(processId);
|
||||||
}
|
}
|
||||||
console.log(processesToScan);
|
console.log(processesToScan);
|
||||||
|
@ -202,6 +202,44 @@ class Database {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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> {
|
public async getObject(storeName: string, key: string): Promise<any | null> {
|
||||||
const db = await this.getDb();
|
const db = await this.getDb();
|
||||||
const tx = db.transaction(storeName, 'readonly');
|
const tx = db.transaction(storeName, 'readonly');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user