Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
lock reload
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Feb 25, 2019
1 parent fc2f64e commit 9a4611e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/abstractions/lock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export abstract class LockService {
setLockOption: (lockOption: number) => Promise<void>;
isPinLockSet: () => Promise<[boolean, boolean]>;
clear: () => Promise<any>;
startLockReload: () => void;
cancelLockReload: () => void;
}
28 changes: 28 additions & 0 deletions src/services/lock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 9a4611e

Please sign in to comment.