diff --git a/jslib b/jslib index cddeeefdbb..7a3462afda 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit cddeeefdbb14d5f70020fb705885eb05a0bb4339 +Subproject commit 7a3462afdabaab0b15b1a41b9b173d5efd23bb4a diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index c82f1e632b..94da6a1ec2 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -1,22 +1,72 @@ -import { Component } from '@angular/core'; -import { Router } from '@angular/router'; +import { + Component, + NgZone, + OnDestroy, + OnInit, +} from '@angular/core'; +import { + ActivatedRoute, + Router, +} from '@angular/router'; import { CryptoService } from 'jslib/abstractions/crypto.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { StorageService } from 'jslib/abstractions/storage.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { ConstantsService } from 'jslib/services/constants.service'; + import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component'; @Component({ selector: 'app-lock', templateUrl: 'lock.component.html', }) -export class LockComponent extends BaseLockComponent { +export class LockComponent extends BaseLockComponent implements OnInit, OnDestroy { + private reloadInterval: number = null; + constructor(router: Router, i18nService: I18nService, platformUtilsService: PlatformUtilsService, messagingService: MessagingService, - userService: UserService, cryptoService: CryptoService) { + userService: UserService, cryptoService: CryptoService, + private ngZone: NgZone, private route: ActivatedRoute, + private storageService: StorageService) { super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService); } + + ngOnInit() { + this.route.queryParams.subscribe((params) => { + if (params.refresh === 'true') { + // Refresh the renderer window when locked to enure that all purged memory is cleaned up + this.ngZone.runOutsideAngular(() => { + this.reloadInterval = window.setInterval(async () => { + let doRefresh = false; + const lastActive = await this.storageService.get(ConstantsService.lastActiveKey); + if (lastActive != null) { + const diffSeconds = (new Date()).getTime() - lastActive; + // Don't refresh if they are still active in the window + doRefresh = diffSeconds >= 5000; + } + if (doRefresh) { + window.clearInterval(this.reloadInterval); + this.reloadInterval = null; + window.location.reload(true); + } + }, 10000); + }); + this.router.navigate([], { + relativeTo: this.route, + queryParams: {}, + replaceUrl: true, + }); + } + }); + } + + ngOnDestroy() { + if (this.reloadInterval != null) { + window.clearInterval(this.reloadInterval); + } + } } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index e5cd7156cc..2088d9c647 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -123,7 +123,7 @@ export class AppComponent implements OnInit { await this.lockService.lock(); break; case 'locked': - this.router.navigate(['lock']); + this.router.navigate(['lock'], { queryParams: { refresh: true } }); this.notificationsService.updateConnection(); this.updateAppMenu(); break;