[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:
Cesar Gonzalez 2024-05-11 20:34:46 -05:00
parent d9b5353cfd
commit d128a26fec
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
2 changed files with 0 additions and 44 deletions

View File

@ -19,21 +19,6 @@ export class BackgroundTaskSchedulerService extends BrowserTaskSchedulerServiceI
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.
*
@ -84,13 +69,4 @@ export class BackgroundTaskSchedulerService extends BrowserTaskSchedulerServiceI
return;
}
};
/**
* Sends a message to all ports.
*
* @param message - The message to send.
*/
private sendMessageToPorts(message: BrowserTaskSchedulerPortMessage) {
this.ports.forEach((port) => port.postMessage(message));
}
}

View File

@ -19,7 +19,6 @@ export class ForegroundTaskSchedulerService extends BrowserTaskSchedulerServiceI
super(logService, stateProvider);
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);
}
/**
* 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.
*