diff --git a/jslib b/jslib index e372bf242b..92a65b7b36 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit e372bf242b24f55c1142e33693ad2c801ab74c93 +Subproject commit 92a65b7b368a8dbf55350657674c90169b04c30b diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 074fdc47a3..6ffeb0dd17 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -24,6 +24,7 @@ import { ContainerService } from "jslib-common/services/container.service"; import { CryptoService } from "jslib-common/services/crypto.service"; import { EventService as EventLoggingService } from "jslib-common/services/event.service"; import { ImportService } from "jslib-common/services/import.service"; +import { StateMigrationService } from "jslib-common/services/stateMigration.service"; import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service"; import { ApiService as ApiServiceAbstraction } from "jslib-common/abstractions/api.service"; @@ -52,13 +53,14 @@ import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "jslib-com import { ThemeType } from "jslib-common/enums/themeType"; -import { AccountFactory } from "jslib-common/models/domain/account"; - import { Account } from "../../models/account"; +import { GlobalState } from "../../models/globalState"; + +import { GlobalStateFactory } from "jslib-common/factories/globalStateFactory"; +import { StateFactory } from "jslib-common/factories/stateFactory"; export function initFactory( window: Window, - storageService: StorageServiceAbstraction, environmentService: EnvironmentServiceAbstraction, notificationsService: NotificationsServiceAbstraction, vaultTimeoutService: VaultTimeoutService, @@ -70,7 +72,6 @@ export function initFactory( cryptoService: CryptoServiceAbstraction ): Function { return async () => { - await (storageService as HtmlStorageService).init(); await stateService.init(); const urls = process.env.URLS as Urls; @@ -110,7 +111,6 @@ export function initFactory( useFactory: initFactory, deps: [ "WINDOW", - StorageServiceAbstraction, EnvironmentServiceAbstraction, NotificationsServiceAbstraction, VaultTimeoutServiceAbstraction, @@ -180,6 +180,19 @@ export function initFactory( StateServiceAbstraction, ], }, + { + provide: StateMigrationServiceAbstraction, + useFactory: ( + storageService: StorageServiceAbstraction, + secureStorageService: StorageServiceAbstraction + ) => + new StateMigrationService( + storageService, + secureStorageService, + new GlobalStateFactory(GlobalState) + ), + deps: [StorageServiceAbstraction, "SECURE_STORAGE"], + }, { provide: StateServiceAbstraction, useFactory: ( @@ -193,7 +206,7 @@ export function initFactory( secureStorageService, logService, stateMigrationService, - new AccountFactory(Account) + new StateFactory(GlobalState, Account) ), deps: [ StorageServiceAbstraction, diff --git a/src/models/globalState.ts b/src/models/globalState.ts new file mode 100644 index 0000000000..620c1124d8 --- /dev/null +++ b/src/models/globalState.ts @@ -0,0 +1,7 @@ +import { ThemeType } from "jslib-common/enums/themeType"; + +import { GlobalState as BaseGlobalState } from "jslib-common/models/domain/globalState"; + +export class GlobalState extends BaseGlobalState { + theme?: ThemeType = ThemeType.Light; +} diff --git a/src/services/htmlStorage.service.ts b/src/services/htmlStorage.service.ts index 40572753ed..e55667bc91 100644 --- a/src/services/htmlStorage.service.ts +++ b/src/services/htmlStorage.service.ts @@ -4,8 +4,6 @@ import { StorageService } from "jslib-common/abstractions/storage.service"; import { HtmlStorageLocation } from "jslib-common/enums/htmlStorageLocation"; -import { GlobalState } from "jslib-common/models/domain/globalState"; -import { State } from "jslib-common/models/domain/state"; import { StorageOptions } from "jslib-common/models/domain/storageOptions"; @Injectable() @@ -14,16 +12,6 @@ export class HtmlStorageService implements StorageService { return { htmlStorageLocation: HtmlStorageLocation.Session }; } - async init() { - const state = - (await this.get("state", { htmlStorageLocation: HtmlStorageLocation.Local })) ?? - new State(); - state.globals = state.globals ?? new GlobalState(); - state.globals.vaultTimeout = state.globals.vaultTimeout ?? 15; - state.globals.vaultTimeoutAction = state.globals.vaultTimeoutAction ?? "lock"; - await this.save("state", state, { htmlStorageLocation: HtmlStorageLocation.Local }); - } - get(key: string, options: StorageOptions = this.defaultOptions): Promise { let json: string = null; switch (options.htmlStorageLocation) {