1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[Bug] [Account Switching] Improve State Management Performance (#1237)

* [dep] Implement new StateService factory parameter from jslib

* [bug] Ensure setLastActive uses the correct userId

Sometimes, because of how often it fires, setLastActive can cause accounts to override each other. To make sure the correct userId is always used we now subscribe to activeUser in the appComponent and pass that value into any setLastActive calls.

* [bug] Show loader when logging out

When logging out of a large vault the application can appear to hang. This commit turns on the app component loader while logout is doing work.

* [bug] Stop tracking activity without an active user

* [style] Ran prettier

* [chore] Update jslib
This commit is contained in:
Addison Beck
2022-01-19 11:00:28 -05:00
committed by GitHub
parent 8b521aa35e
commit b796fe094f
4 changed files with 41 additions and 9 deletions

View File

@@ -122,15 +122,21 @@ export class AppComponent implements OnInit {
) {}
ngOnInit() {
let activeUserId: string = null;
this.stateService.activeAccount.subscribe((userId) => {
activeUserId = userId;
});
this.ngZone.runOutsideAngular(() => {
setTimeout(async () => {
await this.updateAppMenu();
}, 1000);
window.ontouchstart = () => this.recordActivity();
window.onmousedown = () => this.recordActivity();
window.onscroll = () => this.recordActivity();
window.onkeypress = () => this.recordActivity();
if (activeUserId != null) {
window.ontouchstart = () => this.recordActivity(activeUserId);
window.onmousedown = () => this.recordActivity(activeUserId);
window.onscroll = () => this.recordActivity(activeUserId);
window.onkeypress = () => this.recordActivity(activeUserId);
}
});
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
@@ -155,7 +161,9 @@ export class AppComponent implements OnInit {
this.router.navigate(["login"]);
break;
case "logout":
this.loading = true;
await this.logOut(!!message.expired, message.userId);
this.loading = false;
break;
case "lockVault":
await this.vaultTimeoutService.lock(true, message.userId);
@@ -479,14 +487,14 @@ export class AppComponent implements OnInit {
await this.updateAppMenu();
}
private async recordActivity() {
private async recordActivity(userId: string) {
const now = new Date().getTime();
if (this.lastActivity != null && now - this.lastActivity < 250) {
return;
}
this.lastActivity = now;
await this.stateService.setLastActive(now);
await this.stateService.setLastActive(now, { userId: userId });
// Idle states
if (this.isIdle) {