2018-02-10 05:41:29 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
2018-05-08 15:40:33 +02:00
|
|
|
import { DeviceType } from 'jslib/enums/deviceType';
|
|
|
|
|
2018-02-10 05:41:29 +01:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2018-02-11 05:24:22 +01:00
|
|
|
import { LockService } from 'jslib/abstractions/lock.service';
|
2018-02-12 21:06:39 +01:00
|
|
|
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
2018-02-10 05:41:29 +01:00
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2018-02-12 21:06:39 +01:00
|
|
|
import { StateService } from 'jslib/abstractions/state.service';
|
2018-02-11 05:24:22 +01:00
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
|
|
|
|
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
2018-05-04 19:16:12 +02:00
|
|
|
|
2018-05-05 06:29:02 +02:00
|
|
|
import { ElectronConstants } from 'jslib/electron/electronConstants';
|
2018-02-10 05:41:29 +01:00
|
|
|
|
2018-07-24 04:45:58 +02:00
|
|
|
import { Utils } from 'jslib/misc/utils';
|
|
|
|
|
2018-02-10 05:41:29 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-settings',
|
2018-04-06 18:25:22 +02:00
|
|
|
templateUrl: 'settings.component.html',
|
2018-02-10 05:41:29 +01:00
|
|
|
})
|
|
|
|
export class SettingsComponent implements OnInit {
|
2018-02-11 05:24:22 +01:00
|
|
|
lockOption: number = null;
|
|
|
|
disableGa: boolean = false;
|
|
|
|
disableFavicons: boolean = false;
|
2018-05-04 19:16:12 +02:00
|
|
|
enableMinToTray: boolean = false;
|
2018-05-05 06:29:02 +02:00
|
|
|
enableTray: boolean = false;
|
2018-05-08 15:40:33 +02:00
|
|
|
showMinToTray: boolean = false;
|
2018-04-25 05:25:31 +02:00
|
|
|
locale: string;
|
2018-04-25 05:53:20 +02:00
|
|
|
lockOptions: any[];
|
|
|
|
localeOptions: any[];
|
2018-05-30 05:28:58 +02:00
|
|
|
theme: string;
|
|
|
|
themeOptions: any[];
|
2018-02-10 05:41:29 +01:00
|
|
|
|
2018-02-11 05:24:22 +01:00
|
|
|
constructor(private analytics: Angulartics2, private toasterService: ToasterService,
|
2018-10-03 15:42:11 +02:00
|
|
|
i18nService: I18nService, private platformUtilsService: PlatformUtilsService,
|
2018-02-12 21:06:39 +01:00
|
|
|
private storageService: StorageService, private lockService: LockService,
|
|
|
|
private stateService: StateService, private messagingService: MessagingService) {
|
2018-02-11 05:24:22 +01:00
|
|
|
this.lockOptions = [
|
|
|
|
// { name: i18nService.t('immediately'), value: 0 },
|
|
|
|
{ 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 },
|
2018-02-11 06:09:47 +01:00
|
|
|
{ name: i18nService.t('onIdle'), value: -4 },
|
2018-02-11 05:24:22 +01:00
|
|
|
{ name: i18nService.t('onSleep'), value: -3 },
|
|
|
|
// { name: i18nService.t('onLocked'), value: -2 },
|
|
|
|
{ name: i18nService.t('onRestart'), value: -1 },
|
|
|
|
{ name: i18nService.t('never'), value: null },
|
|
|
|
];
|
2018-04-25 05:25:31 +02:00
|
|
|
|
2018-07-24 04:45:58 +02:00
|
|
|
const localeOptions: any[] = [];
|
2018-04-25 14:31:48 +02:00
|
|
|
i18nService.supportedTranslationLocales.forEach((locale) => {
|
2018-07-24 04:45:58 +02:00
|
|
|
localeOptions.push({ name: locale, value: locale });
|
2018-04-25 05:25:31 +02:00
|
|
|
});
|
2018-07-24 04:45:58 +02:00
|
|
|
localeOptions.sort(Utils.getSortFunction(i18nService, 'name'));
|
|
|
|
localeOptions.splice(0, 0, { name: i18nService.t('default'), value: null });
|
|
|
|
this.localeOptions = localeOptions;
|
2018-05-30 05:28:58 +02:00
|
|
|
|
|
|
|
this.themeOptions = [
|
|
|
|
{ name: i18nService.t('default'), value: null },
|
|
|
|
{ name: i18nService.t('light'), value: 'light' },
|
|
|
|
{ name: i18nService.t('dark'), value: 'dark' },
|
2018-07-22 04:02:10 +02:00
|
|
|
{ name: 'Nord', value: 'nord' },
|
2018-05-30 05:28:58 +02:00
|
|
|
];
|
2018-02-10 05:41:29 +01:00
|
|
|
}
|
|
|
|
|
2018-02-11 05:24:22 +01:00
|
|
|
async ngOnInit() {
|
2018-07-09 15:06:45 +02:00
|
|
|
this.showMinToTray = this.platformUtilsService.getDevice() === DeviceType.WindowsDesktop;
|
2018-02-11 05:24:22 +01:00
|
|
|
this.lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
|
|
|
this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
|
2018-05-05 06:29:02 +02:00
|
|
|
this.enableMinToTray = await this.storageService.get<boolean>(ElectronConstants.enableMinimizeToTrayKey);
|
|
|
|
this.enableTray = await this.storageService.get<boolean>(ElectronConstants.enableTrayKey);
|
2018-04-25 05:53:20 +02:00
|
|
|
this.locale = await this.storageService.get<string>(ConstantsService.localeKey);
|
2018-05-30 05:28:58 +02:00
|
|
|
this.theme = await this.storageService.get<string>(ConstantsService.themeKey);
|
2018-02-27 06:00:31 +01:00
|
|
|
|
|
|
|
const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey);
|
2018-08-15 15:33:47 +02:00
|
|
|
const disableGaByDefault = this.platformUtilsService.isMacAppStore();
|
2018-02-27 06:00:31 +01:00
|
|
|
this.disableGa = disableGa || (disableGa == null && disableGaByDefault);
|
2018-02-11 05:24:22 +01:00
|
|
|
}
|
2018-02-10 05:41:29 +01:00
|
|
|
|
2018-02-12 21:06:39 +01:00
|
|
|
async saveLockOption() {
|
2018-02-11 05:24:22 +01:00
|
|
|
await this.lockService.setLockOption(this.lockOption != null ? this.lockOption : null);
|
2018-02-12 21:06:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async saveGa() {
|
|
|
|
if (this.disableGa) {
|
|
|
|
this.callAnalytics('Analytics', !this.disableGa);
|
|
|
|
}
|
2018-02-11 05:24:22 +01:00
|
|
|
await this.storageService.save(ConstantsService.disableGaKey, this.disableGa);
|
2018-02-12 21:06:39 +01:00
|
|
|
if (!this.disableGa) {
|
|
|
|
this.callAnalytics('Analytics', !this.disableGa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async saveFavicons() {
|
2018-02-11 05:24:22 +01:00
|
|
|
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicons);
|
2018-02-12 21:06:39 +01:00
|
|
|
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableFavicons);
|
|
|
|
this.messagingService.send('refreshCiphers');
|
2018-05-04 18:45:42 +02:00
|
|
|
this.callAnalytics('Favicons', !this.disableFavicons);
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:16:12 +02:00
|
|
|
async saveMinToTray() {
|
2018-05-05 06:29:02 +02:00
|
|
|
await this.storageService.save(ElectronConstants.enableMinimizeToTrayKey, this.enableMinToTray);
|
2018-05-04 19:16:12 +02:00
|
|
|
this.callAnalytics('MinimizeToTray', this.enableMinToTray);
|
2018-02-12 21:06:39 +01:00
|
|
|
}
|
|
|
|
|
2018-05-05 06:29:02 +02:00
|
|
|
async saveTray() {
|
|
|
|
await this.storageService.save(ElectronConstants.enableTrayKey, this.enableTray);
|
|
|
|
this.callAnalytics('Tray', this.enableTray);
|
|
|
|
this.messagingService.send(this.enableTray ? 'showTray' : 'removeTray');
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:53:20 +02:00
|
|
|
async saveLocale() {
|
|
|
|
await this.storageService.save(ConstantsService.localeKey, this.locale);
|
|
|
|
this.analytics.eventTrack.next({ action: 'Set Locale ' + this.locale });
|
|
|
|
}
|
|
|
|
|
2018-05-30 05:28:58 +02:00
|
|
|
async saveTheme() {
|
|
|
|
await this.storageService.save(ConstantsService.themeKey, this.theme);
|
|
|
|
this.analytics.eventTrack.next({ action: 'Set Theme ' + this.theme });
|
2018-05-31 04:28:04 +02:00
|
|
|
window.setTimeout(() => window.location.reload(), 200);
|
2018-05-30 05:28:58 +02:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:06:39 +01:00
|
|
|
private callAnalytics(name: string, enabled: boolean) {
|
|
|
|
const status = enabled ? 'Enabled' : 'Disabled';
|
|
|
|
this.analytics.eventTrack.next({ action: `${status} ${name}` });
|
2018-02-10 05:41:29 +01:00
|
|
|
}
|
|
|
|
}
|