mirror of
https://github.com/bitwarden/jslib
synced 2025-12-22 03:03:15 +00:00
[bug] Allow for GlobalState to be extended and modified in clients (#646)
Some clients have unique global setting defaults (and unique global settings) For example: the web vault defaults to light theme, but most clients with theme support default to system theme. The current way we handle GlobalState is buried in jslib and not easily extendible in clients. To fix this, we need to treat GlobalState as a generic in the StateService and StateMigration service and allow for its extension in those methods and anywhere GlobalState is inited.
This commit is contained in:
@@ -175,15 +175,3 @@ export class Account {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class AccountFactory<T extends Account = Account> {
|
||||
private accountConstructor: new (init: Partial<T>) => T;
|
||||
|
||||
constructor(accountConstructor: new (init: Partial<T>) => T) {
|
||||
this.accountConstructor = accountConstructor;
|
||||
}
|
||||
|
||||
create(args: Partial<T>) {
|
||||
return new this.accountConstructor(args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export class GlobalState {
|
||||
ssoOrganizationIdentifier?: string;
|
||||
ssoState?: string;
|
||||
rememberedEmail?: string;
|
||||
theme?: ThemeType = ThemeType.Light;
|
||||
theme?: ThemeType = ThemeType.System;
|
||||
window?: WindowState = new WindowState();
|
||||
twoFactorToken?: string;
|
||||
disableFavicon?: boolean;
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { Account } from "./account";
|
||||
import { GlobalState } from "./globalState";
|
||||
|
||||
export class State<TAccount extends Account = Account> {
|
||||
export class State<
|
||||
TAccount extends Account = Account,
|
||||
TGlobalState extends GlobalState = GlobalState
|
||||
> {
|
||||
accounts: { [userId: string]: TAccount } = {};
|
||||
globals: GlobalState = new GlobalState();
|
||||
globals: TGlobalState;
|
||||
activeUserId: string;
|
||||
authenticatedAccounts: string[] = [];
|
||||
|
||||
constructor(globals: TGlobalState) {
|
||||
this.globals = globals;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user