mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-31 17:57:43 +01:00
move lock service ti jslib
This commit is contained in:
parent
5c98e94198
commit
7ca71cb9a1
@ -1,9 +1,11 @@
|
||||
import LockService from '../services/lock.service';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import { ConstantsService } from 'jslib/services';
|
||||
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
import {
|
||||
LockService,
|
||||
StorageService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
export default class IdleBackground {
|
||||
private idle: any;
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
CryptoService,
|
||||
EnvironmentService,
|
||||
FolderService,
|
||||
LockService,
|
||||
PasswordGenerationService,
|
||||
SettingsService,
|
||||
TokenService,
|
||||
@ -26,6 +27,7 @@ import {
|
||||
CryptoService as CryptoServiceAbstraction,
|
||||
EnvironmentService as EnvironmentServiceAbstraction,
|
||||
FolderService as FolderServiceAbstraction,
|
||||
LockService as LockServiceAbstraction,
|
||||
MessagingService as MessagingServiceAbstraction,
|
||||
PasswordGenerationService as PasswordGenerationServiceAbstraction,
|
||||
PlatformUtilsService as PlatformUtilsServiceAbstraction,
|
||||
@ -52,7 +54,6 @@ import BrowserMessagingService from '../services/browserMessaging.service';
|
||||
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
|
||||
import BrowserStorageService from '../services/browserStorage.service';
|
||||
import i18nService from '../services/i18n.service';
|
||||
import LockService from '../services/lock.service';
|
||||
import SyncService from '../services/sync.service';
|
||||
|
||||
export default class MainBackground {
|
||||
@ -72,7 +73,7 @@ export default class MainBackground {
|
||||
cipherService: CipherServiceAbstraction;
|
||||
folderService: FolderServiceAbstraction;
|
||||
collectionService: CollectionServiceAbstraction;
|
||||
lockService: LockService;
|
||||
lockService: LockServiceAbstraction;
|
||||
syncService: SyncService;
|
||||
passwordGenerationService: PasswordGenerationServiceAbstraction;
|
||||
totpService: TotpServiceAbstraction;
|
||||
|
@ -7,6 +7,7 @@ import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||
import { LockService } from 'jslib/abstractions/lock.service';
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.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 constantsService = getBackgroundService<ConstantsService>('constantsService');
|
||||
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 environmentService = getBackgroundService<EnvironmentService>('environmentService');
|
||||
export const collectionService = getBackgroundService<CollectionService>('collectionService');
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user