diff --git a/src/abstractions/lock.service.ts b/src/abstractions/lock.service.ts index ede31db0b..e40bc0028 100644 --- a/src/abstractions/lock.service.ts +++ b/src/abstractions/lock.service.ts @@ -6,4 +6,6 @@ export abstract class LockService { setLockOption: (lockOption: number) => Promise; isPinLockSet: () => Promise<[boolean, boolean]>; clear: () => Promise; + startLockReload: () => void; + cancelLockReload: () => void; } diff --git a/src/services/lock.service.ts b/src/services/lock.service.ts index 941e86f24..14c13a1a0 100644 --- a/src/services/lock.service.ts +++ b/src/services/lock.service.ts @@ -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 { 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(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; + } + } }