lock reload

This commit is contained in:
Kyle Spearrin 2019-02-25 15:07:19 -05:00
parent fc2f64ee36
commit 9a4611ec5a
2 changed files with 30 additions and 0 deletions

View File

@ -6,4 +6,6 @@ export abstract class LockService {
setLockOption: (lockOption: number) => Promise<void>;
isPinLockSet: () => Promise<[boolean, boolean]>;
clear: () => Promise<any>;
startLockReload: () => void;
cancelLockReload: () => void;
}

View File

@ -14,6 +14,7 @@ export class LockService implements LockServiceAbstraction {
pinLocked = false;
private inited = false;
private reloadInterval: any = null;
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private cryptoService: CryptoService,
@ -117,4 +118,31 @@ export class LockService implements LockServiceAbstraction {
clear(): Promise<any> {
return this.storageService.remove(ConstantsService.protectedPin);
}
startLockReload(): void {
if (this.pinLocked || this.reloadInterval != null) {
return;
}
this.reloadInterval = 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) {
clearInterval(this.reloadInterval);
this.reloadInterval = null;
this.messagingService.send('reloadProcess');
}
}, 10000);
}
cancelLockReload(): void {
if (this.reloadInterval != null) {
clearInterval(this.reloadInterval);
this.reloadInterval = null;
}
}
}