From 14d2f8e956d11f917ab6670d218cb5af1a657818 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Mon, 29 Jul 2024 00:43:07 -0500 Subject: [PATCH] Add AluStore, will do more with this soon --- src/components/SettingsContent/ProxyTab.astro | 2 +- src/components/ts/AluStore.ts | 64 +++++++++++++++++++ src/layouts/Layout.astro | 1 + src/pages/[lang]/settings.astro | 1 + src/types.d.ts | 16 +++++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/components/ts/AluStore.ts diff --git a/src/components/SettingsContent/ProxyTab.astro b/src/components/SettingsContent/ProxyTab.astro index 21f4ba2..50779da 100644 --- a/src/components/SettingsContent/ProxyTab.astro +++ b/src/components/SettingsContent/ProxyTab.astro @@ -51,7 +51,7 @@ const wispURLList = [
- +
diff --git a/src/components/ts/AluStore.ts b/src/components/ts/AluStore.ts new file mode 100644 index 0000000..1664d3a --- /dev/null +++ b/src/components/ts/AluStore.ts @@ -0,0 +1,64 @@ +const KEYSTORE: AluDefaultKeys = { + proxy: { + name: "Ultraviolet", + value: "ultraviolet", + }, + search: { + name: "Google", + value: "google", + }, + openpage: { + name: "Embed", + value: "embed", + }, + wisp: { + name: "Alu (US)", + value: "alu", + }, + bareUrl: { + name: `${window.location.protocol}//${window.location.host}/bare/`, + value: `${window.location.protocol}//${window.location.host}/bare/`, + }, + theme: { + name: "Alu", + value: "alu", + }, + transport: { + name: "Epoxy", + value: "epoxy", + }, + searxng: { + name: "https://searxng.site", + value: "https://searxng.site", + }, +}; + +if (localStorage.getItem("AluStore") === null) { + localStorage.setItem("AluStore", JSON.stringify(KEYSTORE)); +} + +class AluStore { + private store: AluDefaultKeys = KEYSTORE; + constructor() { + const localstore = localStorage.getItem("AluStore"); + if (!localstore) { + localStorage.setItem("AluStore", JSON.stringify(KEYSTORE)); + } + this.store = JSON.parse(localStorage.getItem("AluStore") || "{}"); + } + public getStore(): AluDefaultKeys { + return this.store; + } + public get(key: string): AluKey { + return this.store[key]; + } + public set(key: string, value: AluKey): void { + this.store[key] = value; + this.save(); + } + private save(): void { + localStorage.setItem("AluStore", JSON.stringify(this.store)); + } +} + +window.AluStore = new AluStore(); diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 018a01c..03a1829 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -69,6 +69,7 @@ const { title, optionalPreloads } = Astro.props; }; } + {title} diff --git a/src/pages/[lang]/settings.astro b/src/pages/[lang]/settings.astro index 8f75a33..bd95b72 100644 --- a/src/pages/[lang]/settings.astro +++ b/src/pages/[lang]/settings.astro @@ -323,6 +323,7 @@ export function getStaticPaths() { applySavedLocalStorage("alu__selectedProxy", "dropdown__selected-proxy"); applySavedLocalStorage("alu__search_engine", "dropdown__search-engine"); applySavedLocalStorage("alu__selectedOpenWith", "dropdown__open-with"); + applySavedLocalStorage("alu__selectedWispURL", "dropdown__wisp-url"); applySavedLocalStorage("alu__selectedTransport", "dropdown__transport"); // Dropdowns const selectedProxyDropdown = document.getElementById("dropdown__selected-proxy"); diff --git a/src/types.d.ts b/src/types.d.ts index b4488c0..bacab17 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,4 +1,5 @@ interface Window { + AluStore: AluStore; __uv$config: { prefix: string; encodeUrl: (url: string) => string; @@ -12,6 +13,15 @@ interface Window { wispData: WispData[]; } +declare global { + interface Global { + AluStore: AluStore; + } + + // Add the property to globalThis + let AluStore: AluStore; +} + type ExtType = "serviceWorker" | "theme" | "page"; type Extension = { @@ -75,3 +85,9 @@ type WispData = { server: WispServer; time: number; }; + +type AluKey = Record; + +type AluDefaultKeys = { + [key: string]: AluKey; +};