Add foregroundvaulttimeout service and remove getbgservice call for vaulttimeout service (#10071)

This commit is contained in:
Bernd Schoolmann 2024-07-12 14:32:01 +02:00 committed by GitHub
parent 91dc9f49a5
commit 486176a648
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View File

@ -233,6 +233,9 @@ export default class RuntimeBackground {
case "addToLockedVaultPendingNotifications": case "addToLockedVaultPendingNotifications":
this.lockedVaultPendingNotifications.push(msg.data); this.lockedVaultPendingNotifications.push(msg.data);
break; break;
case "lockVault":
await this.main.vaultTimeoutService.lock(msg.userId);
break;
case "logout": case "logout":
await this.main.logout(msg.expired, msg.userId); await this.main.logout(msg.expired, msg.userId);
break; break;

View File

@ -50,6 +50,7 @@ import { FileDownloadService } from "@bitwarden/common/platform/abstractions/fil
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service";
import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/key-generation.service"; import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/key-generation.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.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 { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { import {
@ -104,6 +105,7 @@ import { ForegroundPlatformUtilsService } from "../../platform/services/platform
import { BrowserStorageServiceProvider } from "../../platform/storage/browser-storage-service.provider"; import { BrowserStorageServiceProvider } from "../../platform/storage/browser-storage-service.provider";
import { ForegroundMemoryStorageService } from "../../platform/storage/foreground-memory-storage.service"; import { ForegroundMemoryStorageService } from "../../platform/storage/foreground-memory-storage.service";
import { fromChromeRuntimeMessaging } from "../../platform/utils/from-chrome-runtime-messaging"; 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 { BrowserSendStateService } from "../../tools/popup/services/browser-send-state.service";
import { FilePopoutUtilsService } from "../../tools/popup/services/file-popout-utils.service"; import { FilePopoutUtilsService } from "../../tools/popup/services/file-popout-utils.service";
import { Fido2UserVerificationService } from "../../vault/services/fido2-user-verification.service"; import { Fido2UserVerificationService } from "../../vault/services/fido2-user-verification.service";
@ -320,8 +322,8 @@ const safeProviders: SafeProvider[] = [
}), }),
safeProvider({ safeProvider({
provide: VaultTimeoutService, provide: VaultTimeoutService,
useFactory: getBgService<VaultTimeoutService>("vaultTimeoutService"), useClass: ForegroundVaultTimeoutService,
deps: [], deps: [MessagingServiceAbstraction],
}), }),
safeProvider({ safeProvider({
provide: NotificationsService, provide: NotificationsService,

View File

@ -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<void> {}
async lock(userId?: UserId): Promise<void> {
this.messagingService.send("lockVault", { userId });
}
async logOut(userId?: string): Promise<void> {
this.messagingService.send("logout", { userId });
}
}