diff --git a/apps/browser/src/platform/services/browser-task-scheduler.service.ts b/apps/browser/src/platform/services/browser-task-scheduler.service.ts index 50a3ff4490..50375c4361 100644 --- a/apps/browser/src/platform/services/browser-task-scheduler.service.ts +++ b/apps/browser/src/platform/services/browser-task-scheduler.service.ts @@ -3,7 +3,7 @@ import { firstValueFrom, map, Observable } from "rxjs"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { TaskIdentifier } from "@bitwarden/common/platform/abstractions/task-scheduler.service"; import { ScheduledTaskName } from "@bitwarden/common/platform/enums/scheduled-task-name.enum"; -import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service"; +import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service"; import { TASK_SCHEDULER_DISK, GlobalState, @@ -23,7 +23,7 @@ const ACTIVE_ALARMS = new KeyDefinition(TASK_SCHEDULER_DISK, "activeAlarms", { }); export class BrowserTaskSchedulerService - extends TaskSchedulerService + extends DefaultTaskSchedulerService implements BrowserTaskSchedulerServiceInterface { private activeAlarmsState: GlobalState; diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 4c6e73e122..660bf6509c 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -64,12 +64,12 @@ import { AbstractStorageService, ObservableStorageService, } from "@bitwarden/common/platform/abstractions/storage.service"; +import { TaskSchedulerService } from "@bitwarden/common/platform/abstractions/task-scheduler.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; import { ContainerService } from "@bitwarden/common/platform/services/container.service"; import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; -import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; import { DerivedStateProvider, diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index 4de4b589d3..9f26c4c8d7 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -40,13 +40,14 @@ import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwar import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service"; +import { TaskSchedulerService } from "@bitwarden/common/platform/abstractions/task-scheduler.service"; import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; +import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service"; import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service"; import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; import { SystemService } from "@bitwarden/common/platform/services/system.service"; -import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service"; import { GlobalStateProvider, StateProvider } from "@bitwarden/common/platform/state"; // eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@bitwarden/common/platform/state/storage/memory-storage.service"; @@ -253,6 +254,7 @@ const safeProviders: SafeProvider[] = [ }), safeProvider({ provide: TaskSchedulerService, + useClass: DefaultTaskSchedulerService, deps: [], }), ]; diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 79d5f438ab..9b528827a2 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -130,6 +130,7 @@ import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/comm import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; +import { TaskSchedulerService } from "@bitwarden/common/platform/abstractions/task-scheduler.service"; import { ValidationService as ValidationServiceAbstraction } from "@bitwarden/common/platform/abstractions/validation.service"; import { BiometricStateService, @@ -147,6 +148,7 @@ import { CryptoService } from "@bitwarden/common/platform/services/crypto.servic import { EncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/encrypt.service.implementation"; import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/multithread-encrypt.service.implementation"; import { DefaultEnvironmentService } from "@bitwarden/common/platform/services/default-environment.service"; +import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service"; import { FileUploadService } from "@bitwarden/common/platform/services/file-upload/file-upload.service"; import { KeyGenerationService } from "@bitwarden/common/platform/services/key-generation.service"; import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service"; @@ -154,7 +156,6 @@ import { MigrationRunner } from "@bitwarden/common/platform/services/migration-r import { NoopNotificationsService } from "@bitwarden/common/platform/services/noop-notifications.service"; import { StateService } from "@bitwarden/common/platform/services/state.service"; import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider"; -import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service"; import { ValidationService } from "@bitwarden/common/platform/services/validation.service"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; import { @@ -1128,6 +1129,7 @@ const safeProviders: SafeProvider[] = [ }), safeProvider({ provide: TaskSchedulerService, + useClass: DefaultTaskSchedulerService, deps: [], }), safeProvider({ diff --git a/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts b/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts index cbe42f3236..657e0fb92d 100644 --- a/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts +++ b/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts @@ -23,7 +23,7 @@ import { MessagingService } from "@bitwarden/common/platform/abstractions/messag import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { KdfType } from "@bitwarden/common/platform/enums"; -import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service"; +import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service"; import { FakeAccountService, FakeGlobalState, @@ -67,7 +67,7 @@ describe("LoginStrategyService", () => { let authRequestService: MockProxy; let userDecryptionOptionsService: MockProxy; let billingAccountProfileStateService: MockProxy; - let taskSchedulerService: MockProxy; + let taskSchedulerService: MockProxy; let stateProvider: FakeGlobalStateProvider; let loginStrategyCacheExpirationState: FakeGlobalState; @@ -97,7 +97,7 @@ describe("LoginStrategyService", () => { userDecryptionOptionsService = mock(); billingAccountProfileStateService = mock(); stateProvider = new FakeGlobalStateProvider(); - taskSchedulerService = mock(); + taskSchedulerService = mock(); sut = new LoginStrategyService( accountService, diff --git a/libs/common/src/platform/abstractions/task-scheduler.service.ts b/libs/common/src/platform/abstractions/task-scheduler.service.ts index 94312a21be..424de64de1 100644 --- a/libs/common/src/platform/abstractions/task-scheduler.service.ts +++ b/libs/common/src/platform/abstractions/task-scheduler.service.ts @@ -6,17 +6,17 @@ export type TaskIdentifier = { intervalId?: number | NodeJS.Timeout; }; -export interface TaskSchedulerService { - setTimeout( +export abstract class TaskSchedulerService { + abstract setTimeout( callback: () => void, delayInMs: number, taskName?: ScheduledTaskName, ): Promise; - setInterval( + abstract setInterval( callback: () => void, intervalInMs: number, taskName?: ScheduledTaskName, initialDelayInMs?: number, ): Promise; - clearScheduledTask(taskIdentifier: TaskIdentifier): Promise; + abstract clearScheduledTask(taskIdentifier: TaskIdentifier): Promise; } diff --git a/libs/common/src/platform/services/task-scheduler.service.spec.ts b/libs/common/src/platform/services/default-task-scheduler.service.spec.ts similarity index 90% rename from libs/common/src/platform/services/task-scheduler.service.spec.ts rename to libs/common/src/platform/services/default-task-scheduler.service.spec.ts index e69e2a3648..9da947a7fd 100644 --- a/libs/common/src/platform/services/task-scheduler.service.spec.ts +++ b/libs/common/src/platform/services/default-task-scheduler.service.spec.ts @@ -1,14 +1,14 @@ -import { TaskSchedulerService } from "./task-scheduler.service"; +import { DefaultTaskSchedulerService } from "./default-task-scheduler.service"; describe("TaskSchedulerService", () => { const callback = jest.fn(); const delayInMs = 1000; const intervalInMs = 1100; - let taskSchedulerService: TaskSchedulerService; + let taskSchedulerService: DefaultTaskSchedulerService; beforeEach(() => { jest.useFakeTimers(); - taskSchedulerService = new TaskSchedulerService(); + taskSchedulerService = new DefaultTaskSchedulerService(); }); afterEach(() => { diff --git a/libs/common/src/platform/services/task-scheduler.service.ts b/libs/common/src/platform/services/default-task-scheduler.service.ts similarity index 88% rename from libs/common/src/platform/services/task-scheduler.service.ts rename to libs/common/src/platform/services/default-task-scheduler.service.ts index 15c86d5abd..74068396fa 100644 --- a/libs/common/src/platform/services/task-scheduler.service.ts +++ b/libs/common/src/platform/services/default-task-scheduler.service.ts @@ -1,10 +1,7 @@ -import { - TaskIdentifier, - TaskSchedulerService as TaskSchedulerServiceInterface, -} from "../abstractions/task-scheduler.service"; +import { TaskIdentifier, TaskSchedulerService } from "../abstractions/task-scheduler.service"; import { ScheduledTaskName } from "../enums/scheduled-task-name.enum"; -export class TaskSchedulerService implements TaskSchedulerServiceInterface { +export class DefaultTaskSchedulerService extends TaskSchedulerService { /** * Sets a timeout and returns the timeout id. *