1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-07 09:31:31 +01:00

record activity for lock

This commit is contained in:
Kyle Spearrin 2018-02-09 23:25:18 -05:00
parent a77b16b766
commit 6e77916a49
4 changed files with 33 additions and 4 deletions

View File

@ -25,10 +25,13 @@ import { LockService } from 'jslib/abstractions/lock.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { SettingsService } from 'jslib/abstractions/settings.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { SyncService } from 'jslib/abstractions/sync.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { UserService } from 'jslib/abstractions/user.service';
import { ConstantsService } from 'jslib/services/constants.service';
@Component({
selector: 'app-root',
styles: [],
@ -44,17 +47,27 @@ export class AppComponent implements OnInit {
limit: 5,
});
private lastActivity: number = null;
constructor(private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics,
private broadcasterService: BroadcasterService, private userService: UserService,
private tokenService: TokenService, private folderService: FolderService, private cryptoService: CryptoService,
private tokenService: TokenService, private folderService: FolderService,
private settingsService: SettingsService, private syncService: SyncService,
private passwordGenerationService: PasswordGenerationService, private cipherService: CipherService,
private authService: AuthService, private router: Router, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private ngZone: NgZone,
private lockService: LockService) { }
private lockService: LockService, private storageService: StorageService,
private cryptoService: CryptoService) { }
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();
this.broadcasterService.subscribe((message: any) => {
this.ngZone.run(async () => {
switch (message.command) {
@ -104,4 +117,14 @@ export class AppComponent implements OnInit {
this.router.navigate(['login']);
});
}
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);
}
}

View File

@ -141,6 +141,7 @@ function initFactory(i18n: I18nService, platformUtils: DesktopPlatformUtilsServi
{ provide: BroadcasterService, useValue: broadcasterService },
{ provide: SettingsServiceAbstraction, useValue: settingsService },
{ provide: LockServiceAbstraction, useValue: lockService },
{ provide: StorageServiceAbstraction, useValue: storageService },
{
provide: APP_INITIALIZER,
useFactory: initFactory,

View File

@ -6,6 +6,7 @@ import {
Component,
ComponentFactoryResolver,
NgZone,
OnDestroy,
OnInit,
ViewChild,
ViewContainerRef,
@ -45,7 +46,7 @@ const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
selector: 'app-vault',
template: template,
})
export class VaultComponent implements OnInit {
export class VaultComponent implements OnInit, OnDestroy {
@ViewChild(AddEditComponent) addEditComponent: AddEditComponent;
@ViewChild(CiphersComponent) ciphersComponent: CiphersComponent;
@ViewChild(GroupingsComponent) groupingsComponent: GroupingsComponent;
@ -143,6 +144,10 @@ export class VaultComponent implements OnInit {
}
}
ngOnDestroy() {
this.broadcasterService.unsubscribe();
}
async load() {
this.route.queryParams.subscribe(async (params) => {
await this.groupingsComponent.load();

View File

@ -97,7 +97,7 @@ export class DesktopPlatformUtilsService implements PlatformUtilsService {
}
isViewOpen(): boolean {
return true;
return false;
}
launchUri(uri: string, options?: any): void {