From 486176a6483575375a3fbba091da702a1335fd8d Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Fri, 12 Jul 2024 14:32:01 +0200 Subject: [PATCH] Add foregroundvaulttimeout service and remove getbgservice call for vaulttimeout service (#10071) --- .../src/background/runtime.background.ts | 3 +++ .../src/popup/services/services.module.ts | 6 ++++-- .../foreground-vault-timeout.service.ts | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 apps/browser/src/services/vault-timeout/foreground-vault-timeout.service.ts diff --git a/apps/browser/src/background/runtime.background.ts b/apps/browser/src/background/runtime.background.ts index 94e96e2dc8..ccf8205744 100644 --- a/apps/browser/src/background/runtime.background.ts +++ b/apps/browser/src/background/runtime.background.ts @@ -233,6 +233,9 @@ export default class RuntimeBackground { case "addToLockedVaultPendingNotifications": this.lockedVaultPendingNotifications.push(msg.data); break; + case "lockVault": + await this.main.vaultTimeoutService.lock(msg.userId); + break; case "logout": await this.main.logout(msg.expired, msg.userId); break; diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index b504996e00..b083c2f4c8 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -50,6 +50,7 @@ import { FileDownloadService } from "@bitwarden/common/platform/abstractions/fil import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service"; import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/key-generation.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; +import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { @@ -104,6 +105,7 @@ import { ForegroundPlatformUtilsService } from "../../platform/services/platform import { BrowserStorageServiceProvider } from "../../platform/storage/browser-storage-service.provider"; import { ForegroundMemoryStorageService } from "../../platform/storage/foreground-memory-storage.service"; import { fromChromeRuntimeMessaging } from "../../platform/utils/from-chrome-runtime-messaging"; +import { ForegroundVaultTimeoutService } from "../../services/vault-timeout/foreground-vault-timeout.service"; import { BrowserSendStateService } from "../../tools/popup/services/browser-send-state.service"; import { FilePopoutUtilsService } from "../../tools/popup/services/file-popout-utils.service"; import { Fido2UserVerificationService } from "../../vault/services/fido2-user-verification.service"; @@ -320,8 +322,8 @@ const safeProviders: SafeProvider[] = [ }), safeProvider({ provide: VaultTimeoutService, - useFactory: getBgService("vaultTimeoutService"), - deps: [], + useClass: ForegroundVaultTimeoutService, + deps: [MessagingServiceAbstraction], }), safeProvider({ provide: NotificationsService, diff --git a/apps/browser/src/services/vault-timeout/foreground-vault-timeout.service.ts b/apps/browser/src/services/vault-timeout/foreground-vault-timeout.service.ts new file mode 100644 index 0000000000..462e2149e8 --- /dev/null +++ b/apps/browser/src/services/vault-timeout/foreground-vault-timeout.service.ts @@ -0,0 +1,18 @@ +import { VaultTimeoutService as BaseVaultTimeoutService } from "@bitwarden/common/src/abstractions/vault-timeout/vault-timeout.service"; +import { MessagingService } from "@bitwarden/common/src/platform/abstractions/messaging.service"; +import { UserId } from "@bitwarden/common/src/types/guid"; + +export class ForegroundVaultTimeoutService implements BaseVaultTimeoutService { + constructor(protected messagingService: MessagingService) {} + + // should only ever run in background + async checkVaultTimeout(): Promise {} + + async lock(userId?: UserId): Promise { + this.messagingService.send("lockVault", { userId }); + } + + async logOut(userId?: string): Promise { + this.messagingService.send("logout", { userId }); + } +}