mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
share disk cache to fix syncing issues between contexts
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { StateMigrationService } from "@bitwarden/common/platform/abstractions/state-migration.service";
|
||||
@@ -33,11 +33,6 @@ export class BrowserStateService
|
||||
protected activeAccountSubject: BehaviorSubject<string>;
|
||||
@sessionSync({ initializer: (b: boolean) => b })
|
||||
protected activeAccountUnlockedSubject: BehaviorSubject<boolean>;
|
||||
@sessionSync({
|
||||
initializer: Account.fromJSON as any, // TODO: Remove this any when all any types are removed from Account
|
||||
initializeAs: "record",
|
||||
})
|
||||
protected accountDiskCache: BehaviorSubject<Record<string, Account>>;
|
||||
|
||||
protected accountDeserializer = Account.fromJSON;
|
||||
|
||||
@@ -48,7 +43,8 @@ export class BrowserStateService
|
||||
logService: LogService,
|
||||
stateMigrationService: StateMigrationService,
|
||||
stateFactory: StateFactory<GlobalState, Account>,
|
||||
useAccountCache = false
|
||||
useAccountCache = true,
|
||||
accountCache: Observable<Record<string, Account>> = null
|
||||
) {
|
||||
super(
|
||||
storageService,
|
||||
@@ -59,6 +55,12 @@ export class BrowserStateService
|
||||
stateFactory,
|
||||
useAccountCache
|
||||
);
|
||||
|
||||
// Hack to allow shared disk cache between contexts on browser
|
||||
// TODO: Remove when services are consolidated to a single context
|
||||
if (useAccountCache && accountCache) {
|
||||
accountCache.subscribe(this.accountDiskCacheSubject);
|
||||
}
|
||||
}
|
||||
|
||||
async addAccount(account: Account) {
|
||||
|
||||
@@ -440,13 +440,20 @@ function getBgService<T>(service: keyof MainBackground) {
|
||||
logService: LogServiceAbstraction,
|
||||
stateMigrationService: StateMigrationService
|
||||
) => {
|
||||
// hack to share the disk cache between the two contexts.
|
||||
// TODO: we need to figure out a better way of sharing/syncing
|
||||
// the disk cache
|
||||
const bgStateService = getBgService<StateServiceAbstraction>("stateService");
|
||||
const bgDiskCache = bgStateService().accountDiskCache$;
|
||||
return new BrowserStateService(
|
||||
storageService,
|
||||
secureStorageService,
|
||||
memoryStorageService,
|
||||
logService,
|
||||
stateMigrationService,
|
||||
new StateFactory(GlobalState, Account)
|
||||
new StateFactory(GlobalState, Account),
|
||||
true,
|
||||
bgDiskCache
|
||||
);
|
||||
},
|
||||
deps: [
|
||||
|
||||
Reference in New Issue
Block a user