2021-05-28 10:08:21 +01:00
|
|
|
import { StorageType } from "./storage/StorageType";
|
2022-01-11 12:45:35 +00:00
|
|
|
import { default_theme } from "../ThemeLoader";
|
2021-05-28 10:08:21 +01:00
|
|
|
|
2022-01-11 10:57:30 +00:00
|
|
|
type OnChangeListener = (key: string) => void;
|
|
|
|
|
2022-01-07 14:26:21 +00:00
|
|
|
export class Settings {
|
2021-04-15 13:01:58 +01:00
|
|
|
constructor() {
|
2022-01-07 14:11:14 +00:00
|
|
|
this.storage = localStorage;
|
2022-01-11 10:57:30 +00:00
|
|
|
this.listeners = [];
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
2021-05-28 10:08:21 +01:00
|
|
|
private storage: StorageType;
|
2022-01-11 10:57:30 +00:00
|
|
|
private listeners: OnChangeListener[];
|
|
|
|
|
|
|
|
registerListener(listener: OnChangeListener) {
|
|
|
|
this.listeners.push(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
alertChange(key: string) {
|
2022-01-11 12:45:35 +00:00
|
|
|
for (const listener of this.listeners) {
|
2022-01-11 10:57:30 +00:00
|
|
|
listener(key);
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 10:08:21 +01:00
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get apiURL(): string | null {
|
2021-05-28 10:08:21 +01:00
|
|
|
const apiurl = this.storage.getItem("apiURL") || "";
|
2022-01-16 19:56:47 +00:00
|
|
|
return apiurl;
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set apiURL(value: string) {
|
2021-05-28 10:08:21 +01:00
|
|
|
this.storage.setItem("apiURL", value);
|
2022-01-11 10:57:30 +00:00
|
|
|
this.alertChange("apiURL");
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
|
|
|
|
get token(): string | null {
|
2021-05-28 10:08:21 +01:00
|
|
|
const tok = this.storage.getItem("token") || "";
|
2021-05-07 11:07:03 +01:00
|
|
|
return tok.length > 0 ? tok : null;
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set token(value: string) {
|
2021-05-28 10:08:21 +01:00
|
|
|
this.storage.setItem("token", value);
|
2022-01-11 10:57:30 +00:00
|
|
|
this.alertChange("token");
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get pageDirection(): string {
|
2021-05-28 10:08:21 +01:00
|
|
|
return this.storage.getItem("pageDirection") || "ltr";
|
2021-05-07 20:41:40 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set pageDirection(value: string) {
|
2021-05-28 10:08:21 +01:00
|
|
|
this.storage.setItem("pageDirection", value);
|
2022-01-11 10:57:30 +00:00
|
|
|
this.alertChange("pageDirection");
|
2021-05-07 20:41:40 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get language(): string {
|
2021-05-28 10:08:21 +01:00
|
|
|
return this.storage.getItem("language") || "";
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set language(value: string) {
|
2021-05-28 10:08:21 +01:00
|
|
|
this.storage.setItem("language", value);
|
2022-01-11 10:57:30 +00:00
|
|
|
this.alertChange("language");
|
|
|
|
}
|
|
|
|
|
|
|
|
get theme(): string {
|
|
|
|
return this.storage.getItem("theme") || default_theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
set theme(value: string) {
|
|
|
|
this.storage.setItem("theme", value);
|
|
|
|
this.alertChange("theme");
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2022-01-19 13:54:13 +00:00
|
|
|
|
|
|
|
get kvEditorDefaultLanguage(): string {
|
|
|
|
return this.storage.getItem("kvEditorDefaultLanguage") || "yaml";
|
|
|
|
}
|
|
|
|
|
|
|
|
set kvEditorDefaultLanguage(value: string) {
|
|
|
|
this.storage.setItem("kvEditorDefaultLanguage", value);
|
|
|
|
this.alertChange("kvEditorDefaultLanguage");
|
|
|
|
}
|
|
|
|
|
|
|
|
get kvEditorIndent(): number {
|
|
|
|
const value = this.storage.getItem("kvEditorIndent");
|
|
|
|
if (value) return parseInt(value);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
set kvEditorIndent(value: number) {
|
|
|
|
this.storage.setItem("kvEditorIndent", String(value));
|
|
|
|
this.alertChange("kvEditorIndent");
|
|
|
|
}
|
2021-05-12 16:01:04 +01:00
|
|
|
}
|