From ca5b057b43ddf1ad671385b589395a91acd808b6 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Fri, 28 Jan 2022 05:28:36 -0500 Subject: [PATCH] [refactor] Use ThemeType enum instead of string (#642) --- common/src/abstractions/state.service.ts | 5 +++-- common/src/models/domain/globalState.ts | 4 +++- common/src/services/state.service.ts | 5 +++-- common/src/services/stateMigration.service.ts | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/common/src/abstractions/state.service.ts b/common/src/abstractions/state.service.ts index bf00d744ff..e4c38025a4 100644 --- a/common/src/abstractions/state.service.ts +++ b/common/src/abstractions/state.service.ts @@ -1,6 +1,7 @@ import { BehaviorSubject } from "rxjs"; import { KdfType } from "../enums/kdfType"; +import { ThemeType } from "../enums/themeType"; import { UriMatchType } from "../enums/uriMatchType"; import { CipherData } from "../models/data/cipherData"; @@ -287,8 +288,8 @@ export abstract class StateService { setSsoOrganizationIdentifier: (value: string, options?: StorageOptions) => Promise; getSsoState: (options?: StorageOptions) => Promise; setSsoState: (value: string, options?: StorageOptions) => Promise; - getTheme: (options?: StorageOptions) => Promise; - setTheme: (value: string, options?: StorageOptions) => Promise; + getTheme: (options?: StorageOptions) => Promise; + setTheme: (value: ThemeType, options?: StorageOptions) => Promise; getTwoFactorToken: (options?: StorageOptions) => Promise; setTwoFactorToken: (value: string, options?: StorageOptions) => Promise; getUserId: (options?: StorageOptions) => Promise; diff --git a/common/src/models/domain/globalState.ts b/common/src/models/domain/globalState.ts index 4fb143351d..322f6d645f 100644 --- a/common/src/models/domain/globalState.ts +++ b/common/src/models/domain/globalState.ts @@ -1,4 +1,6 @@ import { StateVersion } from "../../enums/stateVersion"; +import { ThemeType } from "../../enums/themeType"; + import { EnvironmentUrls } from "./environmentUrls"; import { WindowState } from "./windowState"; @@ -11,7 +13,7 @@ export class GlobalState { ssoOrganizationIdentifier?: string; ssoState?: string; rememberedEmail?: string; - theme?: string = "light"; + theme?: ThemeType = ThemeType.Light; window?: WindowState = new WindowState(); twoFactorToken?: string; disableFavicon?: boolean; diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 0bacc5e8a6..e3a3c5350f 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -8,6 +8,7 @@ import { StorageService } from "../abstractions/storage.service"; import { HtmlStorageLocation } from "../enums/htmlStorageLocation"; import { KdfType } from "../enums/kdfType"; import { StorageLocation } from "../enums/storageLocation"; +import { ThemeType } from "../enums/themeType"; import { UriMatchType } from "../enums/uriMatchType"; import { CipherView } from "../models/view/cipherView"; @@ -1961,13 +1962,13 @@ export class StateService ); } - async getTheme(options?: StorageOptions): Promise { + async getTheme(options?: StorageOptions): Promise { return ( await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())) )?.theme; } - async setTheme(value: string, options?: StorageOptions): Promise { + async setTheme(value: ThemeType, options?: StorageOptions): Promise { const globals = await this.getGlobals( this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()) ); diff --git a/common/src/services/stateMigration.service.ts b/common/src/services/stateMigration.service.ts index f6c0882fd3..95059da3d0 100644 --- a/common/src/services/stateMigration.service.ts +++ b/common/src/services/stateMigration.service.ts @@ -16,6 +16,7 @@ import { SendData } from "../models/data/sendData"; import { HtmlStorageLocation } from "../enums/htmlStorageLocation"; import { KdfType } from "../enums/kdfType"; import { StateVersion } from "../enums/stateVersion"; +import { ThemeType } from "../enums/themeType"; import { EnvironmentUrls } from "../models/domain/environmentUrls"; @@ -191,7 +192,7 @@ export class StateMigrationService { globals.ssoState = (await this.get(v1Keys.ssoState)) ?? globals.ssoState; globals.rememberedEmail = (await this.get(v1Keys.rememberedEmail)) ?? globals.rememberedEmail; - globals.theme = (await this.get(v1Keys.theme)) ?? globals.theme; + globals.theme = (await this.get(v1Keys.theme)) ?? globals.theme; globals.vaultTimeout = (await this.get(v1Keys.vaultTimeout)) ?? globals.vaultTimeout; globals.vaultTimeoutAction = (await this.get(v1Keys.vaultTimeoutAction)) ?? globals.vaultTimeoutAction;