diff --git a/astro.config.ts b/astro.config.ts
index 41f9aa1..07ab795 100644
--- a/astro.config.ts
+++ b/astro.config.ts
@@ -1,8 +1,8 @@
-import { defineConfig } from 'astro/config';
-import type { Plugin } from 'vite';
+import { defineConfig } from "astro/config";
+import type { Plugin } from "vite";
import wisp from "wisp-server-node";
-import node from '@astrojs/node';
-import tailwindcss from '@tailwindcss/vite';
+import node from "@astrojs/node";
+import tailwindcss from "@tailwindcss/vite";
import icon from "astro-icon";
import { viteStaticCopy } from "vite-plugin-static-copy";
import playformCompress from "@playform/compress";
@@ -15,13 +15,13 @@ import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
const viteWispServer = (): Plugin => {
return {
- name: 'vite-wisp-server',
+ name: "vite-wisp-server",
configureServer(server) {
- server.httpServer?.on('upgrade', (req, socket, head) => {
- req.url.startsWith('/wisp') ? wisp.routeRequest(req, socket, head) : undefined
- })
+ server.httpServer?.on("upgrade", (req, socket, head) => {
+ req.url.startsWith("/wisp") ? wisp.routeRequest(req, socket, head) : undefined;
+ });
}
- }
+ };
};
export default defineConfig({
@@ -35,10 +35,26 @@ export default defineConfig({
viteStaticCopy({
targets: [
{ src: `${uvPath}/**/*`.replace(/\\/g, "/"), dest: "vu", overwrite: false },
- { src: `${scramjetPath}/**/*`.replace(/\\/g, "/"), dest: "marcs", overwrite: false },
- { src: `${baremuxPath}/**/*`.replace(/\\/g, "/"), dest: "erab", overwrite: false },
- { src: `${epoxyPath}/**/*`.replace(/\\/g, "/"), dest: "epoxy", overwrite: false },
- { src: `${libcurlPath}/**/*`.replace(/\\/g, "/"), dest: "libcurl", overwrite: false }
+ {
+ src: `${scramjetPath}/**/*`.replace(/\\/g, "/"),
+ dest: "marcs",
+ overwrite: false
+ },
+ {
+ src: `${baremuxPath}/**/*`.replace(/\\/g, "/"),
+ dest: "erab",
+ overwrite: false
+ },
+ {
+ src: `${epoxyPath}/**/*`.replace(/\\/g, "/"),
+ dest: "epoxy",
+ overwrite: false
+ },
+ {
+ src: `${libcurlPath}/**/*`.replace(/\\/g, "/"),
+ dest: "libcurl",
+ overwrite: false
+ }
]
})
]
@@ -53,8 +69,8 @@ export default defineConfig({
SVG: true
})
],
- output: 'server',
+ output: "server",
adapter: node({
- mode: 'middleware'
+ mode: "middleware"
})
});
diff --git a/biome.jsonc b/biome.jsonc
index ea1ffa6..81216d7 100644
--- a/biome.jsonc
+++ b/biome.jsonc
@@ -1,41 +1,40 @@
{
- "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
- "vcs": {
- "enabled": false,
- "clientKind": "git",
- "useIgnoreFile": false
- },
- "files": {
- "ignore": ["**/dist/**", ".github/**"],
+ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
+ "vcs": {
+ "enabled": false,
+ "clientKind": "git",
+ "useIgnoreFile": false
+ },
+ "files": {
+ "ignore": ["**/dist/**", ".github/**"],
"include": ["**/**", "server/**"]
- },
- "formatter": {
- "enabled": true,
- "indentStyle": "space",
- "indendWidth": 4,
+ },
+ "formatter": {
+ "enabled": true,
+ "indentStyle": "space",
+ "indentWidth": 4,
"lineWidth": 100,
"ignore": ["pnpm-lock.yaml", "package.json"]
- },
- "organizeImports": {
- "enabled": true
- },
- "linter": {
- "enabled": false
- },
- "javascript": {
- "formatter": {
- "trailingCommas": "none"
- "quoteStyle": "double",
+ },
+ "organizeImports": {
+ "enabled": true
+ },
+ "linter": {
+ "enabled": false
+ },
+ "javascript": {
+ "formatter": {
+ "trailingCommas": "none",
+ "quoteStyle": "double",
"semicolons": "always"
- }
- },
+ }
+ },
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
},
"formatter": {
- "indentSyle": "space",
"trailingCommas": "none"
}
}
diff --git a/public/sw.js b/public/sw.js
index 876f1c5..f8776b1 100644
--- a/public/sw.js
+++ b/public/sw.js
@@ -1,7 +1,7 @@
importScripts(
- "/vu/uv.bundle.js",
+ "/vu/uv.bundle.js",
"/vu/uv.config.js",
- "/marcs/scramjet.shared.js",
+ "/marcs/scramjet.shared.js",
"/marcs/scramjet.worker.js"
);
importScripts(__uv$config.sw || "/vu/uv.sw.js");
@@ -15,11 +15,9 @@ self.addEventListener("fetch", function (event) {
await sj.loadConfig();
if (event.request.url.startsWith(location.origin + __uv$config.prefix)) {
return await uv.fetch(event);
- }
- else if (sj.route(event)) {
+ } else if (sj.route(event)) {
return await sj.fetch(event);
- }
- else {
+ } else {
return await fetch(event.request);
}
})()
diff --git a/server/index.ts b/server/index.ts
index 31ed8ba..09f327e 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -1,20 +1,19 @@
-import Fastify, { FastifyReply, FastifyRequest } from 'fastify';
-import fastifyMiddie from '@fastify/middie';
-import fastifyStatic from '@fastify/static';
-import { fileURLToPath } from 'node:url';
+import Fastify, { FastifyReply, FastifyRequest } from "fastify";
+import fastifyMiddie from "@fastify/middie";
+import fastifyStatic from "@fastify/static";
+import { fileURLToPath } from "node:url";
//@ts-ignore this is created at runtime. No types associated w/it
import { handler as astroHandler } from "../dist/server/entry.mjs";
-
const app = Fastify({
logger: true,
ignoreDuplicateSlashes: true,
- ignoreTrailingSlash: true,
+ ignoreTrailingSlash: true
});
await app.register(fastifyStatic, {
- root: fileURLToPath(new URL('../dist/client', import.meta.url))
+ root: fileURLToPath(new URL("../dist/client", import.meta.url))
});
await app.register(fastifyMiddie);
diff --git a/src/assets/splash.json b/src/assets/splash.json
index 34e3bfa..16f543b 100644
--- a/src/assets/splash.json
+++ b/src/assets/splash.json
@@ -1,104 +1,104 @@
[
- {
- "splash": "Join our community! https://discord.gg/qsXnhSPtAK"
- },
- {
- "splash": "Browse safely!"
- },
- {
- "splash": "Access with ease!"
- },
- {
- "splash": "Stay secure online!"
- },
- {
- "splash": "New updates available!"
- },
- {
- "splash": "Surf anonymously!"
- },
- {
- "splash": "Unlock the web!"
- },
- {
- "splash": "Don't miss out!"
- },
- {
- "splash": "Fast and reliable!"
- },
- {
- "splash": "Enjoy your privacy!"
- },
- {
- "splash": "Let's get started!"
- },
- {
- "splash": "Protect your data!"
- },
- {
- "splash": "Freedom online!"
- },
- {
- "splash": "Navigate freely!"
- },
- {
- "splash": "Your web, your rules!"
- },
- {
- "splash": "Stay anonymous!"
- },
- {
- "splash": "Access anything!"
- },
- {
- "splash": "Fast and secure!"
- },
- {
- "splash": "Browse without limits!"
- },
- {
- "splash": "Private and secure!"
- },
- {
- "splash": "Keep your data safe!"
- },
- {
- "splash": "Connect globally!"
- },
- {
- "splash": "No boundaries!"
- },
- {
- "splash": "Web freedom!"
- },
- {
- "splash": "Stay private!"
- },
- {
- "splash": "Anonymous browsing!"
- },
- {
- "splash": "Secure access!"
- },
- {
- "splash": "Fast connections!"
- },
- {
- "splash": "Unrestricted access!"
- },
- {
- "splash": "Surf the web freely!"
- },
- {
- "splash": "Your privacy matters!"
- },
- {
- "splash": "Always connected!"
- },
- {
- "splash": "Web without limits!"
- },
- {
- "splash": "Explore the internet!"
- }
+ {
+ "splash": "Join our community! https://discord.gg/qsXnhSPtAK"
+ },
+ {
+ "splash": "Browse safely!"
+ },
+ {
+ "splash": "Access with ease!"
+ },
+ {
+ "splash": "Stay secure online!"
+ },
+ {
+ "splash": "New updates available!"
+ },
+ {
+ "splash": "Surf anonymously!"
+ },
+ {
+ "splash": "Unlock the web!"
+ },
+ {
+ "splash": "Don't miss out!"
+ },
+ {
+ "splash": "Fast and reliable!"
+ },
+ {
+ "splash": "Enjoy your privacy!"
+ },
+ {
+ "splash": "Let's get started!"
+ },
+ {
+ "splash": "Protect your data!"
+ },
+ {
+ "splash": "Freedom online!"
+ },
+ {
+ "splash": "Navigate freely!"
+ },
+ {
+ "splash": "Your web, your rules!"
+ },
+ {
+ "splash": "Stay anonymous!"
+ },
+ {
+ "splash": "Access anything!"
+ },
+ {
+ "splash": "Fast and secure!"
+ },
+ {
+ "splash": "Browse without limits!"
+ },
+ {
+ "splash": "Private and secure!"
+ },
+ {
+ "splash": "Keep your data safe!"
+ },
+ {
+ "splash": "Connect globally!"
+ },
+ {
+ "splash": "No boundaries!"
+ },
+ {
+ "splash": "Web freedom!"
+ },
+ {
+ "splash": "Stay private!"
+ },
+ {
+ "splash": "Anonymous browsing!"
+ },
+ {
+ "splash": "Secure access!"
+ },
+ {
+ "splash": "Fast connections!"
+ },
+ {
+ "splash": "Unrestricted access!"
+ },
+ {
+ "splash": "Surf the web freely!"
+ },
+ {
+ "splash": "Your privacy matters!"
+ },
+ {
+ "splash": "Always connected!"
+ },
+ {
+ "splash": "Web without limits!"
+ },
+ {
+ "splash": "Explore the internet!"
+ }
]
diff --git a/src/components/SettingsNav.astro b/src/components/SettingsNav.astro
index 6150295..8a7577a 100644
--- a/src/components/SettingsNav.astro
+++ b/src/components/SettingsNav.astro
@@ -2,7 +2,7 @@
import { Icon } from "astro-icon/components";
import type { SettingsProps as Props } from "@utils/types.ts";
-const { active } = Astro.props;
+const { active } = Astro.props;
---
diff --git a/src/components/ui/Button.astro b/src/components/ui/Button.astro
index 4d00732..f24e768 100644
--- a/src/components/ui/Button.astro
+++ b/src/components/ui/Button.astro
@@ -1,10 +1,10 @@
---
-import { Icon } from 'astro-icon/components';
+import { Icon } from "astro-icon/components";
interface Props {
id: string;
text: string;
- icon?: string
+ icon?: string;
}
const { id, text, icon } = Astro.props;
---
diff --git a/src/components/ui/Card.astro b/src/components/ui/Card.astro
index e5921f9..7718cdb 100644
--- a/src/components/ui/Card.astro
+++ b/src/components/ui/Card.astro
@@ -10,7 +10,7 @@ interface Props {
imageSrc: string;
text: string;
id: string;
-};
+}
const { imageSrc, text, id, link } = Astro.props;
---
diff --git a/src/global.d.ts b/src/global.d.ts
index 9ee000b..65d2aa3 100644
--- a/src/global.d.ts
+++ b/src/global.d.ts
@@ -1,7 +1,7 @@
declare global {
interface Window {
- __uv: any;
- $scramjet: any;
+ __uv: any;
+ $scramjet: any;
}
}
export {};
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro
index 0d9c720..ab01cf0 100644
--- a/src/layouts/Layout.astro
+++ b/src/layouts/Layout.astro
@@ -8,11 +8,15 @@ import Header from "@components/Header.astro";
import "@styles/global.css";
import "@styles/default.css";
-readdir(pathJoin(import.meta.dirname, '..', 'styles', 'themes'), { encoding: 'utf-8' }, (err, files) => {
- files.forEach(async (name) => {
- await import(`../styles/themes/${name.replace('.css', '')}.css`)
- });
-});
+readdir(
+ pathJoin(import.meta.dirname, "..", "styles", "themes"),
+ { encoding: "utf-8" },
+ (err, files) => {
+ files.forEach(async (name) => {
+ await import(`../styles/themes/${name.replace(".css", "")}.css`);
+ });
+ }
+);
---
diff --git a/src/pages/[...settings]/appearance.astro b/src/pages/[...settings]/appearance.astro
index 993aeec..cb0422a 100644
--- a/src/pages/[...settings]/appearance.astro
+++ b/src/pages/[...settings]/appearance.astro
@@ -8,12 +8,14 @@ import Input from "@components/ui/Input.astro";
import Button from "@components/ui/Button.astro";
import { type DropdownOptions } from "@utils/types";
-const Themes: DropdownOptions[] = [{ name: 'Default', value: 'default' }];
-const files = await readdir(pathJoin(import.meta.dirname, '..', '..', 'styles', 'themes'), { encoding: 'utf-8' });
+const Themes: DropdownOptions[] = [{ name: "Default", value: "default" }];
+const files = await readdir(pathJoin(import.meta.dirname, "..", "..", "styles", "themes"), {
+ encoding: "utf-8"
+});
files.forEach((name) => {
- Themes.push({
- name: name.toLowerCase().charAt(0).toUpperCase() + name.slice(1).replace('.css', ''),
- value: name.toLowerCase().replace('.css', '')
+ Themes.push({
+ name: name.toLowerCase().charAt(0).toUpperCase() + name.slice(1).replace(".css", ""),
+ value: name.toLowerCase().replace(".css", "")
});
});
---
diff --git a/src/pages/[...settings]/index.astro b/src/pages/[...settings]/index.astro
index d0f560b..f0a4080 100644
--- a/src/pages/[...settings]/index.astro
+++ b/src/pages/[...settings]/index.astro
@@ -5,9 +5,9 @@ import Input from "@components/ui/Input.astro";
import Button from "@components/ui/Button.astro";
import { SearchEngines, type DropdownOptions } from "@utils/types";
const SearchEngineOptions: DropdownOptions[] = [];
-Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
- { name: k, value: SearchEngines[k] }
-));
+Object.keys(SearchEngines).forEach((k) =>
+ SearchEngineOptions.push({ name: k, value: SearchEngines[k] })
+);
---
diff --git a/src/pages/index.astro b/src/pages/index.astro
index da1b491..5351b9d 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -1,17 +1,17 @@
---
-import Layout from '@layouts/Layout.astro';
-import { Icon } from 'astro-icon/components'
+import Layout from "@layouts/Layout.astro";
+import { Icon } from "astro-icon/components";
import splash from "@assets/splash.json";
const genSplash = (): String => {
const idx = Math.floor(Math.random() * splash.length);
return splash[idx].splash;
-}
+};
const randomSplash = genSplash();
-const link = Astro.url.searchParams.get('redir');
+const link = Astro.url.searchParams.get("redir");
---
diff --git a/src/styles/global.css b/src/styles/global.css
index 35e6ca4..fd75e1a 100644
--- a/src/styles/global.css
+++ b/src/styles/global.css
@@ -1,7 +1,7 @@
-@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');
+@import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");
@import "tailwindcss";
@theme {
- --font-inter: "Inter", sans-serif
+ --font-inter: "Inter", sans-serif;
}
diff --git a/src/styles/themes/bluelight.css b/src/styles/themes/bluelight.css
index 21277b8..d10c1d9 100644
--- a/src/styles/themes/bluelight.css
+++ b/src/styles/themes/bluelight.css
@@ -18,4 +18,4 @@
--destructive: hsl(2 82% 30%);
--destructive-foreground: hsl(2 82% 90%);
--ring: hsl(223 42% 57%);
- }
+}
diff --git a/src/styles/themes/cyberpunk.css b/src/styles/themes/cyberpunk.css
index 3551371..30a6241 100644
--- a/src/styles/themes/cyberpunk.css
+++ b/src/styles/themes/cyberpunk.css
@@ -18,4 +18,4 @@
--destructive: hsl(5 92% 45%);
--destructive-foreground: hsl(0 0% 100%);
--ring: hsl(167 100% 50%);
- }
+}
diff --git a/src/utils/proxy.ts b/src/utils/proxy.ts
index 6e04ac7..166e05c 100644
--- a/src/utils/proxy.ts
+++ b/src/utils/proxy.ts
@@ -2,35 +2,35 @@ import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
import { StoreManager } from "./storage";
const createScript = (src: string, defer?: boolean) => {
- const script = document.createElement('script') as HTMLScriptElement;
+ const script = document.createElement("script") as HTMLScriptElement;
script.src = src;
if (defer) script.defer = defer;
return document.body.appendChild(script);
-}
+};
/**
- * This class automatically sets up and handles lots of stuff for us.
- *
- * It registers/fixes errors with SW reg
- * It creates our bareMux worker
- * And other stuff.
- *
- * @example
- * import { SW } from "@utils/proxy.ts";
- * const handler = new SW();
- * //Consume the methods
- * // Or if an instance is already running
- * import { SW } from "@utils/proxy.ts";
- * const handler = SW.getInstance();
- * //Consume the methods
-*/
+ * This class automatically sets up and handles lots of stuff for us.
+ *
+ * It registers/fixes errors with SW reg
+ * It creates our bareMux worker
+ * And other stuff.
+ *
+ * @example
+ * import { SW } from "@utils/proxy.ts";
+ * const handler = new SW();
+ * //Consume the methods
+ * // Or if an instance is already running
+ * import { SW } from "@utils/proxy.ts";
+ * const handler = SW.getInstance();
+ * //Consume the methods
+ */
class SW {
#baremuxConn?: BareMuxConnection;
#scramjetController?: ScramjetController;
#serviceWorker?: ServiceWorkerRegistration;
#storageManager: StoreManager<"radius||settings">;
- static #instance = new Set();
-
+ static #instance = new Set();
+
static *getInstance() {
for (const val of SW.#instance.keys()) {
yield val as SW;
@@ -38,41 +38,59 @@ class SW {
}
#search(input: string, template: string) {
- try { return new URL(input).toString() } catch (_) {};
+ try {
+ return new URL(input).toString();
+ } catch (_) {}
try {
const url = new URL(`http://${input}`);
if (url.hostname.includes(".")) return url.toString();
- } catch (_) {};
+ } catch (_) {}
return template.replace("%s", encodeURIComponent(input));
}
encodeURL(string: string): string {
- const proxy = this.#storageManager.getVal("proxy") as 'uv' | 'sj';
- const input = this.#search(string, this.#storageManager.getVal('searchEngine'));
- return proxy === 'uv' ? `${__uv$config.prefix}${__uv$config.encodeUrl!(input)}` : this.#scramjetController!.encodeUrl(input)
+ const proxy = this.#storageManager.getVal("proxy") as "uv" | "sj";
+ const input = this.#search(string, this.#storageManager.getVal("searchEngine"));
+ return proxy === "uv"
+ ? `${__uv$config.prefix}${__uv$config.encodeUrl!(input)}`
+ : this.#scramjetController!.encodeUrl(input);
}
- async setTransport(transport?: 'epoxy' | 'libcurl', get?: boolean) {
- console.log('Setting transport');
- if (get) return this.#storageManager.getVal('transport');
- this.#storageManager.setVal("transport", transport || this.#storageManager.getVal("transport") || 'epoxy');
- switch(transport) {
- case 'epoxy': {
- await this.#baremuxConn!.setTransport("/epoxy/index.mjs", [ { wisp: this.#storageManager.getVal('wispServer') }]);
+ async setTransport(transport?: "epoxy" | "libcurl", get?: boolean) {
+ console.log("Setting transport");
+ if (get) return this.#storageManager.getVal("transport");
+ this.#storageManager.setVal(
+ "transport",
+ transport || this.#storageManager.getVal("transport") || "epoxy"
+ );
+ switch (transport) {
+ case "epoxy": {
+ await this.#baremuxConn!.setTransport("/epoxy/index.mjs", [
+ { wisp: this.#storageManager.getVal("wispServer") }
+ ]);
}
- case 'libcurl': {
- await this.#baremuxConn!.setTransport("/libcurl/index.mjs", [ { wisp: this.#storageManager.getVal('wispServer') }]);
+ case "libcurl": {
+ await this.#baremuxConn!.setTransport("/libcurl/index.mjs", [
+ { wisp: this.#storageManager.getVal("wispServer") }
+ ]);
}
default: {
- await this.#baremuxConn!.setTransport("/epoxy/index.mjs", [ { wisp: this.#storageManager.getVal('wispServer') }]);
+ await this.#baremuxConn!.setTransport("/epoxy/index.mjs", [
+ { wisp: this.#storageManager.getVal("wispServer") }
+ ]);
}
}
}
async wispServer(wispServer?: string, set?: true) {
- this.#storageManager.setVal("wispServer", wispServer || this.#storageManager.getVal('wispServer') || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/");
+ this.#storageManager.setVal(
+ "wispServer",
+ wispServer ||
+ this.#storageManager.getVal("wispServer") ||
+ (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"
+ );
if (set) await this.setTransport();
}
@@ -82,22 +100,25 @@ class SW {
const checkScripts = (): Promise => {
return new Promise((resolve) => {
const t = setInterval(() => {
- if (typeof __uv$config !== 'undefined' && typeof ScramjetController !== 'undefined') {
+ if (
+ typeof __uv$config !== "undefined" &&
+ typeof ScramjetController !== "undefined"
+ ) {
clearInterval(t);
resolve();
}
});
});
};
- createScript('/vu/uv.bundle.js', true);
- createScript('/vu/uv.config.js', true);
- createScript('/marcs/scramjet.controller.js', true);
+ createScript("/vu/uv.bundle.js", true);
+ createScript("/vu/uv.config.js", true);
+ createScript("/marcs/scramjet.controller.js", true);
checkScripts().then(async () => {
this.#baremuxConn = new BareMuxConnection("/erab/worker.js");
await this.setTransport();
this.#scramjetController = new ScramjetController({
- prefix: '/~/scramjet/',
+ prefix: "/~/scramjet/",
files: {
wasm: "/marcs/scramjet.wasm.wasm",
worker: "/marcs/scramjet.worker.js",
@@ -109,19 +130,20 @@ class SW {
rewriterLogs: false
}
});
- if ("serviceWorker" in navigator) {
+ if ("serviceWorker" in navigator) {
await this.#scramjetController.init();
navigator.serviceWorker.ready.then(async (reg) => {
- console.log('SW ready to go!');
+ console.log("SW ready to go!");
this.#serviceWorker = reg;
});
- navigator.serviceWorker.register("/sw.js", { scope: '/' });
- }
- else {
- throw new Error('Your browser is not supported! This website uses Service Workers heavily.');
+ navigator.serviceWorker.register("/sw.js", { scope: "/" });
+ } else {
+ throw new Error(
+ "Your browser is not supported! This website uses Service Workers heavily."
+ );
}
});
- };
+ }
}
export { SW };
diff --git a/src/utils/settings.ts b/src/utils/settings.ts
index 1698aeb..e39b8b3 100644
--- a/src/utils/settings.ts
+++ b/src/utils/settings.ts
@@ -3,37 +3,37 @@ import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
import { SW } from "@utils/proxy.ts";
import { SearchEngines } from "./types";
/**
- * The settings class
- * Initializes it's own StorageManager, and handles everything within the class itself
- *
- * @example
- * // Create a new Settings instance (needs to be done only once)
- * import { Settings } from "@utils/settings.ts";
- * const settings = new Settings();
- * //Consume any of the methods with:
- * settings.methodName();
- *
- * // Most of the time, you'll want to get the running instance this can be done with
- * import { Settings } from "@utils/settings.ts";
- * const settings = await Settings.getInstance();
- * //Consume any of the methods with:
- * settings.methodName();
-*/
+ * The settings class
+ * Initializes it's own StorageManager, and handles everything within the class itself
+ *
+ * @example
+ * // Create a new Settings instance (needs to be done only once)
+ * import { Settings } from "@utils/settings.ts";
+ * const settings = new Settings();
+ * //Consume any of the methods with:
+ * settings.methodName();
+ *
+ * // Most of the time, you'll want to get the running instance this can be done with
+ * import { Settings } from "@utils/settings.ts";
+ * const settings = await Settings.getInstance();
+ * //Consume any of the methods with:
+ * settings.methodName();
+ */
class Settings {
// Our own internal StorageManager so things never interfere
#storageManager: StoreManager<"radius||settings">;
- static #instance = new Set();
-
+ static #instance = new Set();
+
/**
- * Method to get the current or other Settings instance(s)
- *
- *
- * @example
- * const settings = await Settings.getInstance();
- * // Consume the other methods
- */
+ * Method to get the current or other Settings instance(s)
+ *
+ *
+ * @example
+ * const settings = await Settings.getInstance();
+ * // Consume the other methods
+ */
static async getInstance() {
- function *get() {
+ function* get() {
for (const instance of Settings.#instance.keys()) {
yield instance!;
}
@@ -47,50 +47,50 @@ class Settings {
resolve(true);
}
}, 100);
- })
- }
+ });
+ };
await ready();
return get().next().value! as Settings;
}
-
+
/**
- * Set's the theme either to the current theme OR to a new one
- *
- * @example
- * // Retrieve the Settings instance
- * const settings = await Settings.getInstance();
- *
- * // Consume the method
- * settings.theme() // Whatever value is in localstorage at the time
- * settings.theme('theme name') // A new theme based off of the class name
- */
+ * Set's the theme either to the current theme OR to a new one
+ *
+ * @example
+ * // Retrieve the Settings instance
+ * const settings = await Settings.getInstance();
+ *
+ * // Consume the method
+ * settings.theme() // Whatever value is in localstorage at the time
+ * settings.theme('theme name') // A new theme based off of the class name
+ */
theme(theme?: string) {
- this.#storageManager.setVal('theme', theme || this.#storageManager.getVal('theme'));
- theme === 'default'
- ? document.documentElement.className = 'default'
- : document.documentElement.className = theme || this.#storageManager.getVal('theme');
+ this.#storageManager.setVal("theme", theme || this.#storageManager.getVal("theme"));
+ theme === "default"
+ ? (document.documentElement.className = "default")
+ : (document.documentElement.className = theme || this.#storageManager.getVal("theme"));
}
- proxy(prox?: 'uv' | 'sj') {
- this.#storageManager.setVal('proxy', prox || 'uv');
+ proxy(prox?: "uv" | "sj") {
+ this.#storageManager.setVal("proxy", prox || "uv");
}
searchEngine(engine?: string) {
- this.#storageManager.setVal('searchEngine', engine || SearchEngines.DuckDuckGo);
+ this.#storageManager.setVal("searchEngine", engine || SearchEngines.DuckDuckGo);
}
-
+
async *#init() {
- yield this.theme(this.#storageManager.getVal('theme') || 'default');
+ yield this.theme(this.#storageManager.getVal("theme") || "default");
}
constructor() {
this.#storageManager = new StoreManager("radius||settings");
Settings.#instance.add(this);
- (async() => {
- for await (const _ of this.#init());
+ (async () => {
+ for await (const _ of this.#init());
})();
}
}
-export { Settings }
+export { Settings };
diff --git a/src/utils/storage.ts b/src/utils/storage.ts
index 71cbdf1..10f24e3 100644
--- a/src/utils/storage.ts
+++ b/src/utils/storage.ts
@@ -14,4 +14,4 @@ class StoreManager {
}
}
-export { StoreManager }
+export { StoreManager };
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 8a6d989..2f5caf1 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -1,7 +1,7 @@
import type { Props } from "astro";
interface SettingsProps extends Props {
- active: 'appearance' | 'credits' | 'links' | 'proxy';
+ active: "appearance" | "credits" | "links" | "proxy";
title: string;
}
@@ -14,7 +14,7 @@ type DropdownOptions = {
const SearchEngines: Record = {
DuckDuckGo: "https://duckduckgo.com/?q=%s",
Google: "https://google.com/search?q=%s",
- Bing: "https://bing.com/search?q=%s",
+ Bing: "https://bing.com/search?q=%s"
};
export { type SettingsProps, type DropdownOptions, SearchEngines };
diff --git a/tsconfig.json b/tsconfig.json
index 3c992cf..68b841b 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,16 +1,16 @@
{
- "extends": "astro/tsconfigs/strict",
- "include": [".astro/types.d.ts", "**/*"],
- "exclude": ["dist", "server"],
- "compilerOptions": {
- "moduleResolution": "bundler",
- "baseUrl": ".",
- "paths": {
- "@components/*": ["src/components/*"],
- "@layouts/*": ["src/layouts/*"],
- "@utils/*": ["src/utils/*"],
- "@assets/*": ["src/assets/*"],
- "@styles/*": ["src/styles/*"]
+ "extends": "astro/tsconfigs/strict",
+ "include": [".astro/types.d.ts", "**/*"],
+ "exclude": ["dist", "server"],
+ "compilerOptions": {
+ "moduleResolution": "bundler",
+ "baseUrl": ".",
+ "paths": {
+ "@components/*": ["src/components/*"],
+ "@layouts/*": ["src/layouts/*"],
+ "@utils/*": ["src/utils/*"],
+ "@assets/*": ["src/assets/*"],
+ "@styles/*": ["src/styles/*"]
+ }
}
- }
}