diff --git a/jslib b/jslib index 74b31daf14..3d02a1ecb8 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 74b31daf1463502f72fa311d91ea68b11e109423 +Subproject commit 3d02a1ecb8cdb945f3bee2fbb6921b40286575a1 diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5ac09e122c..9fdd6998d9 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -47,6 +47,7 @@ import { RouterService } from './services/router.service'; const BroadcasterSubscriptionId = 'AppComponent'; // Hack due to Angular 5.2 bug const swal: SweetAlert = _swal as any; +const IdleTimeout = 60000 * 5; // 5 minutes @Component({ selector: 'app-root', @@ -61,6 +62,8 @@ export class AppComponent implements OnDestroy, OnInit { }); private lastActivity: number = null; + private idleTimer: number = null; + private isIdle = false; constructor(private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics, private broadcasterService: BroadcasterService, private userService: UserService, @@ -90,9 +93,8 @@ export class AppComponent implements OnDestroy, OnInit { switch (message.command) { case 'loggedIn': case 'loggedOut': - this.notificationsService.updateConnection(); - break; case 'unlocked': + this.notificationsService.updateConnection(); break; case 'logout': this.logOut(!!message.expired); @@ -101,6 +103,7 @@ export class AppComponent implements OnDestroy, OnInit { await this.lockService.lock(); break; case 'locked': + this.notificationsService.updateConnection(); this.router.navigate(['lock']); break; case 'syncStarted': @@ -181,5 +184,29 @@ export class AppComponent implements OnDestroy, OnInit { this.lastActivity = now; this.storageService.save(ConstantsService.lastActiveKey, now); + + // Idle states + if (this.isIdle) { + this.isIdle = false; + this.idleStateChanged(); + } + if (this.idleTimer != null) { + window.clearTimeout(this.idleTimer); + this.idleTimer = null; + } + this.idleTimer = window.setTimeout(() => { + if (!this.isIdle) { + this.isIdle = true; + this.idleStateChanged(); + } + }, IdleTimeout); + } + + private idleStateChanged() { + if (this.isIdle) { + this.notificationsService.disconnectFromInactivity(); + } else { + this.notificationsService.reconnectFromActivity(); + } } } diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index d73b3c6dde..365d1b088e 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -115,8 +115,8 @@ const authService = new AuthService(cryptoService, apiService, userService, tokenService, appIdService, i18nService, platformUtilsService, messagingService); const exportService = new ExportService(folderService, cipherService, apiService); const importService = new ImportService(cipherService, folderService, apiService, i18nService, collectionService); -const notificationsService = new NotificationsService(userService, tokenService, syncService, appIdService, - apiService); +const notificationsService = new NotificationsService(userService, syncService, appIdService, + apiService, cryptoService); const environmentService = new EnvironmentService(apiService, storageService, notificationsService); const auditService = new AuditService(cryptoFunctionService, apiService); diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index 77f24bdae8..8759fedf02 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -102,7 +102,7 @@ export class VaultComponent implements OnInit, OnDestroy { await Promise.all([ this.groupingsComponent.load(), this.organizationsComponent.load(), - this.ciphersComponent.refresh(), + this.ciphersComponent.load(this.ciphersComponent.filter), ]); this.changeDetectorRef.detectChanges(); }