mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
[PM-5568] Implement Badge Settings state provider (#8112)
* create badge settings state provider * replace state service get/set disableBadgeCounter with badge settings service equivalent * migrate disableBadgeCounter account setting to badge settings state provider * cleanup and address PR suggestions
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { BadgeSettingsService } from "@bitwarden/common/autofill/services/badge-settings.service";
|
||||
|
||||
import {
|
||||
CachedServices,
|
||||
factory,
|
||||
FactoryOptions,
|
||||
} from "../../../platform/background/service-factories/factory-options";
|
||||
import {
|
||||
stateProviderFactory,
|
||||
StateProviderInitOptions,
|
||||
} from "../../../platform/background/service-factories/state-provider.factory";
|
||||
|
||||
export type BadgeSettingsServiceInitOptions = FactoryOptions & StateProviderInitOptions;
|
||||
|
||||
export function badgeSettingsServiceFactory(
|
||||
cache: { badgeSettingsService?: BadgeSettingsService } & CachedServices,
|
||||
opts: BadgeSettingsServiceInitOptions,
|
||||
): Promise<BadgeSettingsService> {
|
||||
return factory(
|
||||
cache,
|
||||
"badgeSettingsService",
|
||||
opts,
|
||||
async () => new BadgeSettingsService(await stateProviderFactory(cache, opts)),
|
||||
);
|
||||
}
|
||||
@@ -49,6 +49,10 @@ import {
|
||||
AutofillSettingsServiceAbstraction,
|
||||
AutofillSettingsService,
|
||||
} from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||
import {
|
||||
BadgeSettingsServiceAbstraction,
|
||||
BadgeSettingsService,
|
||||
} from "@bitwarden/common/autofill/services/badge-settings.service";
|
||||
import { AppIdService as AppIdServiceAbstraction } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||
import { ConfigApiServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config-api.service.abstraction";
|
||||
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||
@@ -243,6 +247,7 @@ export default class MainBackground {
|
||||
notificationsService: NotificationsServiceAbstraction;
|
||||
stateService: StateServiceAbstraction;
|
||||
autofillSettingsService: AutofillSettingsServiceAbstraction;
|
||||
badgeSettingsService: BadgeSettingsServiceAbstraction;
|
||||
systemService: SystemServiceAbstraction;
|
||||
eventCollectionService: EventCollectionServiceAbstraction;
|
||||
eventUploadService: EventUploadServiceAbstraction;
|
||||
@@ -482,6 +487,7 @@ export default class MainBackground {
|
||||
this.stateProvider,
|
||||
this.policyService,
|
||||
);
|
||||
this.badgeSettingsService = new BadgeSettingsService(this.stateProvider);
|
||||
this.policyApiService = new PolicyApiService(
|
||||
this.policyService,
|
||||
this.apiService,
|
||||
@@ -1079,7 +1085,10 @@ export default class MainBackground {
|
||||
this.keyConnectorService.clear(),
|
||||
this.vaultFilterService.clear(),
|
||||
this.biometricStateService.logout(userId),
|
||||
// We intentionally do not clear the autofillSettingsService
|
||||
/* We intentionally do not clear:
|
||||
* - autofillSettingsService
|
||||
* - badgeSettingsService
|
||||
*/
|
||||
]);
|
||||
|
||||
//Needs to be checked before state is cleaned
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
import { BadgeSettingsService } from "@bitwarden/common/autofill/services/badge-settings.service";
|
||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
|
||||
@@ -9,9 +12,8 @@ import { ContainerService } from "@bitwarden/common/platform/services/container.
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
|
||||
import { authServiceFactory } from "../../auth/background/service-factories/auth-service.factory";
|
||||
import { badgeSettingsServiceFactory } from "../../autofill/background/service_factories/badge-settings-service.factory";
|
||||
import { Account } from "../../models/account";
|
||||
import { stateServiceFactory } from "../../platform/background/service-factories/state-service.factory";
|
||||
import { BrowserStateService } from "../../platform/services/abstractions/browser-state.service";
|
||||
import IconDetails from "../../vault/background/models/icon-details";
|
||||
import { cipherServiceFactory } from "../../vault/background/service_factories/cipher-service.factory";
|
||||
import { BrowserApi } from "../browser/browser-api";
|
||||
@@ -24,7 +26,7 @@ export type BadgeOptions = {
|
||||
|
||||
export class UpdateBadge {
|
||||
private authService: AuthService;
|
||||
private stateService: BrowserStateService;
|
||||
private badgeSettingsService: BadgeSettingsService;
|
||||
private cipherService: CipherService;
|
||||
private badgeAction: typeof chrome.action | typeof chrome.browserAction;
|
||||
private sidebarAction: OperaSidebarAction | FirefoxSidebarAction;
|
||||
@@ -152,8 +154,8 @@ export class UpdateBadge {
|
||||
|
||||
await this.setBadgeIcon("");
|
||||
|
||||
const disableBadgeCounter = await this.stateService.getDisableBadgeCounter();
|
||||
if (disableBadgeCounter) {
|
||||
const enableBadgeCounter = await firstValueFrom(this.badgeSettingsService.enableBadgeCounter$);
|
||||
if (!enableBadgeCounter) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -290,7 +292,7 @@ export class UpdateBadge {
|
||||
systemLanguage: BrowserApi.getUILanguage(),
|
||||
},
|
||||
};
|
||||
this.stateService = await stateServiceFactory(serviceCache, opts);
|
||||
this.badgeSettingsService = await badgeSettingsServiceFactory(serviceCache, opts);
|
||||
this.authService = await authServiceFactory(serviceCache, opts);
|
||||
this.cipherService = await cipherServiceFactory(serviceCache, opts);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { firstValueFrom } from "rxjs";
|
||||
import { AbstractThemingService } from "@bitwarden/angular/platform/services/theming/theming.service.abstraction";
|
||||
import { SettingsService } from "@bitwarden/common/abstractions/settings.service";
|
||||
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||
import { BadgeSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/badge-settings.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||
@@ -20,7 +21,7 @@ import { enableAccountSwitching } from "../../platform/flags";
|
||||
})
|
||||
export class OptionsComponent implements OnInit {
|
||||
enableFavicon = false;
|
||||
enableBadgeCounter = false;
|
||||
enableBadgeCounter = true;
|
||||
enableAutoFillOnPageLoad = false;
|
||||
autoFillOnPageLoadDefault = false;
|
||||
autoFillOnPageLoadOptions: any[];
|
||||
@@ -47,6 +48,7 @@ export class OptionsComponent implements OnInit {
|
||||
private messagingService: MessagingService,
|
||||
private stateService: StateService,
|
||||
private autofillSettingsService: AutofillSettingsServiceAbstraction,
|
||||
private badgeSettingsService: BadgeSettingsServiceAbstraction,
|
||||
i18nService: I18nService,
|
||||
private themingService: AbstractThemingService,
|
||||
private settingsService: SettingsService,
|
||||
@@ -107,7 +109,7 @@ export class OptionsComponent implements OnInit {
|
||||
|
||||
this.enableFavicon = !this.settingsService.getDisableFavicon();
|
||||
|
||||
this.enableBadgeCounter = !(await this.stateService.getDisableBadgeCounter());
|
||||
this.enableBadgeCounter = await firstValueFrom(this.badgeSettingsService.enableBadgeCounter$);
|
||||
|
||||
this.enablePasskeys = await firstValueFrom(this.vaultSettingsService.enablePasskeys$);
|
||||
|
||||
@@ -155,7 +157,7 @@ export class OptionsComponent implements OnInit {
|
||||
}
|
||||
|
||||
async updateBadgeCounter() {
|
||||
await this.stateService.setDisableBadgeCounter(!this.enableBadgeCounter);
|
||||
await this.badgeSettingsService.setEnableBadgeCounter(this.enableBadgeCounter);
|
||||
this.messagingService.send("bgUpdateContextMenu");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user