mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-04 09:01:01 +01:00
[fix] Unsubscribe from activeAccount in AppComponent (#2960)
This commit is contained in:
parent
57b8144013
commit
e00fe8edae
@ -1,7 +1,15 @@
|
|||||||
import { ChangeDetectorRef, Component, NgZone, OnInit, SecurityContext } from "@angular/core";
|
import {
|
||||||
|
ChangeDetectorRef,
|
||||||
|
Component,
|
||||||
|
NgZone,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
SecurityContext,
|
||||||
|
} from "@angular/core";
|
||||||
import { DomSanitizer } from "@angular/platform-browser";
|
import { DomSanitizer } from "@angular/platform-browser";
|
||||||
import { NavigationEnd, Router, RouterOutlet } from "@angular/router";
|
import { NavigationEnd, Router, RouterOutlet } from "@angular/router";
|
||||||
import { IndividualConfig, ToastrService } from "ngx-toastr";
|
import { IndividualConfig, ToastrService } from "ngx-toastr";
|
||||||
|
import { Subject, takeUntil } from "rxjs";
|
||||||
import Swal, { SweetAlertIcon } from "sweetalert2";
|
import Swal, { SweetAlertIcon } from "sweetalert2";
|
||||||
|
|
||||||
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
|
||||||
@ -23,10 +31,12 @@ import { routerTransition } from "./app-routing.animations";
|
|||||||
<router-outlet #o="outlet"></router-outlet>
|
<router-outlet #o="outlet"></router-outlet>
|
||||||
</div>`,
|
</div>`,
|
||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit, OnDestroy {
|
||||||
private lastActivity: number = null;
|
private lastActivity: number = null;
|
||||||
private activeUserId: string;
|
private activeUserId: string;
|
||||||
|
|
||||||
|
private destroy$: Subject<void> = new Subject<void>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private toastrService: ToastrService,
|
private toastrService: ToastrService,
|
||||||
private broadcasterService: BroadcasterService,
|
private broadcasterService: BroadcasterService,
|
||||||
@ -46,7 +56,7 @@ export class AppComponent implements OnInit {
|
|||||||
// Clear them aggressively to make sure this doesn't occur
|
// Clear them aggressively to make sure this doesn't occur
|
||||||
await this.clearComponentStates();
|
await this.clearComponentStates();
|
||||||
|
|
||||||
this.stateService.activeAccount.subscribe((userId) => {
|
this.stateService.activeAccount.pipe(takeUntil(this.destroy$)).subscribe((userId) => {
|
||||||
this.activeUserId = userId;
|
this.activeUserId = userId;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,7 +131,7 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
BrowserApi.messageListener("app.component", (window as any).bitwardenPopupMainMessageListener);
|
BrowserApi.messageListener("app.component", (window as any).bitwardenPopupMainMessageListener);
|
||||||
|
|
||||||
this.router.events.subscribe(async (event) => {
|
this.router.events.pipe(takeUntil(this.destroy$)).subscribe(async (event) => {
|
||||||
if (event instanceof NavigationEnd) {
|
if (event instanceof NavigationEnd) {
|
||||||
const url = event.urlAfterRedirects || event.url || "";
|
const url = event.urlAfterRedirects || event.url || "";
|
||||||
if (
|
if (
|
||||||
@ -146,6 +156,11 @@ export class AppComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.destroy$.next();
|
||||||
|
this.destroy$.complete();
|
||||||
|
}
|
||||||
|
|
||||||
getState(outlet: RouterOutlet) {
|
getState(outlet: RouterOutlet) {
|
||||||
if (outlet.activatedRouteData.state === "ciphers") {
|
if (outlet.activatedRouteData.state === "ciphers") {
|
||||||
const routeDirection =
|
const routeDirection =
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
import { DomSanitizer } from "@angular/platform-browser";
|
import { DomSanitizer } from "@angular/platform-browser";
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
import { IndividualConfig, ToastrService } from "ngx-toastr";
|
import { IndividualConfig, ToastrService } from "ngx-toastr";
|
||||||
|
import { Subject, takeUntil } from "rxjs";
|
||||||
|
|
||||||
import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref";
|
import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref";
|
||||||
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
||||||
@ -96,6 +97,8 @@ export class AppComponent implements OnInit {
|
|||||||
private isIdle = false;
|
private isIdle = false;
|
||||||
private activeUserId: string = null;
|
private activeUserId: string = null;
|
||||||
|
|
||||||
|
private destroy$: Subject<void> = new Subject<void>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private broadcasterService: BroadcasterService,
|
private broadcasterService: BroadcasterService,
|
||||||
private tokenService: TokenService,
|
private tokenService: TokenService,
|
||||||
@ -127,9 +130,10 @@ export class AppComponent implements OnInit {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.stateService.activeAccount.subscribe((userId) => {
|
this.stateService.activeAccount.pipe(takeUntil(this.destroy$)).subscribe((userId) => {
|
||||||
this.activeUserId = userId;
|
this.activeUserId = userId;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.ngZone.runOutsideAngular(() => {
|
this.ngZone.runOutsideAngular(() => {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await this.updateAppMenu();
|
await this.updateAppMenu();
|
||||||
@ -360,6 +364,8 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
this.destroy$.next();
|
||||||
|
this.destroy$.complete();
|
||||||
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user