2018-12-26 17:02:02 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
NgZone,
|
|
|
|
OnDestroy,
|
|
|
|
} from '@angular/core';
|
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
2018-02-10 04:47:53 +01:00
|
|
|
|
|
|
|
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';
|
2018-12-26 17:02:02 +01:00
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
2018-02-10 04:47:53 +01:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
|
|
|
|
2018-12-26 17:02:02 +01:00
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
|
|
|
|
2018-04-05 05:01:40 +02:00
|
|
|
import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component';
|
|
|
|
|
2018-02-10 04:47:53 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-lock',
|
2018-04-06 18:25:22 +02:00
|
|
|
templateUrl: 'lock.component.html',
|
2018-02-10 04:47:53 +01:00
|
|
|
})
|
2019-01-08 06:21:28 +01:00
|
|
|
export class LockComponent extends BaseLockComponent implements OnDestroy {
|
2018-12-26 17:02:02 +01:00
|
|
|
private reloadInterval: number = null;
|
|
|
|
|
2018-10-03 15:42:11 +02:00
|
|
|
constructor(router: Router, i18nService: I18nService,
|
2018-04-05 05:01:40 +02:00
|
|
|
platformUtilsService: PlatformUtilsService, messagingService: MessagingService,
|
2018-12-26 17:02:02 +01:00
|
|
|
userService: UserService, cryptoService: CryptoService,
|
|
|
|
private ngZone: NgZone, private route: ActivatedRoute,
|
|
|
|
private storageService: StorageService) {
|
2018-10-03 15:42:11 +02:00
|
|
|
super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService);
|
2018-02-24 19:48:55 +01:00
|
|
|
}
|
2018-12-26 17:02:02 +01:00
|
|
|
|
2019-01-08 06:21:28 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
2018-12-26 17:02:02 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 04:47:53 +01:00
|
|
|
}
|