bitwarden-estensione-browser/src/popup/settings/options.component.ts

115 lines
4.6 KiB
TypeScript
Raw Normal View History

2018-04-13 20:19:33 +02:00
import {
Component,
OnInit,
} from '@angular/core';
import { Angulartics2 } from 'angulartics2';
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;
showDisableContextMenu = true;
disableGa = false;
2018-05-30 23:26:43 +02:00
theme: string;
themeOptions: 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,
private i18nService: I18nService) {
this.themeOptions = [
{ name: i18nService.t('default'), value: null },
{ name: i18nService.t('light'), value: 'light' },
{ name: i18nService.t('dark'), value: 'dark' },
];
}
2018-04-13 20:19:33 +02:00
async ngOnInit() {
this.showDisableContextMenu = !this.platformUtilsService.isSafari();
this.enableAutoFillOnPageLoad = await this.storageService.get<boolean>(
ConstantsService.enableAutoFillOnPageLoadKey);
const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey);
const disableGaByDefault = this.platformUtilsService.isFirefox();
this.disableGa = disableGa || (disableGa == null && disableGaByDefault);
this.disableAddLoginNotification = await this.storageService.get<boolean>(
ConstantsService.disableAddLoginNotificationKey);
this.disableContextMenuItem = await this.storageService.get<boolean>(
ConstantsService.disableContextMenuItemKey);
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);
2018-04-13 20:19:33 +02:00
}
async saveGa() {
if (this.disableGa) {
this.callAnalytics('Analytics', !this.disableGa);
}
await this.storageService.save(ConstantsService.disableGaKey, this.disableGa);
if (!this.disableGa) {
this.callAnalytics('Analytics', !this.disableGa);
}
}
async updateAddLoginNotification() {
await this.storageService.save(ConstantsService.disableAddLoginNotificationKey,
this.disableAddLoginNotification);
this.callAnalytics('Add Login Notification', !this.disableAddLoginNotification);
}
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-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-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}` });
}
}