From 5f2693524e78d009db113f3b607acfb650ca929c Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 29 Dec 2025 10:58:32 -0600 Subject: [PATCH] Consolidate references to credential provider feature flag --- .../services/desktop-autofill.service.ts | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/apps/desktop/src/autofill/services/desktop-autofill.service.ts b/apps/desktop/src/autofill/services/desktop-autofill.service.ts index c50964e31e3..64bebc3b557 100644 --- a/apps/desktop/src/autofill/services/desktop-autofill.service.ts +++ b/apps/desktop/src/autofill/services/desktop-autofill.service.ts @@ -10,6 +10,7 @@ import { mergeMap, switchMap, takeUntil, + tap, } from "rxjs"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; @@ -52,6 +53,8 @@ import type { NativeWindowObject } from "./desktop-fido2-user-interface.service" export class DesktopAutofillService implements OnDestroy { private destroy$ = new Subject(); private registrationRequest: autofill.PasskeyRegistrationRequest; + private featureFlag?: FeatureFlag; + private isEnabled: boolean = false; constructor( private logService: LogService, @@ -60,19 +63,25 @@ export class DesktopAutofillService implements OnDestroy { private fido2AuthenticatorService: Fido2AuthenticatorServiceAbstraction, private accountService: AccountService, private authService: AuthService, - private platformUtilsService: PlatformUtilsService, - ) {} + platformUtilsService: PlatformUtilsService, + ) { + const deviceType = platformUtilsService.getDevice() + if (deviceType === DeviceType.MacOsDesktop) { + this.featureFlag = FeatureFlag.MacOsNativeCredentialSync; + } + } async init() { - // Currently only supported for MacOS - if (this.platformUtilsService.getDevice() !== DeviceType.MacOsDesktop) { + this.isEnabled = this.featureFlag && await this.configService.getFeatureFlag(this.featureFlag); + if (!this.isEnabled) { return; } this.configService - .getFeatureFlag$(FeatureFlag.MacOsNativeCredentialSync) + .getFeatureFlag$(this.featureFlag) .pipe( distinctUntilChanged(), + tap((enabled) => this.isEnabled = enabled), filter((enabled) => enabled === true), // Only proceed if feature is enabled switchMap(() => { return combineLatest([ @@ -199,11 +208,11 @@ export class DesktopAutofillService implements OnDestroy { listenIpc() { ipc.autofill.listenPasskeyRegistration(async (clientId, sequenceNumber, request, callback) => { - if (!(await this.configService.getFeatureFlag(FeatureFlag.MacOsNativeCredentialSync))) { + if (!this.isEnabled) { this.logService.debug( - "listenPasskeyRegistration: MacOsNativeCredentialSync feature flag is disabled", + "listenPasskeyRegistration: Native credential sync feature flag is disabled", ); - callback(new Error("MacOsNativeCredentialSync feature flag is disabled"), null); + callback(new Error("Native credential sync feature flag is disabled"), null); return; } @@ -230,11 +239,11 @@ export class DesktopAutofillService implements OnDestroy { ipc.autofill.listenPasskeyAssertionWithoutUserInterface( async (clientId, sequenceNumber, request, callback) => { - if (!(await this.configService.getFeatureFlag(FeatureFlag.MacOsNativeCredentialSync))) { + if (!this.isEnabled) { this.logService.debug( - "listenPasskeyAssertionWithoutUserInterface: MacOsNativeCredentialSync feature flag is disabled", + "listenPasskeyAssertionWithoutUserInterface: Native credential sync feature flag is disabled", ); - callback(new Error("MacOsNativeCredentialSync feature flag is disabled"), null); + callback(new Error("Native credential sync feature flag is disabled"), null); return; } @@ -297,11 +306,11 @@ export class DesktopAutofillService implements OnDestroy { ); ipc.autofill.listenPasskeyAssertion(async (clientId, sequenceNumber, request, callback) => { - if (!(await this.configService.getFeatureFlag(FeatureFlag.MacOsNativeCredentialSync))) { + if (!await this.isEnabled) { this.logService.debug( - "listenPasskeyAssertion: MacOsNativeCredentialSync feature flag is disabled", + "listenPasskeyAssertion: Native credential sync feature flag is disabled", ); - callback(new Error("MacOsNativeCredentialSync feature flag is disabled"), null); + callback(new Error("Native credential sync feature flag is disabled"), null); return; } @@ -324,9 +333,9 @@ export class DesktopAutofillService implements OnDestroy { // Listen for native status messages ipc.autofill.listenNativeStatus(async (clientId, sequenceNumber, status) => { - if (!(await this.configService.getFeatureFlag(FeatureFlag.MacOsNativeCredentialSync))) { + if (!await this.isEnabled) { this.logService.debug( - "listenNativeStatus: MacOsNativeCredentialSync feature flag is disabled", + "listenNativeStatus: Native credential sync feature flag is disabled", ); return; }