1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 18:53:29 +00:00

move lock service ti jslib

This commit is contained in:
Kyle Spearrin
2018-01-09 23:18:55 -05:00
parent 5c98e94198
commit 7ca71cb9a1
4 changed files with 9 additions and 73 deletions

View File

@@ -1,68 +0,0 @@
import {
ConstantsService,
} from 'jslib/services';
import {
CipherService,
CollectionService,
CryptoService,
FolderService,
PlatformUtilsService,
StorageService,
} from 'jslib/abstractions';
export default class LockService {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private cryptoService: CryptoService,
private platformUtilsService: PlatformUtilsService,
private storageService: StorageService,
private setIcon: Function, private refreshBadgeAndMenu: Function) {
this.checkLock();
setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds
}
async checkLock(): Promise<void> {
if (this.platformUtilsService.isViewOpen()) {
// Do not lock
return;
}
const key = await this.cryptoService.getKey();
if (key == null) {
// no key so no need to lock
return;
}
const lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
if (lockOption == null || lockOption < 0) {
return;
}
const lastActive = await this.storageService.get<number>(ConstantsService.lastActiveKey);
if (lastActive == null) {
return;
}
const lockOptionSeconds = lockOption * 60;
const diffSeconds = ((new Date()).getTime() - lastActive) / 1000;
if (diffSeconds >= lockOptionSeconds) {
// need to lock now
await this.lock();
}
}
async lock(): Promise<void> {
await Promise.all([
this.cryptoService.clearKey(),
this.cryptoService.clearOrgKeys(true),
this.cryptoService.clearPrivateKey(true),
this.cryptoService.clearEncKey(true),
this.setIcon(),
this.refreshBadgeAndMenu(),
]);
this.folderService.clearCache();
this.cipherService.clearCache();
this.collectionService.clearCache();
}
}