reload on logout too, move to messages

This commit is contained in:
Kyle Spearrin 2019-02-25 15:07:44 -05:00
parent 5657105291
commit fdb822f8b3
3 changed files with 15 additions and 54 deletions

2
jslib

@ -1 +1 @@
Subproject commit fc2f64ee367b65e35e683ece0c91c05b5fb83bc5 Subproject commit 9a4611ec5a650362abc7f5616fd7006f950c5b3d

View File

@ -1,12 +1,5 @@
import { import { Component } from '@angular/core';
Component, import { Router } from '@angular/router';
NgZone,
OnDestroy,
} 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';
@ -16,59 +9,18 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StorageService } from 'jslib/abstractions/storage.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 implements OnDestroy { export class LockComponent extends BaseLockComponent {
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,
storageService: StorageService, lockService: LockService) { storageService: StorageService, lockService: LockService) {
super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService, super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService,
storageService, lockService); storageService, lockService);
} }
async ngOnInit() {
await super.ngOnInit();
this.route.queryParams.subscribe((params) => {
if (params.refresh === 'true' && !this.lockService.pinLocked) {
// 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

@ -111,10 +111,15 @@ export class AppComponent implements OnInit {
this.ngZone.run(async () => { this.ngZone.run(async () => {
switch (message.command) { switch (message.command) {
case 'loggedIn': case 'loggedIn':
case 'loggedOut':
case 'unlocked': case 'unlocked':
this.notificationsService.updateConnection(); this.notificationsService.updateConnection();
this.updateAppMenu(); this.updateAppMenu();
this.lockService.cancelLockReload();
break;
case 'loggedOut':
this.notificationsService.updateConnection();
this.updateAppMenu();
this.lockService.startLockReload();
break; break;
case 'logout': case 'logout':
this.logOut(!!message.expired); this.logOut(!!message.expired);
@ -123,9 +128,13 @@ export class AppComponent implements OnInit {
await this.lockService.lock(true); await this.lockService.lock(true);
break; break;
case 'locked': case 'locked':
this.router.navigate(['lock'], { queryParams: { refresh: true } }); this.router.navigate(['lock']);
this.notificationsService.updateConnection(); this.notificationsService.updateConnection();
this.updateAppMenu(); this.updateAppMenu();
this.lockService.startLockReload();
break;
case 'reloadProcess':
window.location.reload(true);
break; break;
case 'syncStarted': case 'syncStarted':
break; break;