2018-06-25 22:44:06 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
2022-07-26 14:48:11 +02:00
|
|
|
import { UntypedFormControl } from "@angular/forms";
|
2018-06-25 22:44:06 +02:00
|
|
|
|
2022-06-23 13:36:05 +02:00
|
|
|
import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-08-30 16:11:19 +02:00
|
|
|
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ThemeType } from "@bitwarden/common/enums/themeType";
|
|
|
|
import { Utils } from "@bitwarden/common/misc/utils";
|
2018-07-24 04:45:43 +02:00
|
|
|
|
2018-06-25 22:44:06 +02:00
|
|
|
@Component({
|
2022-05-09 14:21:52 +02:00
|
|
|
selector: "app-preferences",
|
|
|
|
templateUrl: "preferences.component.html",
|
2018-06-25 22:44:06 +02:00
|
|
|
})
|
2022-05-09 14:21:52 +02:00
|
|
|
export class PreferencesComponent implements OnInit {
|
2022-02-24 12:10:07 +01:00
|
|
|
vaultTimeoutAction = "lock";
|
2022-06-23 09:53:42 +02:00
|
|
|
enableFavicons: boolean;
|
2018-07-31 06:02:09 +02:00
|
|
|
enableGravatars: boolean;
|
2020-05-30 02:21:42 +02:00
|
|
|
enableFullWidth: boolean;
|
2022-01-28 17:30:45 +01:00
|
|
|
theme: ThemeType;
|
2018-06-25 22:44:06 +02:00
|
|
|
locale: string;
|
2021-09-10 15:27:00 +02:00
|
|
|
vaultTimeouts: { name: string; value: number }[];
|
2018-06-25 22:44:06 +02:00
|
|
|
localeOptions: any[];
|
2021-09-30 00:06:20 +02:00
|
|
|
themeOptions: any[];
|
2018-06-25 22:44:06 +02:00
|
|
|
|
2022-07-26 14:48:11 +02:00
|
|
|
vaultTimeout: UntypedFormControl = new UntypedFormControl(null);
|
2021-09-10 15:27:00 +02:00
|
|
|
|
2018-06-26 15:04:12 +02:00
|
|
|
private startingLocale: string;
|
2022-01-28 17:30:45 +01:00
|
|
|
private startingTheme: ThemeType;
|
2018-06-26 15:04:12 +02:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
constructor(
|
|
|
|
private stateService: StateService,
|
2021-12-07 20:41:45 +01:00
|
|
|
private i18nService: I18nService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private vaultTimeoutService: VaultTimeoutService,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
2022-06-23 13:36:05 +02:00
|
|
|
private messagingService: MessagingService,
|
|
|
|
private themingService: AbstractThemingService
|
2021-12-14 17:10:26 +01:00
|
|
|
) {
|
2020-03-30 16:59:47 +02:00
|
|
|
this.vaultTimeouts = [
|
2018-07-27 21:08:59 +02:00
|
|
|
{ name: i18nService.t("oneMinute"), value: 1 },
|
|
|
|
{ name: i18nService.t("fiveMinutes"), value: 5 },
|
|
|
|
{ name: i18nService.t("fifteenMinutes"), value: 15 },
|
|
|
|
{ name: i18nService.t("thirtyMinutes"), value: 30 },
|
2020-03-30 16:59:47 +02:00
|
|
|
{ name: i18nService.t("oneHour"), value: 60 },
|
2019-09-06 15:33:35 +02:00
|
|
|
{ name: i18nService.t("fourHours"), value: 240 },
|
|
|
|
{ name: i18nService.t("onRefresh"), value: -1 },
|
2018-07-24 04:45:43 +02:00
|
|
|
];
|
|
|
|
if (this.platformUtilsService.isDev()) {
|
|
|
|
this.vaultTimeouts.push({ name: i18nService.t("never"), value: null });
|
2018-06-25 22:44:06 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
const localeOptions: any[] = [];
|
|
|
|
i18nService.supportedTranslationLocales.forEach((locale) => {
|
|
|
|
let name = locale;
|
|
|
|
if (i18nService.localeNames.has(locale)) {
|
|
|
|
name += " - " + i18nService.localeNames.get(locale);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-12-14 17:10:26 +01:00
|
|
|
localeOptions.push({ name: name, value: locale });
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2021-12-14 17:10:26 +01:00
|
|
|
localeOptions.sort(Utils.getSortFunction(i18nService, "name"));
|
|
|
|
localeOptions.splice(0, 0, { name: i18nService.t("default"), value: null });
|
|
|
|
this.localeOptions = localeOptions;
|
|
|
|
this.themeOptions = [
|
|
|
|
{ name: i18nService.t("themeLight"), value: ThemeType.Light },
|
|
|
|
{ name: i18nService.t("themeDark"), value: ThemeType.Dark },
|
|
|
|
{ name: i18nService.t("themeSystem"), value: ThemeType.System },
|
2021-12-17 15:57:11 +01:00
|
|
|
];
|
2018-06-25 22:44:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 15:04:12 +02:00
|
|
|
async ngOnInit() {
|
2021-09-10 15:27:00 +02:00
|
|
|
this.vaultTimeout.setValue(await this.vaultTimeoutService.getVaultTimeout());
|
2021-12-07 20:41:45 +01:00
|
|
|
this.vaultTimeoutAction = await this.stateService.getVaultTimeoutAction();
|
2022-06-23 09:53:42 +02:00
|
|
|
this.enableFavicons = !(await this.stateService.getDisableFavicon());
|
2021-12-14 17:10:26 +01:00
|
|
|
this.enableGravatars = await this.stateService.getEnableGravitars();
|
2021-12-07 20:41:45 +01:00
|
|
|
this.enableFullWidth = await this.stateService.getEnableFullWidth();
|
2022-01-31 15:11:25 +01:00
|
|
|
|
2022-05-02 15:32:44 +02:00
|
|
|
this.locale = (await this.stateService.getLocale()) ?? null;
|
2022-01-31 15:11:25 +01:00
|
|
|
this.startingLocale = this.locale;
|
|
|
|
|
|
|
|
this.theme = await this.stateService.getTheme();
|
|
|
|
this.startingTheme = this.theme;
|
2021-09-10 15:27:00 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 22:44:06 +02:00
|
|
|
async submit() {
|
2021-09-10 15:27:00 +02:00
|
|
|
if (!this.vaultTimeout.valid) {
|
2022-06-08 06:41:27 +02:00
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
null,
|
|
|
|
this.i18nService.t("vaultTimeoutRangeError")
|
|
|
|
);
|
2021-12-17 15:57:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:27:00 +02:00
|
|
|
await this.vaultTimeoutService.setVaultTimeoutOptions(
|
|
|
|
this.vaultTimeout.value,
|
|
|
|
this.vaultTimeoutAction
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
2022-06-23 09:53:42 +02:00
|
|
|
await this.stateService.setDisableFavicon(!this.enableFavicons);
|
2021-12-14 17:10:26 +01:00
|
|
|
await this.stateService.setEnableGravitars(this.enableGravatars);
|
|
|
|
await this.stateService.setEnableFullWidth(this.enableFullWidth);
|
2020-05-30 10:30:35 +02:00
|
|
|
this.messagingService.send("setFullWidth");
|
2021-09-30 00:06:20 +02:00
|
|
|
if (this.theme !== this.startingTheme) {
|
2022-06-23 13:36:05 +02:00
|
|
|
await this.themingService.updateConfiguredTheme(this.theme);
|
2021-09-30 00:06:20 +02:00
|
|
|
this.startingTheme = this.theme;
|
|
|
|
}
|
2021-12-14 17:10:26 +01:00
|
|
|
await this.stateService.setLocale(this.locale);
|
2018-06-26 15:04:12 +02:00
|
|
|
if (this.locale !== this.startingLocale) {
|
|
|
|
window.location.reload();
|
|
|
|
} else {
|
2022-05-09 14:21:52 +02:00
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"success",
|
|
|
|
null,
|
|
|
|
this.i18nService.t("preferencesUpdated")
|
|
|
|
);
|
2018-06-25 22:44:06 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2020-05-18 15:51:20 +02:00
|
|
|
|
|
|
|
async vaultTimeoutActionChanged(newValue: string) {
|
|
|
|
if (newValue === "logOut") {
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t("vaultTimeoutLogOutConfirmation"),
|
|
|
|
this.i18nService.t("vaultTimeoutLogOutConfirmationTitle"),
|
|
|
|
this.i18nService.t("yes"),
|
|
|
|
this.i18nService.t("cancel"),
|
|
|
|
"warning"
|
|
|
|
);
|
|
|
|
if (!confirmed) {
|
|
|
|
this.vaultTimeoutAction = "lock";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.vaultTimeoutAction = newValue;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-25 22:44:06 +02:00
|
|
|
}
|