diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 21c52ab6da1..1c7db74812f 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -115,6 +115,7 @@ containerService.attachToWindow(window); export function initFactory(): Function { return async () => { + await (storageService as HtmlStorageService).init(); const isDev = platformUtilsService.isDev(); if (!isDev && platformUtilsService.isSelfHost()) { environmentService.baseUrl = window.location.origin; diff --git a/src/app/settings/options.component.html b/src/app/settings/options.component.html index 329cddc1319..aa8ce67b96f 100644 --- a/src/app/settings/options.component.html +++ b/src/app/settings/options.component.html @@ -3,6 +3,17 @@

{{'optionsDesc' | i18n}}

+
+
+
+ + + {{'lockOptionsDesc' | i18n}} +
+
+
diff --git a/src/app/settings/options.component.ts b/src/app/settings/options.component.ts index bd552837f35..f12f8c6dc59 100644 --- a/src/app/settings/options.component.ts +++ b/src/app/settings/options.component.ts @@ -7,6 +7,7 @@ import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; import { I18nService } from 'jslib/abstractions/i18n.service'; +import { LockService } from 'jslib/abstractions/lock.service'; import { StateService } from 'jslib/abstractions/state.service'; import { StorageService } from 'jslib/abstractions/storage.service'; @@ -19,15 +20,27 @@ import { Utils } from 'jslib/misc/utils'; templateUrl: 'options.component.html', }) export class OptionsComponent implements OnInit { + lockOption: number = null; disableIcons: boolean; locale: string; + lockOptions: any[]; localeOptions: any[]; private startingLocale: string; constructor(private storageService: StorageService, private stateService: StateService, private analytics: Angulartics2, private i18nService: I18nService, - private toasterService: ToasterService) { + private toasterService: ToasterService, private lockService: LockService) { + this.lockOptions = [ + { name: i18nService.t('oneMinute'), value: 1 }, + { name: i18nService.t('fiveMinutes'), value: 5 }, + { name: i18nService.t('fifteenMinutes'), value: 15 }, + { name: i18nService.t('thirtyMinutes'), value: 30 }, + { name: i18nService.t('oneHour'), value: 60 }, + { name: i18nService.t('fourHours'), value: 240 }, + { name: i18nService.t('onRefresh'), value: -1 }, + ]; + const localeOptions: any[] = []; i18nService.supportedTranslationLocales.forEach((locale) => { localeOptions.push({ name: locale, value: locale }); @@ -38,11 +51,13 @@ export class OptionsComponent implements OnInit { } async ngOnInit() { + this.lockOption = await this.storageService.get(ConstantsService.lockOptionKey); this.disableIcons = await this.storageService.get(ConstantsService.disableFaviconKey); this.locale = this.startingLocale = await this.storageService.get(ConstantsService.localeKey); } async submit() { + await this.lockService.setLockOption(this.lockOption != null ? this.lockOption : null); await this.storageService.save(ConstantsService.disableFaviconKey, this.disableIcons); await this.stateService.save(ConstantsService.disableFaviconKey, this.disableIcons); await this.storageService.save(ConstantsService.localeKey, this.locale); diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index b84300caf78..788b6f352fe 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -2350,5 +2350,32 @@ }, "filters": { "message": "Filters" + }, + "lockOptions": { + "message": "Lock Options" + }, + "lockOptionsDesc": { + "message": "Choose when your vault locks. A locked vault requires that you re-enter your master password to access it again." + }, + "oneMinute": { + "message": "1 minute" + }, + "fiveMinutes": { + "message": "5 minutes" + }, + "fifteenMinutes": { + "message": "15 minutes" + }, + "thirtyMinutes": { + "message": "30 minutes" + }, + "oneHour": { + "message": "1 hour" + }, + "fourHours": { + "message": "4 hours" + }, + "onRefresh": { + "message": "On Refresh" } } diff --git a/src/services/htmlStorage.service.ts b/src/services/htmlStorage.service.ts index a2e4033ae67..89155b7b636 100644 --- a/src/services/htmlStorage.service.ts +++ b/src/services/htmlStorage.service.ts @@ -7,6 +7,13 @@ export class HtmlStorageService implements StorageService { ConstantsService.localeKey, ConstantsService.lockOptionKey]); private localStorageStartsWithKeys = ['twoFactorToken_']; + async init() { + const lockOption = await this.get(ConstantsService.lockOptionKey); + if (lockOption == null) { + await this.save(ConstantsService.lockOptionKey, 15); + } + } + get(key: string): Promise { let json: string = null; if (this.isLocalStorage(key)) { diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index 842343dcdf1..da414566505 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -94,7 +94,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService { } lockTimeout(): number { - return 15; + return null; } launchUri(uri: string, options?: any): void {