mirror of
https://github.com/bitwarden/browser
synced 2025-12-24 12:13:39 +00:00
[Account Switching] Base changes for account switching (#2250)
* Pull in jslib * Create new state models * Create browser specific stateService * Remove registration deprecated services, register stateService * Replace usage of deprecated services (user, constants) * Add missing properties to BrowserGroupingsComponentState * Remove StorageService from initFactory * Clear the correct state * Add null check when restoring send-grouping state * add remember email * Initialize stateservice in services.module * Fix 'lock now' not working * Comment to remove setting defaults on install * Pull jslib * Remove setting defaults on install * Bump jslib * Pass the current userId to services when logging out * Bump jslib * Override vaultTimeout default on account addition * Pull latest jslib * Retrieve vaultTimeout from stateService * Record activity per Account * Add userId to logout and add fallback if not present * Register AccountFactory * Pass userId in messages * Base changes for account switching di fixes (#2280) * [bug] Null checks on Account init * [bug] Use same stateService instance for all operations We override the stateService in browser, but currently don't pull the background service into popup and allow jslib to create its own instance of the base StateService for jslib services. This causes a split in in memory state between the three isntances that results in many errors, namely locking not working. * [chore] Update jslib * Pull in jslib * Pull in jslib * Pull in latest jslib to multiple stateservice inits * Check vault states before executing processReload * Adjust iterator * Update native messaging to include the userId (#2290) * Re-Add UserVerificationService * Fix email not being remembered by base component * Improve readability of reloadProcess * Removed unneeded null check * Fix constructor dependency (stateService) * Added missing await * Simplify dependency registration * Fixed typos * Reverted back to simple loop * Use vaultTimeoutService to retrieve Timeout Co-authored-by: Addison Beck <abeck@bitwarden.com> Co-authored-by: Oscar Hinton <oscar@oscarhinton.com>
This commit is contained in:
committed by
GitHub
parent
ade2a96239
commit
bd770c90ed
33
src/services/abstractions/state.service.ts
Normal file
33
src/services/abstractions/state.service.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { StateService as BaseStateServiceAbstraction } from "jslib-common/abstractions/state.service";
|
||||
|
||||
import { StorageOptions } from "jslib-common/models/domain/storageOptions";
|
||||
|
||||
import { Account } from "src/models/account";
|
||||
import { BrowserComponentState } from "src/models/browserComponentState";
|
||||
import { BrowserGroupingsComponentState } from "src/models/browserGroupingsComponentState";
|
||||
import { BrowserSendComponentState } from "src/models/browserSendComponentState";
|
||||
|
||||
export abstract class StateService extends BaseStateServiceAbstraction<Account> {
|
||||
getBrowserGroupingComponentState: (
|
||||
options?: StorageOptions
|
||||
) => Promise<BrowserGroupingsComponentState>;
|
||||
setBrowserGroupingComponentState: (
|
||||
value: BrowserGroupingsComponentState,
|
||||
options?: StorageOptions
|
||||
) => Promise<void>;
|
||||
getBrowserCipherComponentState: (options?: StorageOptions) => Promise<BrowserComponentState>;
|
||||
setBrowserCipherComponentState: (
|
||||
value: BrowserComponentState,
|
||||
options?: StorageOptions
|
||||
) => Promise<void>;
|
||||
getBrowserSendComponentState: (options?: StorageOptions) => Promise<BrowserSendComponentState>;
|
||||
setBrowserSendComponentState: (
|
||||
value: BrowserSendComponentState,
|
||||
options?: StorageOptions
|
||||
) => Promise<void>;
|
||||
getBrowserSendTypeComponentState: (options?: StorageOptions) => Promise<BrowserComponentState>;
|
||||
setBrowserSendTypeComponentState: (
|
||||
value: BrowserComponentState,
|
||||
options?: StorageOptions
|
||||
) => Promise<void>;
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import { CipherService } from "jslib-common/abstractions/cipher.service";
|
||||
import { EventService } from "jslib-common/abstractions/event.service";
|
||||
import { LogService } from "jslib-common/abstractions/log.service";
|
||||
import { TotpService } from "jslib-common/abstractions/totp.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
|
||||
import { AutofillService as AutofillServiceInterface } from "./abstractions/autofill.service";
|
||||
|
||||
@@ -18,6 +17,8 @@ import AutofillField from "../models/autofillField";
|
||||
import AutofillPageDetails from "../models/autofillPageDetails";
|
||||
import AutofillScript from "../models/autofillScript";
|
||||
|
||||
import { StateService } from "../services/abstractions/state.service";
|
||||
|
||||
import { BrowserApi } from "../browser/browserApi";
|
||||
|
||||
import {
|
||||
@@ -29,7 +30,7 @@ import {
|
||||
export default class AutofillService implements AutofillServiceInterface {
|
||||
constructor(
|
||||
private cipherService: CipherService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private totpService: TotpService,
|
||||
private eventService: EventService,
|
||||
private logService: LogService
|
||||
@@ -74,7 +75,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
throw new Error("Nothing to auto-fill.");
|
||||
}
|
||||
|
||||
const canAccessPremium = await this.userService.canAccessPremium();
|
||||
const canAccessPremium = await this.stateService.getCanAccessPremium();
|
||||
let didAutofill = false;
|
||||
options.pageDetails.forEach((pd: any) => {
|
||||
// make sure we're still on correct tab
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { KeySuffixOptions } from "jslib-common/abstractions/storage.service";
|
||||
import { KeySuffixOptions } from "jslib-common/enums/keySuffixOptions";
|
||||
import { CryptoService } from "jslib-common/services/crypto.service";
|
||||
|
||||
export class BrowserCryptoService extends CryptoService {
|
||||
|
||||
@@ -6,9 +6,8 @@ import { ThemeType } from "jslib-common/enums/themeType";
|
||||
|
||||
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
||||
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
||||
import { StorageService } from "jslib-common/abstractions/storage.service";
|
||||
|
||||
import { ConstantsService } from "jslib-common/services/constants.service";
|
||||
import { StateService } from "../services/abstractions/state.service";
|
||||
|
||||
const DialogPromiseExpiration = 600000; // 10 minutes
|
||||
|
||||
@@ -25,7 +24,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
|
||||
constructor(
|
||||
private messagingService: MessagingService,
|
||||
private storageService: StorageService,
|
||||
private stateService: StateService,
|
||||
private clipboardWriteCallback: (clipboardValue: string, clearMs: number) => void,
|
||||
private biometricCallback: () => Promise<boolean>
|
||||
) {}
|
||||
@@ -367,7 +366,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
}
|
||||
|
||||
async getEffectiveTheme() {
|
||||
const theme = await this.storageService.get<ThemeType>(ConstantsService.themeKey);
|
||||
const theme = (await this.stateService.getTheme()) as ThemeType;
|
||||
if (theme == null || theme === ThemeType.System) {
|
||||
return this.getDefaultSystemTheme();
|
||||
} else {
|
||||
|
||||
81
src/services/state.service.ts
Normal file
81
src/services/state.service.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { StorageOptions } from "jslib-common/models/domain/storageOptions";
|
||||
import { StateService as BaseStateService } from "jslib-common/services/state.service";
|
||||
|
||||
import { Account } from "../models/account";
|
||||
import { BrowserComponentState } from "../models/browserComponentState";
|
||||
import { BrowserGroupingsComponentState } from "../models/browserGroupingsComponentState";
|
||||
import { BrowserSendComponentState } from "../models/browserSendComponentState";
|
||||
import { StateService as StateServiceAbstraction } from "./abstractions/state.service";
|
||||
|
||||
export class StateService extends BaseStateService<Account> implements StateServiceAbstraction {
|
||||
async addAccount(account: Account) {
|
||||
// Apply browser overrides to default account values
|
||||
account = new Account(account);
|
||||
await super.addAccount(account);
|
||||
}
|
||||
|
||||
async getBrowserGroupingComponentState(
|
||||
options?: StorageOptions
|
||||
): Promise<BrowserGroupingsComponentState> {
|
||||
return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)))
|
||||
?.groupings;
|
||||
}
|
||||
|
||||
async setBrowserGroupingComponentState(
|
||||
value: BrowserGroupingsComponentState,
|
||||
options?: StorageOptions
|
||||
): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, this.defaultInMemoryOptions)
|
||||
);
|
||||
account.groupings = value;
|
||||
await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
}
|
||||
|
||||
async getBrowserCipherComponentState(options?: StorageOptions): Promise<BrowserComponentState> {
|
||||
return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)))
|
||||
?.ciphers;
|
||||
}
|
||||
|
||||
async setBrowserCipherComponentState(
|
||||
value: BrowserComponentState,
|
||||
options?: StorageOptions
|
||||
): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, this.defaultInMemoryOptions)
|
||||
);
|
||||
account.ciphers = value;
|
||||
await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
}
|
||||
|
||||
async getBrowserSendComponentState(options?: StorageOptions): Promise<BrowserSendComponentState> {
|
||||
return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)))
|
||||
?.send;
|
||||
}
|
||||
|
||||
async setBrowserSendComponentState(
|
||||
value: BrowserSendComponentState,
|
||||
options?: StorageOptions
|
||||
): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, this.defaultInMemoryOptions)
|
||||
);
|
||||
account.send = value;
|
||||
await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
}
|
||||
async getBrowserSendTypeComponentState(options?: StorageOptions): Promise<BrowserComponentState> {
|
||||
return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)))
|
||||
?.sendType;
|
||||
}
|
||||
|
||||
async setBrowserSendTypeComponentState(
|
||||
value: BrowserComponentState,
|
||||
options?: StorageOptions
|
||||
): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, this.defaultInMemoryOptions)
|
||||
);
|
||||
account.sendType = value;
|
||||
await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user