mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-02 04:48:57 +02:00
[PM-6426] Implementing foreground and background task scheduler services to avoid duplication of task scheudlers and to have the background setup as a fallback to the poopup tasks
This commit is contained in:
parent
d9b5353cfd
commit
d128a26fec
@ -19,21 +19,6 @@ export class BackgroundTaskSchedulerService extends BrowserTaskSchedulerServiceI
|
|||||||
BrowserApi.addListener(chrome.runtime.onConnect, this.handlePortOnConnect);
|
BrowserApi.addListener(chrome.runtime.onConnect, this.handlePortOnConnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears a scheduled alarm and sends a message to all ports to clear the alarm.
|
|
||||||
*
|
|
||||||
* @param alarmName - The name of the alarm.
|
|
||||||
*/
|
|
||||||
async clearScheduledAlarm(alarmName: string): Promise<void> {
|
|
||||||
void super.clearScheduledAlarm(alarmName);
|
|
||||||
const taskName = this.getTaskFromAlarmName(alarmName);
|
|
||||||
this.sendMessageToPorts({
|
|
||||||
action: BrowserTaskSchedulerPortActions.clearAlarm,
|
|
||||||
taskName,
|
|
||||||
alarmName,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a port connection made from the foreground task scheduler.
|
* Handles a port connection made from the foreground task scheduler.
|
||||||
*
|
*
|
||||||
@ -84,13 +69,4 @@ export class BackgroundTaskSchedulerService extends BrowserTaskSchedulerServiceI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a message to all ports.
|
|
||||||
*
|
|
||||||
* @param message - The message to send.
|
|
||||||
*/
|
|
||||||
private sendMessageToPorts(message: BrowserTaskSchedulerPortMessage) {
|
|
||||||
this.ports.forEach((port) => port.postMessage(message));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ export class ForegroundTaskSchedulerService extends BrowserTaskSchedulerServiceI
|
|||||||
super(logService, stateProvider);
|
super(logService, stateProvider);
|
||||||
|
|
||||||
this.port = chrome.runtime.connect({ name: BrowserTaskSchedulerPortName });
|
this.port = chrome.runtime.connect({ name: BrowserTaskSchedulerPortName });
|
||||||
this.port.onMessage.addListener(this.handlePortMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,25 +60,6 @@ export class ForegroundTaskSchedulerService extends BrowserTaskSchedulerServiceI
|
|||||||
return super.setInterval(taskName, intervalInMs, initialDelayInMs);
|
return super.setInterval(taskName, intervalInMs, initialDelayInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles port messages from the background task scheduler.
|
|
||||||
*
|
|
||||||
* @param message - The message that indicates we should clear an alarm.
|
|
||||||
* @param port - The port that the message was received on.
|
|
||||||
*/
|
|
||||||
private handlePortMessage = (
|
|
||||||
message: BrowserTaskSchedulerPortMessage,
|
|
||||||
port: chrome.runtime.Port,
|
|
||||||
) => {
|
|
||||||
if (port.name !== BrowserTaskSchedulerPortName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.action === BrowserTaskSchedulerPortActions.clearAlarm) {
|
|
||||||
void super.clearScheduledAlarm(message.alarmName);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to the background task scheduler.
|
* Sends a message to the background task scheduler.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user