mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-07 09:31:31 +01:00
keep using on init
This commit is contained in:
parent
da9bd3a8db
commit
4d261964e5
@ -6,13 +6,7 @@ import {
|
|||||||
OnInit,
|
OnInit,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import {
|
import { Router } from '@angular/router';
|
||||||
ActivatedRoute,
|
|
||||||
NavigationEnd,
|
|
||||||
Router,
|
|
||||||
} from '@angular/router';
|
|
||||||
|
|
||||||
import { Subscription } from 'rxjs';
|
|
||||||
|
|
||||||
import { ToasterService } from 'angular2-toaster';
|
import { ToasterService } from 'angular2-toaster';
|
||||||
import { Angulartics2 } from 'angulartics2';
|
import { Angulartics2 } from 'angulartics2';
|
||||||
@ -22,7 +16,6 @@ import { BrowserApi } from '../../browser/browserApi';
|
|||||||
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
|
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
|
||||||
|
|
||||||
import { CipherType } from 'jslib/enums/cipherType';
|
import { CipherType } from 'jslib/enums/cipherType';
|
||||||
import { DeviceType } from 'jslib/enums/deviceType';
|
|
||||||
|
|
||||||
import { CipherView } from 'jslib/models/view/cipherView';
|
import { CipherView } from 'jslib/models/view/cipherView';
|
||||||
|
|
||||||
@ -64,7 +57,6 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
private totpTimeout: number;
|
private totpTimeout: number;
|
||||||
private loadedTimeout: number;
|
private loadedTimeout: number;
|
||||||
private searchTimeout: number;
|
private searchTimeout: number;
|
||||||
private navSubscription: Subscription;
|
|
||||||
|
|
||||||
constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
|
constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
|
||||||
private popupUtilsService: PopupUtilsService, private autofillService: AutofillService,
|
private popupUtilsService: PopupUtilsService, private autofillService: AutofillService,
|
||||||
@ -73,26 +65,57 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
private ngZone: NgZone, private broadcasterService: BroadcasterService,
|
private ngZone: NgZone, private broadcasterService: BroadcasterService,
|
||||||
private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService,
|
private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService,
|
||||||
private searchService: SearchService, private storageService: StorageService) {
|
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() {
|
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() {
|
ngOnDestroy() {
|
||||||
window.clearTimeout(this.loadedTimeout);
|
window.clearTimeout(this.loadedTimeout);
|
||||||
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
||||||
if (this.navSubscription != null) {
|
|
||||||
this.navSubscription.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async refresh() {
|
async refresh() {
|
||||||
@ -163,52 +186,6 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
}, 200);
|
}, 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() {
|
private async load() {
|
||||||
const tab = await BrowserApi.getTabFromCurrentWindow();
|
const tab = await BrowserApi.getTabFromCurrentWindow();
|
||||||
if (tab != null) {
|
if (tab != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user