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,9 +1,11 @@
import LockService from '../services/lock.service';
import MainBackground from './main.background'; import MainBackground from './main.background';
import { ConstantsService } from 'jslib/services'; import { ConstantsService } from 'jslib/services';
import { StorageService } from 'jslib/abstractions'; import {
LockService,
StorageService,
} from 'jslib/abstractions';
export default class IdleBackground { export default class IdleBackground {
private idle: any; private idle: any;

View File

@ -10,6 +10,7 @@ import {
CryptoService, CryptoService,
EnvironmentService, EnvironmentService,
FolderService, FolderService,
LockService,
PasswordGenerationService, PasswordGenerationService,
SettingsService, SettingsService,
TokenService, TokenService,
@ -26,6 +27,7 @@ import {
CryptoService as CryptoServiceAbstraction, CryptoService as CryptoServiceAbstraction,
EnvironmentService as EnvironmentServiceAbstraction, EnvironmentService as EnvironmentServiceAbstraction,
FolderService as FolderServiceAbstraction, FolderService as FolderServiceAbstraction,
LockService as LockServiceAbstraction,
MessagingService as MessagingServiceAbstraction, MessagingService as MessagingServiceAbstraction,
PasswordGenerationService as PasswordGenerationServiceAbstraction, PasswordGenerationService as PasswordGenerationServiceAbstraction,
PlatformUtilsService as PlatformUtilsServiceAbstraction, PlatformUtilsService as PlatformUtilsServiceAbstraction,
@ -52,7 +54,6 @@ import BrowserMessagingService from '../services/browserMessaging.service';
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service'; import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
import BrowserStorageService from '../services/browserStorage.service'; import BrowserStorageService from '../services/browserStorage.service';
import i18nService from '../services/i18n.service'; import i18nService from '../services/i18n.service';
import LockService from '../services/lock.service';
import SyncService from '../services/sync.service'; import SyncService from '../services/sync.service';
export default class MainBackground { export default class MainBackground {
@ -72,7 +73,7 @@ export default class MainBackground {
cipherService: CipherServiceAbstraction; cipherService: CipherServiceAbstraction;
folderService: FolderServiceAbstraction; folderService: FolderServiceAbstraction;
collectionService: CollectionServiceAbstraction; collectionService: CollectionServiceAbstraction;
lockService: LockService; lockService: LockServiceAbstraction;
syncService: SyncService; syncService: SyncService;
passwordGenerationService: PasswordGenerationServiceAbstraction; passwordGenerationService: PasswordGenerationServiceAbstraction;
totpService: TotpServiceAbstraction; totpService: TotpServiceAbstraction;

View File

@ -7,6 +7,7 @@ import { CollectionService } from 'jslib/abstractions/collection.service';
import { CryptoService } from 'jslib/abstractions/crypto.service'; import { CryptoService } from 'jslib/abstractions/crypto.service';
import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { FolderService } from 'jslib/abstractions/folder.service'; import { FolderService } from 'jslib/abstractions/folder.service';
import { LockService } from 'jslib/abstractions/lock.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { SettingsService } from 'jslib/abstractions/settings.service'; import { SettingsService } from 'jslib/abstractions/settings.service';
@ -39,7 +40,7 @@ export const appIdService = getBackgroundService<AppIdService>('appIdService');
export const i18nService = getBackgroundService<any>('i18nService'); export const i18nService = getBackgroundService<any>('i18nService');
export const constantsService = getBackgroundService<ConstantsService>('constantsService'); export const constantsService = getBackgroundService<ConstantsService>('constantsService');
export const settingsService = getBackgroundService<SettingsService>('settingsService'); export const settingsService = getBackgroundService<SettingsService>('settingsService');
export const lockService = getBackgroundService<any>('lockService'); export const lockService = getBackgroundService<LockService>('lockService');
export const totpService = getBackgroundService<TotpService>('totpService'); export const totpService = getBackgroundService<TotpService>('totpService');
export const environmentService = getBackgroundService<EnvironmentService>('environmentService'); export const environmentService = getBackgroundService<EnvironmentService>('environmentService');
export const collectionService = getBackgroundService<CollectionService>('collectionService'); export const collectionService = getBackgroundService<CollectionService>('collectionService');

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();
}
}