2018-04-13 20:19:33 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
2019-01-09 17:59:14 +01:00
|
|
|
import { UriMatchType } from 'jslib/enums/uriMatchType';
|
|
|
|
|
2018-05-30 23:26:43 +02:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2018-04-13 20:19:33 +02:00
|
|
|
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 { TotpService } from 'jslib/abstractions/totp.service';
|
|
|
|
|
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-options',
|
|
|
|
templateUrl: 'options.component.html',
|
|
|
|
})
|
|
|
|
export class OptionsComponent implements OnInit {
|
|
|
|
disableFavicon = false;
|
|
|
|
enableAutoFillOnPageLoad = false;
|
|
|
|
disableAutoTotpCopy = false;
|
|
|
|
disableContextMenuItem = false;
|
|
|
|
disableAddLoginNotification = false;
|
2018-08-01 05:48:11 +02:00
|
|
|
disableChangedPasswordNotification = false;
|
2018-11-21 20:31:34 +01:00
|
|
|
dontShowCards = false;
|
|
|
|
dontShowIdentities = false;
|
2018-04-13 20:19:33 +02:00
|
|
|
showDisableContextMenu = true;
|
2019-03-05 15:26:57 +01:00
|
|
|
showClearClipboard = true;
|
2018-05-30 23:26:43 +02:00
|
|
|
theme: string;
|
|
|
|
themeOptions: any[];
|
2019-01-09 17:59:14 +01:00
|
|
|
defaultUriMatch = UriMatchType.Domain;
|
|
|
|
uriMatchOptions: any[];
|
2019-02-27 17:07:54 +01:00
|
|
|
clearClipboard: number;
|
|
|
|
clearClipboardOptions: any[];
|
2018-04-13 20:19:33 +02:00
|
|
|
|
|
|
|
constructor(private analytics: Angulartics2, private messagingService: MessagingService,
|
|
|
|
private platformUtilsService: PlatformUtilsService, private storageService: StorageService,
|
2018-05-30 23:26:43 +02:00
|
|
|
private stateService: StateService, private totpService: TotpService,
|
2019-01-09 17:59:14 +01:00
|
|
|
i18nService: I18nService) {
|
2018-05-30 23:26:43 +02:00
|
|
|
this.themeOptions = [
|
|
|
|
{ name: i18nService.t('default'), value: null },
|
|
|
|
{ name: i18nService.t('light'), value: 'light' },
|
|
|
|
{ name: i18nService.t('dark'), value: 'dark' },
|
|
|
|
];
|
2019-01-09 17:59:14 +01:00
|
|
|
this.uriMatchOptions = [
|
|
|
|
{ name: i18nService.t('baseDomain'), value: UriMatchType.Domain },
|
|
|
|
{ name: i18nService.t('host'), value: UriMatchType.Host },
|
|
|
|
{ name: i18nService.t('startsWith'), value: UriMatchType.StartsWith },
|
|
|
|
{ name: i18nService.t('regEx'), value: UriMatchType.RegularExpression },
|
|
|
|
{ name: i18nService.t('exact'), value: UriMatchType.Exact },
|
|
|
|
{ name: i18nService.t('never'), value: UriMatchType.Never },
|
|
|
|
];
|
2019-02-27 17:07:54 +01:00
|
|
|
this.clearClipboardOptions = [
|
|
|
|
{ name: i18nService.t('never'), value: null },
|
|
|
|
{ name: i18nService.t('tenSeconds'), value: 10 },
|
|
|
|
{ name: i18nService.t('twentySeconds'), value: 20 },
|
|
|
|
{ name: i18nService.t('thirtySeconds'), value: 30 },
|
|
|
|
{ name: i18nService.t('oneMinute'), value: 60 },
|
|
|
|
{ name: i18nService.t('twoMinutes'), value: 120 },
|
|
|
|
{ name: i18nService.t('fiveMinutes'), value: 300 },
|
|
|
|
];
|
2018-05-30 23:26:43 +02:00
|
|
|
}
|
2018-04-13 20:19:33 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2019-03-05 15:26:57 +01:00
|
|
|
this.showDisableContextMenu = this.showClearClipboard = !this.platformUtilsService.isSafari();
|
2018-04-13 20:19:33 +02:00
|
|
|
|
|
|
|
this.enableAutoFillOnPageLoad = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.enableAutoFillOnPageLoadKey);
|
|
|
|
|
|
|
|
this.disableAddLoginNotification = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableAddLoginNotificationKey);
|
|
|
|
|
2018-08-01 05:48:11 +02:00
|
|
|
this.disableChangedPasswordNotification = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableChangedPasswordNotificationKey);
|
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
this.disableContextMenuItem = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableContextMenuItemKey);
|
|
|
|
|
2018-11-21 20:31:34 +01:00
|
|
|
this.dontShowCards = await this.storageService.get<boolean>(ConstantsService.dontShowCardsCurrentTab);
|
|
|
|
this.dontShowIdentities = await this.storageService.get<boolean>(ConstantsService.dontShowIdentitiesCurrentTab);
|
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
this.disableAutoTotpCopy = !await this.totpService.isAutoCopyEnabled();
|
|
|
|
|
|
|
|
this.disableFavicon = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
|
2018-05-30 23:26:43 +02:00
|
|
|
|
|
|
|
this.theme = await this.storageService.get<string>(ConstantsService.themeKey);
|
2019-01-09 17:59:14 +01:00
|
|
|
|
|
|
|
const defaultUriMatch = await this.storageService.get<UriMatchType>(ConstantsService.defaultUriMatch);
|
|
|
|
this.defaultUriMatch = defaultUriMatch == null ? UriMatchType.Domain : defaultUriMatch;
|
2019-02-27 17:07:54 +01:00
|
|
|
|
|
|
|
this.clearClipboard = await this.storageService.get<number>(ConstantsService.clearClipboardKey);
|
2018-04-13 20:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async updateAddLoginNotification() {
|
|
|
|
await this.storageService.save(ConstantsService.disableAddLoginNotificationKey,
|
|
|
|
this.disableAddLoginNotification);
|
|
|
|
this.callAnalytics('Add Login Notification', !this.disableAddLoginNotification);
|
|
|
|
}
|
|
|
|
|
2018-08-01 05:48:11 +02:00
|
|
|
async updateChangedPasswordNotification() {
|
|
|
|
await this.storageService.save(ConstantsService.disableChangedPasswordNotificationKey,
|
|
|
|
this.disableChangedPasswordNotification);
|
|
|
|
this.callAnalytics('Changed Password Notification', !this.disableChangedPasswordNotification);
|
|
|
|
}
|
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
async updateDisableContextMenuItem() {
|
|
|
|
await this.storageService.save(ConstantsService.disableContextMenuItemKey,
|
|
|
|
this.disableContextMenuItem);
|
|
|
|
this.messagingService.send('bgUpdateContextMenu');
|
|
|
|
this.callAnalytics('Context Menu Item', !this.disableContextMenuItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateAutoTotpCopy() {
|
|
|
|
await this.storageService.save(ConstantsService.disableAutoTotpCopyKey, this.disableAutoTotpCopy);
|
|
|
|
this.callAnalytics('Auto Copy TOTP', !this.disableAutoTotpCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateAutoFillOnPageLoad() {
|
|
|
|
await this.storageService.save(ConstantsService.enableAutoFillOnPageLoadKey, this.enableAutoFillOnPageLoad);
|
|
|
|
this.callAnalytics('Auto-fill Page Load', this.enableAutoFillOnPageLoad);
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateDisableFavicon() {
|
|
|
|
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicon);
|
|
|
|
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableFavicon);
|
|
|
|
this.callAnalytics('Favicon', !this.disableFavicon);
|
|
|
|
}
|
|
|
|
|
2018-11-21 20:31:34 +01:00
|
|
|
async updateShowCards() {
|
|
|
|
await this.storageService.save(ConstantsService.dontShowCardsCurrentTab, this.dontShowCards);
|
|
|
|
await this.stateService.save(ConstantsService.dontShowCardsCurrentTab, this.dontShowCards);
|
|
|
|
this.callAnalytics('Show Cards on Current Tab', !this.dontShowCards);
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateShowIdentities() {
|
|
|
|
await this.storageService.save(ConstantsService.dontShowIdentitiesCurrentTab, this.dontShowIdentities);
|
|
|
|
await this.stateService.save(ConstantsService.dontShowIdentitiesCurrentTab, this.dontShowIdentities);
|
|
|
|
this.callAnalytics('Show Identities on Current Tab', !this.dontShowIdentities);
|
|
|
|
}
|
|
|
|
|
2018-05-30 23:26:43 +02:00
|
|
|
async saveTheme() {
|
|
|
|
await this.storageService.save(ConstantsService.themeKey, this.theme);
|
|
|
|
this.analytics.eventTrack.next({ action: 'Set Theme ' + this.theme });
|
2018-05-31 05:11:05 +02:00
|
|
|
window.setTimeout(() => window.location.reload(), 200);
|
2018-05-30 23:26:43 +02:00
|
|
|
}
|
|
|
|
|
2019-01-09 17:59:14 +01:00
|
|
|
async saveDefaultUriMatch() {
|
|
|
|
await this.storageService.save(ConstantsService.defaultUriMatch, this.defaultUriMatch);
|
|
|
|
this.analytics.eventTrack.next({ action: 'Set Default URI Match ' + this.defaultUriMatch });
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:07:54 +01:00
|
|
|
async saveClearClipboard() {
|
2019-03-07 02:28:49 +01:00
|
|
|
await this.storageService.save(ConstantsService.clearClipboardKey, this.clearClipboard);
|
|
|
|
this.analytics.eventTrack.next({
|
|
|
|
action: 'Set Clear Clipboard ' + (this.clearClipboard == null ? 'Disabled' : this.clearClipboard),
|
|
|
|
});
|
2019-02-27 17:07:54 +01:00
|
|
|
}
|
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
private callAnalytics(name: string, enabled: boolean) {
|
|
|
|
const status = enabled ? 'Enabled' : 'Disabled';
|
|
|
|
this.analytics.eventTrack.next({ action: `${status} ${name}` });
|
|
|
|
}
|
|
|
|
}
|