mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-12 01:48:21 +02:00
[bug] Extend GlobalState to supply correct default theme (#1422)
* [bug] Extend GlobalState to supply correct default theme The default theme for most clients is System, but web uses Light. We need to extend GlobalState in web to reflect this. * [chore] Update jslib
This commit is contained in:
parent
e3b962a779
commit
d79f074825
2
jslib
2
jslib
@ -1 +1 @@
|
||||
Subproject commit e372bf242b24f55c1142e33693ad2c801ab74c93
|
||||
Subproject commit 92a65b7b368a8dbf55350657674c90169b04c30b
|
@ -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,
|
||||
|
7
src/models/globalState.ts
Normal file
7
src/models/globalState.ts
Normal file
@ -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;
|
||||
}
|
@ -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>("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<T>(key: string, options: StorageOptions = this.defaultOptions): Promise<T> {
|
||||
let json: string = null;
|
||||
switch (options.htmlStorageLocation) {
|
||||
|
Loading…
Reference in New Issue
Block a user