2018-04-04 04:14:54 +02:00
|
|
|
import {
|
|
|
|
ToasterConfig,
|
|
|
|
ToasterContainerComponent,
|
|
|
|
} from 'angular2-toaster';
|
|
|
|
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
2018-04-09 15:51:22 +02:00
|
|
|
import {
|
|
|
|
Router,
|
|
|
|
RouterOutlet,
|
|
|
|
} from '@angular/router';
|
2018-04-04 04:14:54 +02:00
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
import { BrowserApi } from '../browser/browserApi';
|
|
|
|
|
|
|
|
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
|
|
|
|
|
|
|
|
import { AuthService } from 'jslib/abstractions/auth.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
|
|
|
|
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
|
|
|
|
2018-04-08 06:30:04 +02:00
|
|
|
import { routerTransition } from './app-routing.animations';
|
|
|
|
|
2018-04-04 04:14:54 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
styles: [],
|
2018-04-08 06:30:04 +02:00
|
|
|
animations: [routerTransition],
|
2018-04-04 04:14:54 +02:00
|
|
|
template: `
|
|
|
|
<toaster-container [toasterconfig]="toasterConfig"></toaster-container>
|
2018-04-08 06:30:04 +02:00
|
|
|
<main [@routerTransition]="getState(o)">
|
|
|
|
<router-outlet #o="outlet"></router-outlet>
|
|
|
|
</main>`,
|
2018-04-04 04:14:54 +02:00
|
|
|
})
|
2018-04-06 21:33:20 +02:00
|
|
|
export class AppComponent implements OnInit {
|
2018-04-04 04:14:54 +02:00
|
|
|
toasterConfig: ToasterConfig = new ToasterConfig({
|
|
|
|
showCloseButton: true,
|
|
|
|
mouseoverTimerStop: true,
|
2018-04-04 20:19:44 +02:00
|
|
|
animation: 'slideUp',
|
|
|
|
limit: 2,
|
|
|
|
positionClass: 'toast-bottom-full-width',
|
|
|
|
newestOnTop: false
|
2018-04-04 04:14:54 +02:00
|
|
|
});
|
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
private lastActivity: number = null;
|
|
|
|
|
2018-04-04 04:14:54 +02:00
|
|
|
constructor(private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics, private analytics: Angulartics2,
|
2018-04-06 21:33:20 +02:00
|
|
|
private toasterService: ToasterService, private storageService: StorageService,
|
|
|
|
private broadcasterService: BroadcasterService, private authService: AuthService,
|
|
|
|
private i18nService: I18nService, private router: Router) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
window.onmousemove = () => this.recordActivity();
|
|
|
|
window.onmousedown = () => this.recordActivity();
|
|
|
|
window.ontouchstart = () => this.recordActivity();
|
|
|
|
window.onclick = () => this.recordActivity();
|
|
|
|
window.onscroll = () => this.recordActivity();
|
|
|
|
window.onkeypress = () => this.recordActivity();
|
|
|
|
|
|
|
|
(window as any).bitwardenPopupMainMessageListener = (msg: any, sender: any, sendResponse: any) => {
|
|
|
|
if (msg.command === 'doneLoggingOut') {
|
|
|
|
this.authService.logOut(() => {
|
|
|
|
this.analytics.eventTrack.next({ action: 'Logged Out' });
|
|
|
|
if (msg.expired) {
|
|
|
|
this.toasterService.popAsync('warning', this.i18nService.t('loggedOut'),
|
|
|
|
this.i18nService.t('loginExpired'));
|
|
|
|
}
|
|
|
|
this.router.navigate(['home']);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
msg.webExtSender = sender;
|
|
|
|
this.broadcasterService.send(msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
BrowserApi.messageListener((window as any).bitwardenPopupMainMessageListener);
|
|
|
|
}
|
|
|
|
|
2018-04-09 15:51:22 +02:00
|
|
|
getState(outlet: RouterOutlet) {
|
2018-04-08 06:30:04 +02:00
|
|
|
return outlet.activatedRouteData.state;
|
|
|
|
}
|
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
private async recordActivity() {
|
|
|
|
const now = (new Date()).getTime();
|
|
|
|
if (this.lastActivity != null && now - this.lastActivity < 250) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.lastActivity = now;
|
|
|
|
this.storageService.save(ConstantsService.lastActiveKey, now);
|
|
|
|
}
|
2018-04-04 04:14:54 +02:00
|
|
|
}
|