keep using on init

This commit is contained in:
Kyle Spearrin 2019-08-19 09:31:05 -04:00
parent da9bd3a8db
commit 4d261964e5
1 changed files with 44 additions and 67 deletions

View File

@ -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) {