[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 { CryptoService } from "jslib-common/services/crypto.service";
|
||||||
import { EventService as EventLoggingService } from "jslib-common/services/event.service";
|
import { EventService as EventLoggingService } from "jslib-common/services/event.service";
|
||||||
import { ImportService } from "jslib-common/services/import.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 { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service";
|
||||||
|
|
||||||
import { ApiService as ApiServiceAbstraction } from "jslib-common/abstractions/api.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 { ThemeType } from "jslib-common/enums/themeType";
|
||||||
|
|
||||||
import { AccountFactory } from "jslib-common/models/domain/account";
|
|
||||||
|
|
||||||
import { Account } from "../../models/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(
|
export function initFactory(
|
||||||
window: Window,
|
window: Window,
|
||||||
storageService: StorageServiceAbstraction,
|
|
||||||
environmentService: EnvironmentServiceAbstraction,
|
environmentService: EnvironmentServiceAbstraction,
|
||||||
notificationsService: NotificationsServiceAbstraction,
|
notificationsService: NotificationsServiceAbstraction,
|
||||||
vaultTimeoutService: VaultTimeoutService,
|
vaultTimeoutService: VaultTimeoutService,
|
||||||
|
@ -70,7 +72,6 @@ export function initFactory(
|
||||||
cryptoService: CryptoServiceAbstraction
|
cryptoService: CryptoServiceAbstraction
|
||||||
): Function {
|
): Function {
|
||||||
return async () => {
|
return async () => {
|
||||||
await (storageService as HtmlStorageService).init();
|
|
||||||
await stateService.init();
|
await stateService.init();
|
||||||
|
|
||||||
const urls = process.env.URLS as Urls;
|
const urls = process.env.URLS as Urls;
|
||||||
|
@ -110,7 +111,6 @@ export function initFactory(
|
||||||
useFactory: initFactory,
|
useFactory: initFactory,
|
||||||
deps: [
|
deps: [
|
||||||
"WINDOW",
|
"WINDOW",
|
||||||
StorageServiceAbstraction,
|
|
||||||
EnvironmentServiceAbstraction,
|
EnvironmentServiceAbstraction,
|
||||||
NotificationsServiceAbstraction,
|
NotificationsServiceAbstraction,
|
||||||
VaultTimeoutServiceAbstraction,
|
VaultTimeoutServiceAbstraction,
|
||||||
|
@ -180,6 +180,19 @@ export function initFactory(
|
||||||
StateServiceAbstraction,
|
StateServiceAbstraction,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: StateMigrationServiceAbstraction,
|
||||||
|
useFactory: (
|
||||||
|
storageService: StorageServiceAbstraction,
|
||||||
|
secureStorageService: StorageServiceAbstraction
|
||||||
|
) =>
|
||||||
|
new StateMigrationService(
|
||||||
|
storageService,
|
||||||
|
secureStorageService,
|
||||||
|
new GlobalStateFactory(GlobalState)
|
||||||
|
),
|
||||||
|
deps: [StorageServiceAbstraction, "SECURE_STORAGE"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: StateServiceAbstraction,
|
provide: StateServiceAbstraction,
|
||||||
useFactory: (
|
useFactory: (
|
||||||
|
@ -193,7 +206,7 @@ export function initFactory(
|
||||||
secureStorageService,
|
secureStorageService,
|
||||||
logService,
|
logService,
|
||||||
stateMigrationService,
|
stateMigrationService,
|
||||||
new AccountFactory(Account)
|
new StateFactory(GlobalState, Account)
|
||||||
),
|
),
|
||||||
deps: [
|
deps: [
|
||||||
StorageServiceAbstraction,
|
StorageServiceAbstraction,
|
||||||
|
|
|
@ -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 { 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";
|
import { StorageOptions } from "jslib-common/models/domain/storageOptions";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -14,16 +12,6 @@ export class HtmlStorageService implements StorageService {
|
||||||
return { htmlStorageLocation: HtmlStorageLocation.Session };
|
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> {
|
get<T>(key: string, options: StorageOptions = this.defaultOptions): Promise<T> {
|
||||||
let json: string = null;
|
let json: string = null;
|
||||||
switch (options.htmlStorageLocation) {
|
switch (options.htmlStorageLocation) {
|
||||||
|
|
Loading…
Reference in New Issue