From 8372c838447470e3354c0f73021c9b1e75389d26 Mon Sep 17 00:00:00 2001 From: Nicholas Wehrhan Date: Mon, 2 Dec 2024 22:34:47 +0100 Subject: [PATCH] Add clear all jobs and cast alarms to jobs --- packages/job-scheduler/src/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/job-scheduler/src/index.ts b/packages/job-scheduler/src/index.ts index 5917351..cd2bc6f 100644 --- a/packages/job-scheduler/src/index.ts +++ b/packages/job-scheduler/src/index.ts @@ -92,6 +92,11 @@ export interface JobScheduler { */ removeJob(jobId: string): Promise; + /** + * Un-schedules all jobs + */ + removeAllJobs(): Promise; + /** * Listen for a job to finish successfully. */ @@ -235,8 +240,10 @@ export function defineJobScheduler(options?: JobSchedulerConfig): JobScheduler { } async function listJobs() { - logger?.debug('Listing jobs: '); - return await browser.alarms.getAll(); + logger?.debug('Listing jobs'); + const alarms = await browser.alarms.getAll(); + + return alarms.map(alarm => jobs[alarm.name]); } /** @@ -270,6 +277,10 @@ export function defineJobScheduler(options?: JobSchedulerConfig): JobScheduler { await browser.alarms.clear(jobId); }, + async removeAllJobs() { + await browser.alarms.clearAll(); + }, + on(event, callback) { const listeners = event === 'success' ? successListeners : errorListeners; listeners.push(callback);