From e6fde2e92be4be472933234daa7bae242ee17794 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 16 May 2018 10:18:05 -0400 Subject: [PATCH] move lock service interval to init --- src/services/lock.service.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/services/lock.service.ts b/src/services/lock.service.ts index 43b9e57d56..dbc26f8140 100644 --- a/src/services/lock.service.ts +++ b/src/services/lock.service.ts @@ -10,12 +10,24 @@ import { PlatformUtilsService } from '../abstractions/platformUtils.service'; import { StorageService } from '../abstractions/storage.service'; export class LockService implements LockServiceAbstraction { + private inited = false; + constructor(private cipherService: CipherService, private folderService: FolderService, private collectionService: CollectionService, private cryptoService: CryptoService, private platformUtilsService: PlatformUtilsService, private storageService: StorageService, - private messagingService: MessagingService, private lockedCallback: Function) { - this.checkLock(); - setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds + private messagingService: MessagingService, private lockedCallback: () => Promise) { + } + + init(checkOnInterval: boolean) { + if (this.inited) { + return; + } + + this.inited = true; + if (checkOnInterval) { + this.checkLock(); + setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds + } } async checkLock(): Promise { @@ -60,7 +72,9 @@ export class LockService implements LockServiceAbstraction { this.cipherService.clearCache(); this.collectionService.clearCache(); this.messagingService.send('locked'); - this.lockedCallback(); + if (this.lockedCallback != null) { + await this.lockedCallback(); + } } async setLockOption(lockOption: number): Promise {