diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 34fd0adf..9cc13d00 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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); + } } diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 4c361084..dfc61be4 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -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, diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index aea06cb4..132b7f56 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -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(); diff --git a/src/services/desktopPlatformUtils.service.ts b/src/services/desktopPlatformUtils.service.ts index 84508cda..f58b453d 100644 --- a/src/services/desktopPlatformUtils.service.ts +++ b/src/services/desktopPlatformUtils.service.ts @@ -97,7 +97,7 @@ export class DesktopPlatformUtilsService implements PlatformUtilsService { } isViewOpen(): boolean { - return true; + return false; } launchUri(uri: string, options?: any): void {