2018-04-13 20:19:33 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
|
2021-10-07 01:52:33 +02:00
|
|
|
import { ThemeType } from "jslib-common/enums/themeType";
|
2021-06-07 19:25:37 +02:00
|
|
|
import { UriMatchType } from "jslib-common/enums/uriMatchType";
|
2019-01-09 17:59:14 +01:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
|
|
|
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
|
|
|
import { StorageService } from "jslib-common/abstractions/storage.service";
|
|
|
|
import { TotpService } from "jslib-common/abstractions/totp.service";
|
2018-04-13 20:19:33 +02:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { ConstantsService } from "jslib-common/services/constants.service";
|
2018-04-13 20:19:33 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-options",
|
|
|
|
templateUrl: "options.component.html",
|
|
|
|
})
|
|
|
|
export class OptionsComponent implements OnInit {
|
|
|
|
disableFavicon = false;
|
2021-02-21 23:35:14 +01:00
|
|
|
disableBadgeCounter = false;
|
2018-04-13 20:19:33 +02:00
|
|
|
enableAutoFillOnPageLoad = false;
|
2021-04-07 02:45:12 +02:00
|
|
|
autoFillOnPageLoadDefault = false;
|
|
|
|
autoFillOnPageLoadOptions: any[];
|
2018-04-13 20:19:33 +02:00
|
|
|
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;
|
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[];
|
2021-05-05 05:57:50 +02:00
|
|
|
showGeneral: boolean = true;
|
|
|
|
showAutofill: boolean = true;
|
|
|
|
showDisplay: boolean = true;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-04-14 23:43:09 +02:00
|
|
|
constructor(
|
|
|
|
private messagingService: MessagingService,
|
|
|
|
private storageService: StorageService,
|
|
|
|
private stateService: StateService,
|
|
|
|
private totpService: TotpService,
|
|
|
|
i18nService: I18nService
|
|
|
|
) {
|
2018-05-30 23:26:43 +02:00
|
|
|
this.themeOptions = [
|
|
|
|
{ name: i18nService.t("default"), value: null },
|
2021-10-04 22:30:31 +02:00
|
|
|
{ name: i18nService.t("light"), value: ThemeType.Light },
|
|
|
|
{ name: i18nService.t("dark"), value: ThemeType.Dark },
|
|
|
|
{ name: "Nord", value: ThemeType.Nord },
|
|
|
|
{ name: i18nService.t("solarizedDark"), value: ThemeType.SolarizedDark },
|
2018-05-30 23:26:43 +02:00
|
|
|
];
|
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 },
|
|
|
|
];
|
2021-04-07 02:45:12 +02:00
|
|
|
this.autoFillOnPageLoadOptions = [
|
2021-04-16 05:46:56 +02:00
|
|
|
{ name: i18nService.t("autoFillOnPageLoadYes"), value: true },
|
|
|
|
{ name: i18nService.t("autoFillOnPageLoadNo"), value: false },
|
2021-06-07 19:25:37 +02:00
|
|
|
];
|
2018-05-30 23:26:43 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
this.enableAutoFillOnPageLoad = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.enableAutoFillOnPageLoadKey
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-04-16 05:46:56 +02:00
|
|
|
this.autoFillOnPageLoadDefault =
|
|
|
|
(await this.storageService.get<boolean>(ConstantsService.autoFillOnPageLoadDefaultKey)) ??
|
2021-05-21 01:11:04 +02:00
|
|
|
true;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
this.disableAddLoginNotification = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableAddLoginNotificationKey
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-08-01 05:48:11 +02:00
|
|
|
this.disableChangedPasswordNotification = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableChangedPasswordNotificationKey
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
this.disableContextMenuItem = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableContextMenuItemKey
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
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
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2019-05-30 15:37:09 +02:00
|
|
|
this.disableAutoTotpCopy = !(await this.totpService.isAutoCopyEnabled());
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
this.disableFavicon = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableFaviconKey
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-02-21 23:35:14 +01:00
|
|
|
this.disableBadgeCounter = await this.storageService.get<boolean>(
|
|
|
|
ConstantsService.disableBadgeCounterKey
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-05-30 23:26:43 +02:00
|
|
|
this.theme = await this.storageService.get<string>(ConstantsService.themeKey);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2019-01-09 17:59:14 +01:00
|
|
|
const defaultUriMatch = await this.storageService.get<UriMatchType>(
|
|
|
|
ConstantsService.defaultUriMatch
|
|
|
|
);
|
|
|
|
this.defaultUriMatch = defaultUriMatch == null ? UriMatchType.Domain : defaultUriMatch;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
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
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
async updateAddLoginNotification() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.disableAddLoginNotificationKey,
|
|
|
|
this.disableAddLoginNotification
|
|
|
|
);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-08-01 05:48:11 +02:00
|
|
|
async updateChangedPasswordNotification() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.disableChangedPasswordNotificationKey,
|
|
|
|
this.disableChangedPasswordNotification
|
|
|
|
);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
async updateDisableContextMenuItem() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.disableContextMenuItemKey,
|
|
|
|
this.disableContextMenuItem
|
|
|
|
);
|
|
|
|
this.messagingService.send("bgUpdateContextMenu");
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
async updateAutoTotpCopy() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.disableAutoTotpCopyKey,
|
|
|
|
this.disableAutoTotpCopy
|
|
|
|
);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
async updateAutoFillOnPageLoad() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.enableAutoFillOnPageLoadKey,
|
|
|
|
this.enableAutoFillOnPageLoad
|
|
|
|
);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-04-16 05:46:56 +02:00
|
|
|
async updateAutoFillOnPageLoadDefault() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.autoFillOnPageLoadDefaultKey,
|
|
|
|
this.autoFillOnPageLoadDefault
|
|
|
|
);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-13 20:19:33 +02:00
|
|
|
async updateDisableFavicon() {
|
|
|
|
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicon);
|
|
|
|
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableFavicon);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-02-21 23:35:14 +01:00
|
|
|
async updateDisableBadgeCounter() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.disableBadgeCounterKey,
|
|
|
|
this.disableBadgeCounter
|
|
|
|
);
|
|
|
|
await this.stateService.save(ConstantsService.disableBadgeCounterKey, this.disableBadgeCounter);
|
2021-03-06 17:18:11 +01:00
|
|
|
this.messagingService.send("bgUpdateContextMenu");
|
2018-04-13 20:19:33 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
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);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-11-21 20:31:34 +01:00
|
|
|
async updateShowIdentities() {
|
|
|
|
await this.storageService.save(
|
|
|
|
ConstantsService.dontShowIdentitiesCurrentTab,
|
|
|
|
this.dontShowIdentities
|
|
|
|
);
|
|
|
|
await this.stateService.save(
|
|
|
|
ConstantsService.dontShowIdentitiesCurrentTab,
|
|
|
|
this.dontShowIdentities
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2018-11-21 20:31:34 +01:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-05-30 23:26:43 +02:00
|
|
|
async saveTheme() {
|
|
|
|
await this.storageService.save(ConstantsService.themeKey, this.theme);
|
2018-05-31 05:11:05 +02:00
|
|
|
window.setTimeout(() => window.location.reload(), 200);
|
2018-05-30 23:26:43 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2019-01-09 17:59:14 +01:00
|
|
|
async saveDefaultUriMatch() {
|
|
|
|
await this.storageService.save(ConstantsService.defaultUriMatch, this.defaultUriMatch);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
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);
|
2018-04-13 20:19:33 +02:00
|
|
|
}
|
|
|
|
}
|