bitwarden-estensione-browser/src/popup2/app.component.ts

87 lines
3.1 KiB
TypeScript
Raw Normal View History

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';
import { Router } from '@angular/router';
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-04 04:14:54 +02:00
@Component({
selector: 'app-root',
styles: [],
template: `
<toaster-container [toasterconfig]="toasterConfig"></toaster-container>
<router-outlet></router-outlet>`,
})
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,
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);
}
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
}