diff --git a/jslib b/jslib index 31a257407b..28e3fff739 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 31a257407be7f8f47624b0d021363aaf2cfda2d7 +Subproject commit 28e3fff739e64c2dd80d3d98717e2921895d16df diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index edf1c9e834..e2637fe435 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -321,8 +321,8 @@ "invalidMasterPassword": { "message": "Invalid master password" }, - "lockOptions": { - "message": "Lock Options" + "vaultTimeout": { + "message": "Vault Timeout" }, "lockNow": { "message": "Lock Now" @@ -1247,5 +1247,12 @@ }, "passwordGeneratorPolicyInEffect": { "message": "One or more organization policies are affecting your generator settings." + }, + "vaultTimeoutAction": { + "message": "Vault Timeout Action" + }, + "lock": { + "message": "Lock", + "description": "Verb form: to make secure or inaccesible by" } } diff --git a/src/background/commands.background.ts b/src/background/commands.background.ts index 7a6b2adc32..ae10d4c730 100644 --- a/src/background/commands.background.ts +++ b/src/background/commands.background.ts @@ -4,9 +4,9 @@ import MainBackground from './main.background'; import { Analytics } from 'jslib/misc'; -import { LockService } from 'jslib/abstractions/lock.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; export default class CommandsBackground { private isSafari: boolean; @@ -15,7 +15,7 @@ export default class CommandsBackground { constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService, private platformUtilsService: PlatformUtilsService, private analytics: Analytics, - private lockService: LockService) { + private vaultTimeoutService: VaultTimeoutService) { this.isSafari = this.platformUtilsService.isSafari(); this.isEdge = this.platformUtilsService.isEdge(); this.isVivaldi = this.platformUtilsService.isVivaldi(); @@ -69,7 +69,7 @@ export default class CommandsBackground { } private async autoFillLogin(tab?: any) { - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } diff --git a/src/background/contextMenus.background.ts b/src/background/contextMenus.background.ts index 07b104b0aa..fb335c879f 100644 --- a/src/background/contextMenus.background.ts +++ b/src/background/contextMenus.background.ts @@ -6,10 +6,10 @@ import { Analytics } from 'jslib/misc'; import { CipherService } from 'jslib/abstractions/cipher.service'; import { EventService } from 'jslib/abstractions/event.service'; -import { LockService } from 'jslib/abstractions/lock.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { TotpService } from 'jslib/abstractions/totp.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; import { EventType } from 'jslib/enums/eventType'; @@ -18,7 +18,7 @@ export default class ContextMenusBackground { constructor(private main: MainBackground, private cipherService: CipherService, private passwordGenerationService: PasswordGenerationService, private analytics: Analytics, - private platformUtilsService: PlatformUtilsService, private lockService: LockService, + private platformUtilsService: PlatformUtilsService, private vaultTimeoutService: VaultTimeoutService, private eventService: EventService, private totpService: TotpService) { this.contextMenus = chrome.contextMenus; } @@ -61,7 +61,7 @@ export default class ContextMenusBackground { return; } - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } diff --git a/src/background/idle.background.ts b/src/background/idle.background.ts index ac6dd82a56..d65c2d1856 100644 --- a/src/background/idle.background.ts +++ b/src/background/idle.background.ts @@ -1,8 +1,8 @@ import { ConstantsService } from 'jslib/services/constants.service'; import { - LockService, StorageService, + VaultTimeoutService, } from 'jslib/abstractions'; import { NotificationsService } from 'jslib/abstractions/notifications.service'; @@ -13,7 +13,7 @@ export default class IdleBackground { private idleTimer: number = null; private idleState = 'active'; - constructor(private lockService: LockService, private storageService: StorageService, + constructor(private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService, private notificationsService: NotificationsService) { this.idle = chrome.idle || (browser != null ? browser.idle : null); } @@ -39,10 +39,15 @@ export default class IdleBackground { if (this.idle.onStateChanged) { this.idle.onStateChanged.addListener(async (newState: string) => { - if (newState === 'locked') { - const lockOption = await this.storageService.get(ConstantsService.lockOptionKey); - if (lockOption === -2) { - this.lockService.lock(true); + if (newState === 'locked') { // If the screen is locked or the screensaver activates + const timeout = await this.storageService.get(ConstantsService.vaultTimeoutKey); + if (timeout === -2) { // On System Lock vault timeout option + const action = await this.storageService.get(ConstantsService.vaultTimeoutActionKey); + if (action === 'lock') { + await this.vaultTimeoutService.lock(true); + } else { + await this.vaultTimeoutService.logOut(); + } } } }); diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 894cfecd59..20e0bbe182 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -11,13 +11,13 @@ import { CryptoService, EnvironmentService, FolderService, - LockService, PasswordGenerationService, SettingsService, SyncService, TokenService, TotpService, UserService, + VaultTimeoutService, } from 'jslib/services'; import { EventService } from 'jslib/services/event.service'; import { ExportService } from 'jslib/services/export.service'; @@ -37,7 +37,6 @@ import { EnvironmentService as EnvironmentServiceAbstraction, FolderService as FolderServiceAbstraction, I18nService as I18nServiceAbstraction, - LockService as LockServiceAbstraction, MessagingService as MessagingServiceAbstraction, PasswordGenerationService as PasswordGenerationServiceAbstraction, PlatformUtilsService as PlatformUtilsServiceAbstraction, @@ -47,6 +46,7 @@ import { TokenService as TokenServiceAbstraction, TotpService as TotpServiceAbstraction, UserService as UserServiceAbstraction, + VaultTimeoutService as VaultTimeoutServiceAbstraction, } from 'jslib/abstractions'; import { EventService as EventServiceAbstraction } from 'jslib/abstractions/event.service'; import { ExportService as ExportServiceAbstraction } from 'jslib/abstractions/export.service'; @@ -94,7 +94,7 @@ export default class MainBackground { cipherService: CipherServiceAbstraction; folderService: FolderServiceAbstraction; collectionService: CollectionServiceAbstraction; - lockService: LockServiceAbstraction; + vaultTimeoutService: VaultTimeoutServiceAbstraction; syncService: SyncServiceAbstraction; passwordGenerationService: PasswordGenerationServiceAbstraction; totpService: TotpServiceAbstraction; @@ -156,9 +156,9 @@ export default class MainBackground { this.i18nService); this.searchService = new SearchService(this.cipherService, this.platformUtilsService); this.policyService = new PolicyService(this.userService, this.storageService); - this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService, - this.cryptoService, this.platformUtilsService, this.storageService, this.messagingService, - this.searchService, this.userService, async () => { + this.vaultTimeoutService = new VaultTimeoutService(this.cipherService, this.folderService, + this.collectionService, this.cryptoService, this.platformUtilsService, this.storageService, + this.messagingService, this.searchService, this.userService, async () => { if (this.notificationsService != null) { this.notificationsService.updateConnection(false); } @@ -168,7 +168,7 @@ export default class MainBackground { this.systemService.startProcessReload(); await this.systemService.clearPendingClipboard(); } - }); + }, async () => await this.logout(false)); this.syncService = new SyncService(this.userService, this.apiService, this.settingsService, this.folderService, this.cipherService, this.cryptoService, this.collectionService, this.storageService, this.messagingService, this.policyService, @@ -184,12 +184,12 @@ export default class MainBackground { this.auditService = new AuditService(cryptoFunctionService, this.apiService); this.exportService = new ExportService(this.folderService, this.cipherService, this.apiService); this.notificationsService = new NotificationsService(this.userService, this.syncService, this.appIdService, - this.apiService, this.lockService, () => this.logout(true)); + this.apiService, this.vaultTimeoutService, () => this.logout(true)); this.environmentService = new EnvironmentService(this.apiService, this.storageService, this.notificationsService); this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService, this.storageService, this.appIdService); - this.systemService = new SystemService(this.storageService, this.lockService, + this.systemService = new SystemService(this.storageService, this.vaultTimeoutService, this.messagingService, this.platformUtilsService, () => { const forceWindowReload = this.platformUtilsService.isSafari() || this.platformUtilsService.isFirefox() || this.platformUtilsService.isOpera(); @@ -205,18 +205,19 @@ export default class MainBackground { // Background this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService, this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService, - this.analytics, this.notificationsService, this.systemService, this.lockService); + this.analytics, this.notificationsService, this.systemService, this.vaultTimeoutService); this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService, - this.platformUtilsService, this.analytics, this.lockService); + this.platformUtilsService, this.analytics, this.vaultTimeoutService); if (!this.isSafari) { this.tabsBackground = new TabsBackground(this); this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService, - this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService, + this.passwordGenerationService, this.analytics, this.platformUtilsService, this.vaultTimeoutService, this.eventService, this.totpService); - this.idleBackground = new IdleBackground(this.lockService, this.storageService, this.notificationsService); + this.idleBackground = new IdleBackground(this.vaultTimeoutService, this.storageService, + this.notificationsService); this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService, - this.lockService); + this.vaultTimeoutService); this.windowsBackground = new WindowsBackground(this); } } @@ -226,7 +227,7 @@ export default class MainBackground { this.analytics.ga('send', 'pageview', '/background.html'); this.containerService.attachToWindow(window); - await (this.lockService as LockService).init(true); + await (this.vaultTimeoutService as VaultTimeoutService).init(true); await (this.i18nService as I18nService).init(); await (this.eventService as EventService).init(true); await this.runtimeBackground.init(); @@ -258,7 +259,7 @@ export default class MainBackground { } const isAuthenticated = await this.userService.isAuthenticated(); - const locked = await this.lockService.isLocked(); + const locked = await this.vaultTimeoutService.isLocked(); let suffix = ''; if (!isAuthenticated) { @@ -311,7 +312,7 @@ export default class MainBackground { this.collectionService.clear(userId), this.policyService.clear(userId), this.passwordGenerationService.clear(), - this.lockService.clear(), + this.vaultTimeoutService.clear(), ]); this.searchService.clearIndex(); @@ -330,7 +331,7 @@ export default class MainBackground { return; } - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } @@ -378,8 +379,8 @@ export default class MainBackground { return; } - const currentLockOption = await this.storageService.get(ConstantsService.lockOptionKey); - if (currentLockOption == null) { + const currentVaultTimeout = await this.storageService.get(ConstantsService.vaultTimeoutKey); + if (currentVaultTimeout == null) { return; } @@ -482,7 +483,7 @@ export default class MainBackground { this.actionSetBadgeBackgroundColor(this.sidebarAction); this.menuOptionsLoaded = []; - const locked = await this.lockService.isLocked(); + const locked = await this.vaultTimeoutService.isLocked(); if (!locked) { try { const ciphers = await this.cipherService.getAllDecryptedForUrl(url); diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 72ee3ef153..7578f109db 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -11,9 +11,9 @@ import { I18nService } from 'jslib/abstractions/i18n.service'; import { Analytics } from 'jslib/misc'; import { CipherService } from 'jslib/abstractions/cipher.service'; -import { LockService } from 'jslib/abstractions/lock.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { SystemService } from 'jslib/abstractions/system.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; import { BrowserApi } from '../browser/browserApi'; @@ -37,7 +37,7 @@ export default class RuntimeBackground { private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService, private storageService: StorageService, private i18nService: I18nService, private analytics: Analytics, private notificationsService: NotificationsService, - private systemService: SystemService, private lockService: LockService) { + private systemService: SystemService, private vaultTimeoutService: VaultTimeoutService) { this.isSafari = this.platformUtilsService.isSafari(); this.runtime = this.isSafari ? {} : chrome.runtime; @@ -127,7 +127,7 @@ export default class RuntimeBackground { await this.main.reseedStorage(); break; case 'collectPageDetailsResponse': - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } switch (msg.sender) { @@ -183,7 +183,7 @@ export default class RuntimeBackground { } private async saveAddLogin(tab: any) { - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } @@ -223,7 +223,7 @@ export default class RuntimeBackground { } private async saveChangePassword(tab: any) { - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } @@ -276,7 +276,7 @@ export default class RuntimeBackground { } private async addLogin(loginInfo: any, tab: any) { - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } @@ -322,7 +322,7 @@ export default class RuntimeBackground { } private async changedPassword(changeData: any, tab: any) { - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { return; } @@ -400,10 +400,16 @@ export default class RuntimeBackground { } private async setDefaultSettings() { - // Default lock options to "on restart". - const currentLockOption = await this.storageService.get(ConstantsService.lockOptionKey); - if (currentLockOption == null) { - await this.storageService.save(ConstantsService.lockOptionKey, -1); + // Default timeout option to "on restart". + const currentVaultTimeout = await this.storageService.get(ConstantsService.vaultTimeoutKey); + if (currentVaultTimeout == null) { + await this.storageService.save(ConstantsService.vaultTimeoutKey, -1); + } + + // Default action to "lock". + const currentVaultTimeoutAction = await this.storageService.get(ConstantsService.vaultTimeoutActionKey); + if (currentVaultTimeoutAction == null) { + await this.storageService.save(ConstantsService.vaultTimeoutActionKey, 'lock'); } } diff --git a/src/background/webRequest.background.ts b/src/background/webRequest.background.ts index 14ae4a2691..e0d8913713 100644 --- a/src/background/webRequest.background.ts +++ b/src/background/webRequest.background.ts @@ -1,6 +1,6 @@ import { CipherService } from 'jslib/abstractions/cipher.service'; -import { LockService } from 'jslib/abstractions/lock.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; export default class WebRequestBackground { private pendingAuthRequests: any[] = []; @@ -8,7 +8,7 @@ export default class WebRequestBackground { private isFirefox: boolean; constructor(platformUtilsService: PlatformUtilsService, private cipherService: CipherService, - private lockService: LockService) { + private vaultTimeoutService: VaultTimeoutService) { this.webRequest = (window as any).chrome.webRequest; this.isFirefox = platformUtilsService.isFirefox(); } @@ -44,7 +44,7 @@ export default class WebRequestBackground { } private async resolveAuthCredentials(domain: string, success: Function, error: Function) { - if (await this.lockService.isLocked()) { + if (await this.vaultTimeoutService.isLocked()) { error(); return; } diff --git a/src/popup/accounts/lock.component.ts b/src/popup/accounts/lock.component.ts index 708ee746bc..f31716e527 100644 --- a/src/popup/accounts/lock.component.ts +++ b/src/popup/accounts/lock.component.ts @@ -4,12 +4,12 @@ import { Router } from '@angular/router'; import { CryptoService } from 'jslib/abstractions/crypto.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; -import { LockService } from 'jslib/abstractions/lock.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component'; @@ -21,10 +21,10 @@ export class LockComponent extends BaseLockComponent { constructor(router: Router, i18nService: I18nService, platformUtilsService: PlatformUtilsService, messagingService: MessagingService, userService: UserService, cryptoService: CryptoService, - storageService: StorageService, lockService: LockService, + storageService: StorageService, vaultTimeoutService: VaultTimeoutService, environmentService: EnvironmentService, stateService: StateService) { super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService, - storageService, lockService, environmentService, stateService); + storageService, vaultTimeoutService, environmentService, stateService); this.successRoute = '/tabs/current'; } diff --git a/src/popup/services/launch-guard.service.ts b/src/popup/services/launch-guard.service.ts index b4bec3b155..4e19dba4ad 100644 --- a/src/popup/services/launch-guard.service.ts +++ b/src/popup/services/launch-guard.service.ts @@ -6,12 +6,13 @@ import { Router, } from '@angular/router'; -import { LockService } from 'jslib/abstractions/lock.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; @Injectable() export class LaunchGuardService implements CanActivate { - constructor(private lockService: LockService, private userService: UserService, private router: Router) { } + constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService, + private router: Router) { } async canActivate() { if (BrowserApi.getBackgroundPage() == null) { @@ -28,7 +29,7 @@ export class LaunchGuardService implements CanActivate { return true; } - const locked = await this.lockService.isLocked(); + const locked = await this.vaultTimeoutService.isLocked(); if (locked) { this.router.navigate(['lock']); } else { diff --git a/src/popup/services/services.module.ts b/src/popup/services/services.module.ts index 5a6293136d..e02050ed01 100644 --- a/src/popup/services/services.module.ts +++ b/src/popup/services/services.module.ts @@ -26,7 +26,6 @@ import { EventService } from 'jslib/abstractions/event.service'; import { ExportService } from 'jslib/abstractions/export.service'; import { FolderService } from 'jslib/abstractions/folder.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; -import { LockService } from 'jslib/abstractions/lock.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { NotificationsService } from 'jslib/abstractions/notifications.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; @@ -40,6 +39,7 @@ import { SyncService } from 'jslib/abstractions/sync.service'; import { TokenService } from 'jslib/abstractions/token.service'; import { TotpService } from 'jslib/abstractions/totp.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; import { AutofillService } from '../../services/abstractions/autofill.service'; import BrowserMessagingService from '../../services/browserMessaging.service'; @@ -146,11 +146,15 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer { provide: SyncService, useFactory: getBgService('syncService'), deps: [] }, { provide: UserService, useFactory: getBgService('userService'), deps: [] }, { provide: SettingsService, useFactory: getBgService('settingsService'), deps: [] }, - { provide: LockService, useFactory: getBgService('lockService'), deps: [] }, { provide: StorageService, useFactory: getBgService('storageService'), deps: [] }, { provide: AppIdService, useFactory: getBgService('appIdService'), deps: [] }, { provide: AutofillService, useFactory: getBgService('autofillService'), deps: [] }, { provide: ExportService, useFactory: getBgService('exportService'), deps: [] }, + { + provide: VaultTimeoutService, + useFactory: getBgService('vaultTimeoutService'), + deps: [], + }, { provide: NotificationsService, useFactory: getBgService('notificationsService'), diff --git a/src/popup/settings/settings.component.html b/src/popup/settings/settings.component.html index 85d1f9ad90..d96e3fe972 100644 --- a/src/popup/settings/settings.component.html +++ b/src/popup/settings/settings.component.html @@ -25,10 +25,17 @@
{{'security' | i18n}}
- - + + +
+
+ +
diff --git a/src/popup/settings/settings.component.ts b/src/popup/settings/settings.component.ts index 5170e53eb8..6bc8c679ef 100644 --- a/src/popup/settings/settings.component.ts +++ b/src/popup/settings/settings.component.ts @@ -18,11 +18,11 @@ import { ConstantsService } from 'jslib/services/constants.service'; import { CryptoService } from 'jslib/abstractions/crypto.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; -import { LockService } from 'jslib/abstractions/lock.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; const RateUrls = { [DeviceType.ChromeExtension]: @@ -44,14 +44,16 @@ const RateUrls = { templateUrl: 'settings.component.html', }) export class SettingsComponent implements OnInit { - @ViewChild('lockOptionsSelect', { read: ElementRef }) lockOptionsSelectRef: ElementRef; - lockOptions: any[]; - lockOption: number = null; + @ViewChild('vaultTimeoutSelect', { read: ElementRef }) vaultTimeoutSelectRef: ElementRef; + vaultTimeouts: any[]; + vaultTimeout: number = null; + vaultTimeoutActions: any[]; + vaultTimeoutAction: string; pin: boolean = null; - previousLockOption: number = null; + previousVaultTimeout: number = null; constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private analytics: Angulartics2, private lockService: LockService, + private analytics: Angulartics2, private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService, public messagingService: MessagingService, private router: Router, private environmentService: EnvironmentService, private cryptoService: CryptoService, private userService: UserService) { @@ -61,7 +63,7 @@ export class SettingsComponent implements OnInit { const showOnLocked = !this.platformUtilsService.isFirefox() && !this.platformUtilsService.isEdge() && !this.platformUtilsService.isSafari(); - this.lockOptions = [ + this.vaultTimeouts = [ { name: this.i18nService.t('immediately'), value: 0 }, { name: this.i18nService.t('oneMinute'), value: 1 }, { name: this.i18nService.t('fiveMinutes'), value: 5 }, @@ -74,47 +76,61 @@ export class SettingsComponent implements OnInit { ]; if (showOnLocked) { - this.lockOptions.push({ name: this.i18nService.t('onLocked'), value: -2 }); + this.vaultTimeouts.push({ name: this.i18nService.t('onLocked'), value: -2 }); } - this.lockOptions.push({ name: this.i18nService.t('onRestart'), value: -1 }); - this.lockOptions.push({ name: this.i18nService.t('never'), value: null }); + this.vaultTimeouts.push({ name: this.i18nService.t('onRestart'), value: -1 }); + this.vaultTimeouts.push({ name: this.i18nService.t('never'), value: null }); - let option = await this.storageService.get(ConstantsService.lockOptionKey); - if (option != null) { - if (option === -2 && !showOnLocked) { - option = -1; + this.vaultTimeoutActions = [ + { name: this.i18nService.t('lock'), value: 'lock' }, + { name: this.i18nService.t('logOut'), value: 'logOut' }, + ]; + + let timeout = await this.storageService.get(ConstantsService.vaultTimeoutKey); + if (timeout != null) { + if (timeout === -2 && !showOnLocked) { + timeout = -1; } - this.lockOption = option; + this.vaultTimeout = timeout; } - this.previousLockOption = this.lockOption; + this.previousVaultTimeout = this.vaultTimeout; + const action = await this.storageService.get(ConstantsService.vaultTimeoutActionKey); + this.vaultTimeoutAction = action == null ? 'lock' : action; - const pinSet = await this.lockService.isPinLockSet(); + const pinSet = await this.vaultTimeoutService.isPinLockSet(); this.pin = pinSet[0] || pinSet[1]; } - async saveLockOption(newValue: number) { + async saveVaultTimeout(newValue: number) { if (newValue == null) { const confirmed = await this.platformUtilsService.showDialog( this.i18nService.t('neverLockWarning'), null, this.i18nService.t('yes'), this.i18nService.t('cancel'), 'warning'); if (!confirmed) { - this.lockOptions.forEach((option: any, i) => { - if (option.value === this.lockOption) { - this.lockOptionsSelectRef.nativeElement.value = i + ': ' + this.lockOption; + this.vaultTimeouts.forEach((option: any, i) => { + if (option.value === this.vaultTimeout) { + this.vaultTimeoutSelectRef.nativeElement.value = i + ': ' + this.vaultTimeout; } }); return; } } - this.previousLockOption = this.lockOption; - this.lockOption = newValue; - await this.lockService.setLockOption(this.lockOption != null ? this.lockOption : null); - if (this.previousLockOption == null) { + this.previousVaultTimeout = this.vaultTimeout; + this.vaultTimeout = newValue; + await this.vaultTimeoutService.setVaultTimeoutOptions(this.vaultTimeout != null ? this.vaultTimeout : null, + this.vaultTimeoutAction); + if (this.previousVaultTimeout == null) { this.messagingService.send('bgReseedStorage'); } } + async saveVaultTimeoutAction(newValue: string) { + this.vaultTimeoutAction = newValue; + await this.vaultTimeoutService.setVaultTimeoutOptions(this.vaultTimeout != null ? this.vaultTimeout : null, + this.vaultTimeoutAction); + } + async updatePin() { if (this.pin) { const div = document.createElement('div'); @@ -160,7 +176,7 @@ export class SettingsComponent implements OnInit { if (masterPassOnRestart) { const encPin = await this.cryptoService.encrypt(pin); await this.storageService.save(ConstantsService.protectedPin, encPin.encryptedString); - this.lockService.pinProtectedKey = pinProtectedKey; + this.vaultTimeoutService.pinProtectedKey = pinProtectedKey; } else { await this.storageService.save(ConstantsService.pinProtectedKey, pinProtectedKey.encryptedString); } @@ -170,13 +186,13 @@ export class SettingsComponent implements OnInit { } if (!this.pin) { await this.cryptoService.clearPinProtectedKey(); - await this.lockService.clear(); + await this.vaultTimeoutService.clear(); } } async lock() { this.analytics.eventTrack.next({ action: 'Lock Now' }); - await this.lockService.lock(true); + await this.vaultTimeoutService.lock(true); } async logOut() {