1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +00:00

[PM-5535] Migrate Environment Service to StateProvider (#7621)

* Migrate EnvironmentService

* Move Migration Test Helper

* Claim StateDefinition

* Add State Migration

* Update StateServices

* Update EnvironmentService Abstraction

* Update DI

* Update Browser Instantiation

* Fix BrowserEnvironmentService

* Update Desktop & CLI Instantiation

* Update Usage

* Create isStringRecord helper

* Fix Old Tests

* Use Existing AccountService

* Don't Rely on Parameter Mutation

* Fix Conflicts
This commit is contained in:
Justin Baur
2024-01-24 14:21:50 -05:00
committed by GitHub
parent 842fa5153b
commit c1d5351075
26 changed files with 648 additions and 232 deletions

View File

@@ -5,10 +5,16 @@ import { app } from "electron";
import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service";
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
import { EnvironmentService } from "@bitwarden/common/platform/services/environment.service";
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
import { NoopMessagingService } from "@bitwarden/common/platform/services/noop-messaging.service";
// eslint-disable-next-line import/no-restricted-paths -- We need the implementation to inject, but generally this should not be accessed
/* eslint-disable import/no-restricted-paths -- We need the implementation to inject, but generally this should not be accessed */
import { DefaultActiveUserStateProvider } from "@bitwarden/common/platform/state/implementations/default-active-user-state.provider";
import { DefaultDerivedStateProvider } from "@bitwarden/common/platform/state/implementations/default-derived-state.provider";
import { DefaultGlobalStateProvider } from "@bitwarden/common/platform/state/implementations/default-global-state.provider";
import { DefaultSingleUserStateProvider } from "@bitwarden/common/platform/state/implementations/default-single-user-state.provider";
import { DefaultStateProvider } from "@bitwarden/common/platform/state/implementations/default-state.provider";
/*/ eslint-enable import/no-restricted-paths */
import { MenuMain } from "./main/menu/menu.main";
import { MessagingMain } from "./main/messaging.main";
@@ -34,6 +40,7 @@ export class Main {
memoryStorageService: MemoryStorageService;
messagingService: ElectronMainMessagingService;
stateService: ElectronStateService;
environmentService: EnvironmentService;
desktopCredentialStorageListener: DesktopCredentialStorageListener;
windowMain: WindowMain;
@@ -93,6 +100,25 @@ export class Main {
this.storageService,
);
const accountService = new AccountServiceImplementation(
new NoopMessagingService(),
this.logService,
globalStateProvider,
);
const stateProvider = new DefaultStateProvider(
new DefaultActiveUserStateProvider(
accountService,
this.memoryStorageService,
this.storageService,
),
new DefaultSingleUserStateProvider(this.memoryStorageService, this.storageService),
globalStateProvider,
new DefaultDerivedStateProvider(this.memoryStorageService),
);
this.environmentService = new EnvironmentService(stateProvider, accountService);
// TODO: this state service will have access to on disk storage, but not in memory storage.
// If we could get this to work using the stateService singleton that the rest of the app uses we could save
// ourselves from some hacks, like having to manually update the app menu vs. the menu subscribing to events.
@@ -102,11 +128,8 @@ export class Main {
this.memoryStorageService,
this.logService,
new StateFactory(GlobalState, Account),
new AccountServiceImplementation(
new NoopMessagingService(),
this.logService,
globalStateProvider,
), // will not broadcast logouts. This is a hack until we can remove messaging dependency
accountService, // will not broadcast logouts. This is a hack until we can remove messaging dependency
this.environmentService,
false, // Do not use disk caching because this will get out of sync with the renderer service
);
@@ -128,7 +151,7 @@ export class Main {
this.menuMain = new MenuMain(
this.i18nService,
this.messagingService,
this.stateService,
this.environmentService,
this.windowMain,
this.updaterMain,
);