diff --git a/common/src/abstractions/state.service.ts b/common/src/abstractions/state.service.ts index 10693164..2fcd3670 100644 --- a/common/src/abstractions/state.service.ts +++ b/common/src/abstractions/state.service.ts @@ -1,4 +1,4 @@ -import { BehaviorSubject } from "rxjs"; +import { BehaviorSubject, Observable } from "rxjs"; import { KdfType } from "../enums/kdfType"; import { ThemeType } from "../enums/themeType"; @@ -26,7 +26,7 @@ import { SendView } from "../models/view/sendView"; export abstract class StateService { accounts: BehaviorSubject<{ [userId: string]: T }>; - activeAccount: BehaviorSubject; + activeAccount: Observable; addAccount: (account: T) => Promise; setActiveUser: (userId: string) => Promise; diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 3714b3e7..49df85b3 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -1,4 +1,4 @@ -import { BehaviorSubject } from "rxjs"; +import { BehaviorSubject, Observable } from "rxjs"; import { LogService } from "../abstractions/log.service"; import { StateService as StateServiceAbstraction } from "../abstractions/state.service"; @@ -53,7 +53,10 @@ export class StateService< > implements StateServiceAbstraction { accounts = new BehaviorSubject<{ [userId: string]: TAccount }>({}); - activeAccount = new BehaviorSubject(null); + protected innerActiveAccount = new BehaviorSubject(null); + get activeAccount(): Observable { + return this.innerActiveAccount.asObservable(); + } protected state: State = new State( this.createGlobals() @@ -100,7 +103,7 @@ export class StateService< this.state.activeUserId = storedActiveUser; } await this.pushAccounts(); - this.activeAccount.next(this.state.activeUserId); + this.innerActiveAccount.next(this.state.activeUserId); } async syncAccountFromDisk(userId: string) { @@ -120,14 +123,14 @@ export class StateService< await this.scaffoldNewAccountStorage(account); await this.setLastActive(new Date().getTime(), { userId: account.profile.userId }); await this.setActiveUser(account.profile.userId); - this.activeAccount.next(account.profile.userId); + this.innerActiveAccount.next(account.profile.userId); } async setActiveUser(userId: string): Promise { this.clearDecryptedDataForActiveUser(); this.state.activeUserId = userId; await this.storageService.save(keys.activeUserId, userId); - this.activeAccount.next(this.state.activeUserId); + this.innerActiveAccount.next(this.state.activeUserId); await this.pushAccounts(); }