From 4d261964e5f27b201bd1e01eb3e671c1b15d9f8f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 19 Aug 2019 09:31:05 -0400 Subject: [PATCH] keep using on init --- src/popup/vault/current-tab.component.ts | 111 +++++++++-------------- 1 file changed, 44 insertions(+), 67 deletions(-) diff --git a/src/popup/vault/current-tab.component.ts b/src/popup/vault/current-tab.component.ts index a3f7f4e923..81b753f719 100644 --- a/src/popup/vault/current-tab.component.ts +++ b/src/popup/vault/current-tab.component.ts @@ -6,13 +6,7 @@ import { OnInit, } from '@angular/core'; -import { - ActivatedRoute, - NavigationEnd, - Router, -} from '@angular/router'; - -import { Subscription } from 'rxjs'; +import { Router } from '@angular/router'; import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; @@ -22,7 +16,6 @@ import { BrowserApi } from '../../browser/browserApi'; import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; import { CipherType } from 'jslib/enums/cipherType'; -import { DeviceType } from 'jslib/enums/deviceType'; import { CipherView } from 'jslib/models/view/cipherView'; @@ -64,7 +57,6 @@ export class CurrentTabComponent implements OnInit, OnDestroy { private totpTimeout: number; private loadedTimeout: number; private searchTimeout: number; - private navSubscription: Subscription; constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService, private popupUtilsService: PopupUtilsService, private autofillService: AutofillService, @@ -73,26 +65,57 @@ export class CurrentTabComponent implements OnInit, OnDestroy { private ngZone: NgZone, private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService, private searchService: SearchService, private storageService: StorageService) { - this.navSubscription = this.router.events.subscribe(async (e: any) => { - // If it is a NavigationEnd event re-initialize the component - if (e instanceof NavigationEnd) { - console.log('nav end'); - console.log(e); - await this.init(); - } - }); } async ngOnInit() { - console.log('ngOnInit'); + this.showLeftHeader = this.searchTypeSearch = !this.platformUtilsService.isSafari(); + this.inSidebar = this.popupUtilsService.inSidebar(window); + + this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { + this.ngZone.run(async () => { + switch (message.command) { + case 'syncCompleted': + if (this.loaded) { + window.setTimeout(() => { + this.load(); + }, 500); + } + break; + case 'collectPageDetailsResponse': + if (message.sender === BroadcasterSubscriptionId) { + this.pageDetails.push({ + frameId: message.webExtSender.frameId, + tab: message.tab, + details: message.details, + }); + } + break; + default: + break; + } + + this.changeDetectorRef.detectChanges(); + }); + }); + + if (!this.syncService.syncInProgress) { + await this.load(); + } else { + this.loadedTimeout = window.setTimeout(async () => { + if (!this.loaded) { + await this.load(); + } + }, 5000); + } + + window.setTimeout(() => { + document.getElementById('search').focus(); + }, 100); } ngOnDestroy() { window.clearTimeout(this.loadedTimeout); this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); - if (this.navSubscription != null) { - this.navSubscription.unsubscribe(); - } } async refresh() { @@ -163,52 +186,6 @@ export class CurrentTabComponent implements OnInit, OnDestroy { }, 200); } - private async init() { - this.showLeftHeader = this.searchTypeSearch = !this.platformUtilsService.isSafari(); - this.inSidebar = this.popupUtilsService.inSidebar(window); - - this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { - this.ngZone.run(async () => { - switch (message.command) { - case 'syncCompleted': - if (this.loaded) { - window.setTimeout(() => { - this.load(); - }, 500); - } - break; - case 'collectPageDetailsResponse': - if (message.sender === BroadcasterSubscriptionId) { - this.pageDetails.push({ - frameId: message.webExtSender.frameId, - tab: message.tab, - details: message.details, - }); - } - break; - default: - break; - } - - this.changeDetectorRef.detectChanges(); - }); - }); - - if (!this.syncService.syncInProgress) { - await this.load(); - } else { - this.loadedTimeout = window.setTimeout(async () => { - if (!this.loaded) { - await this.load(); - } - }, 5000); - } - - window.setTimeout(() => { - document.getElementById('search').focus(); - }, 100); - } - private async load() { const tab = await BrowserApi.getTabFromCurrentWindow(); if (tab != null) {