1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-27 17:18:04 +01:00

Refresh window when locked to enure that all purged memory is cleaned up

This commit is contained in:
Kyle Spearrin 2018-12-26 11:02:02 -05:00
parent 2ccbcb75bf
commit 24bd7208fd
3 changed files with 56 additions and 6 deletions

2
jslib

@ -1 +1 @@
Subproject commit cddeeefdbb14d5f70020fb705885eb05a0bb4339 Subproject commit 7a3462afdabaab0b15b1a41b9b173d5efd23bb4a

View File

@ -1,22 +1,72 @@
import { Component } from '@angular/core'; import {
import { Router } from '@angular/router'; Component,
NgZone,
OnDestroy,
OnInit,
} from '@angular/core';
import {
ActivatedRoute,
Router,
} from '@angular/router';
import { CryptoService } from 'jslib/abstractions/crypto.service'; import { CryptoService } from 'jslib/abstractions/crypto.service';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
import { MessagingService } from 'jslib/abstractions/messaging.service'; import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { UserService } from 'jslib/abstractions/user.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'; import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component';
@Component({ @Component({
selector: 'app-lock', selector: 'app-lock',
templateUrl: 'lock.component.html', 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, constructor(router: Router, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, messagingService: MessagingService, 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); 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<number>(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);
}
}
} }

View File

@ -123,7 +123,7 @@ export class AppComponent implements OnInit {
await this.lockService.lock(); await this.lockService.lock();
break; break;
case 'locked': case 'locked':
this.router.navigate(['lock']); this.router.navigate(['lock'], { queryParams: { refresh: true } });
this.notificationsService.updateConnection(); this.notificationsService.updateConnection();
this.updateAppMenu(); this.updateAppMenu();
break; break;