add experimental user settings service

This commit is contained in:
Jonathan Prusik 2024-10-04 16:45:38 -04:00
parent 1ca03e7815
commit 8e995da0d4
No known key found for this signature in database
GPG Key ID: 83CF2DF735A5EC35
4 changed files with 114 additions and 0 deletions

View File

@ -34,6 +34,10 @@ import {
AutofillSettingsService,
AutofillSettingsServiceAbstraction,
} from "@bitwarden/common/autofill/services/autofill-settings.service";
import {
LabsSettingsService,
LabsSettingsServiceAbstraction,
} from "@bitwarden/common/autofill/services/labs-settings.service";
import {
DefaultDomainSettingsService,
DomainSettingsService,
@ -453,6 +457,11 @@ const safeProviders: SafeProvider[] = [
useClass: AutofillSettingsService,
deps: [StateProvider, PolicyService],
}),
safeProvider({
provide: LabsSettingsServiceAbstraction,
useClass: LabsSettingsService,
deps: [StateProvider, ConfigService],
}),
safeProvider({
provide: UserNotificationSettingsServiceAbstraction,
useClass: UserNotificationSettingsService,

View File

@ -115,6 +115,10 @@ import {
AutofillSettingsServiceAbstraction,
AutofillSettingsService,
} from "@bitwarden/common/autofill/services/autofill-settings.service";
import {
LabsSettingsServiceAbstraction,
LabsSettingsService,
} from "@bitwarden/common/autofill/services/labs-settings.service";
import {
BadgeSettingsServiceAbstraction,
BadgeSettingsService,
@ -1205,6 +1209,11 @@ const safeProviders: SafeProvider[] = [
useClass: AutofillSettingsService,
deps: [StateProvider, PolicyServiceAbstraction],
}),
safeProvider({
provide: LabsSettingsServiceAbstraction,
useClass: LabsSettingsService,
deps: [StateProvider, ConfigService],
}),
safeProvider({
provide: BadgeSettingsServiceAbstraction,
useClass: BadgeSettingsService,

View File

@ -0,0 +1,92 @@
import { map, Observable, firstValueFrom } from "rxjs";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { devFlagEnabled } from "@bitwarden/common/platform/misc/flags";
import {
LABS_SETTINGS_DISK,
LABS_SETTINGS_DISK_LOCAL,
ActiveUserState,
GlobalState,
KeyDefinition,
StateProvider,
UserKeyDefinition,
} from "../../platform/state";
const LABS_SETTINGS_ENABLED = new UserKeyDefinition(LABS_SETTINGS_DISK, "labsSettingsEnabled", {
deserializer: (value: boolean) => value ?? false,
clearOn: [],
});
const IMPROVED_FIELD_QUALIFICATION_FOR_INLINE_MENU_ENABLED = new UserKeyDefinition(
LABS_SETTINGS_DISK,
"improvedFieldQualificationForInlineMenuEnabled",
{
deserializer: (value: boolean) => value ?? null,
clearOn: [],
},
);
const ADDITIONAL_INLINE_MENU_CIPHER_TYPES_ENABLED = new UserKeyDefinition(
LABS_SETTINGS_DISK,
"additionalInlineMenuCipherTypesEnabled",
{
deserializer: (value: boolean) => value ?? null,
clearOn: [],
},
);
export abstract class LabsSettingsServiceAbstraction {
labsSettingsEnabled$: Observable<boolean>;
setLabsSettingsEnabled: (newValue: boolean) => Promise<void>;
improvedFieldQualificationForInlineMenuEnabled$: Observable<boolean>;
setImprovedFieldQualificationForInlineMenuEnabled: (newValue: boolean) => Promise<void>;
additionalInlineMenuCipherTypesEnabled$: Observable<boolean>;
setAdditionalInlineMenuCipherTypesEnabled: (newValue: boolean) => Promise<void>;
}
export class LabsSettingsService implements LabsSettingsServiceAbstraction {
private labsSettingsEnabledState: ActiveUserState<boolean>;
readonly labsSettingsEnabled$: Observable<boolean>;
private improvedFieldQualificationForInlineMenuEnabledState: ActiveUserState<boolean>;
readonly improvedFieldQualificationForInlineMenuEnabled$: Observable<boolean>;
private additionalInlineMenuCipherTypesEnabledState: ActiveUserState<boolean>;
readonly additionalInlineMenuCipherTypesEnabled$: Observable<boolean>;
constructor(
private stateProvider: StateProvider,
private configService: ConfigService,
) {
this.labsSettingsEnabledState = this.stateProvider.getActive(LABS_SETTINGS_ENABLED);
this.labsSettingsEnabled$ = this.labsSettingsEnabledState.state$.pipe(map((x) => x ?? false));
this.improvedFieldQualificationForInlineMenuEnabledState = this.stateProvider.getActive(
IMPROVED_FIELD_QUALIFICATION_FOR_INLINE_MENU_ENABLED,
);
this.improvedFieldQualificationForInlineMenuEnabled$ =
this.improvedFieldQualificationForInlineMenuEnabledState.state$.pipe(map((x) => x ?? null));
this.additionalInlineMenuCipherTypesEnabledState = this.stateProvider.getActive(
ADDITIONAL_INLINE_MENU_CIPHER_TYPES_ENABLED,
);
this.additionalInlineMenuCipherTypesEnabled$ =
this.additionalInlineMenuCipherTypesEnabledState.state$.pipe(map((x) => x ?? null));
}
async init() {
}
async setLabsSettingsEnabled(newValue: boolean): Promise<void> {
await this.labsSettingsEnabledState.update(() => newValue);
}
// This setting may improve the accuracy of the inline menu appearing in login forms
async setImprovedFieldQualificationForInlineMenuEnabled(newValue: boolean): Promise<void> {
await this.improvedFieldQualificationForInlineMenuEnabledState.update(() => newValue);
}
// This flag turns on inline menu credit card and identity features
async setAdditionalInlineMenuCipherTypesEnabled(newValue: boolean): Promise<void> {
await this.additionalInlineMenuCipherTypesEnabledState.update(() => newValue);
}
}

View File

@ -85,6 +85,10 @@ export const USER_NOTIFICATION_SETTINGS_DISK = new StateDefinition(
"disk",
);
export const LABS_SETTINGS_DISK = new StateDefinition("labsSettings", "disk");
export const LABS_SETTINGS_DISK_LOCAL = new StateDefinition("labsSettingsLocal", "disk", {
web: "disk-local",
});
export const DOMAIN_SETTINGS_DISK = new StateDefinition("domainSettings", "disk");
export const AUTOFILL_SETTINGS_DISK = new StateDefinition("autofillSettings", "disk");
export const AUTOFILL_SETTINGS_DISK_LOCAL = new StateDefinition("autofillSettingsLocal", "disk", {