mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-13 03:50:02 -04:00
Switch to bare client for omnibox, remove libcurl as a dep
This commit is contained in:
parent
32a7cc3b7c
commit
0d1d6e5490
6 changed files with 44 additions and 44 deletions
|
@ -43,7 +43,6 @@
|
||||||
"fastify": "^5.1.0",
|
"fastify": "^5.1.0",
|
||||||
"form-data": "^4.0.1",
|
"form-data": "^4.0.1",
|
||||||
"gradient-string": "^3.0.0",
|
"gradient-string": "^3.0.0",
|
||||||
"libcurl.js-new": "npm:libcurl.js@^0.6.19",
|
|
||||||
"nanostores": "^0.10.3",
|
"nanostores": "^0.10.3",
|
||||||
"ora": "^8.1.1",
|
"ora": "^8.1.1",
|
||||||
"pg": "^8.13.1",
|
"pg": "^8.13.1",
|
||||||
|
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
@ -83,9 +83,6 @@ importers:
|
||||||
gradient-string:
|
gradient-string:
|
||||||
specifier: ^3.0.0
|
specifier: ^3.0.0
|
||||||
version: 3.0.0
|
version: 3.0.0
|
||||||
libcurl.js-new:
|
|
||||||
specifier: npm:libcurl.js@^0.6.19
|
|
||||||
version: libcurl.js@0.6.19
|
|
||||||
nanostores:
|
nanostores:
|
||||||
specifier: ^0.10.3
|
specifier: ^0.10.3
|
||||||
version: 0.10.3
|
version: 0.10.3
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { settings, Settings } from "@utils/settings/index";
|
import { settings, Settings } from "@utils/settings/index";
|
||||||
|
import { loadProxyScripts, setTransport, initSw, setSWStuff } from "@utils/registerSW";
|
||||||
// This loads the settings in a nice way
|
// This loads the settings in a nice way
|
||||||
settings.tabSettings.cloakTab(localStorage.getItem(Settings.TabSettings.tabCloak) as string || "default");
|
settings.tabSettings.cloakTab(localStorage.getItem(Settings.TabSettings.tabCloak) as string || "default");
|
||||||
settings.proxySettings.changeProxy(localStorage.getItem(Settings.ProxySettings.proxy) as string || "automatic");
|
settings.proxySettings.changeProxy(localStorage.getItem(Settings.ProxySettings.proxy) as string || "automatic");
|
||||||
|
@ -12,4 +13,13 @@
|
||||||
settings.tabSettings.cloakTab(localStorage.getItem(Settings.TabSettings.tabCloak) as string || "default");
|
settings.tabSettings.cloakTab(localStorage.getItem(Settings.TabSettings.tabCloak) as string || "default");
|
||||||
//settings.marketPlaceSettings.changeTheme(false);
|
//settings.marketPlaceSettings.changeTheme(false);
|
||||||
});
|
});
|
||||||
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
const conn = await loadProxyScripts();
|
||||||
|
await setTransport(
|
||||||
|
conn,
|
||||||
|
localStorage.getItem(Settings.ProxySettings.transport) as string
|
||||||
|
);
|
||||||
|
const sw = await initSw();
|
||||||
|
await setSWStuff({sw, conn});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -57,7 +57,7 @@ import { VERSION } from "astro:env/client";
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
<script>
|
<script>
|
||||||
import { initSw, setTransport, loadProxyScripts } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
|
import { setTransport, getSWStuff } from "@utils/registerSW"; //../../utils/registerSW.ts
|
||||||
import { pageLoad } from "@utils/events";
|
import { pageLoad } from "@utils/events";
|
||||||
import { SupportedSites } from "@utils/siteSupport";
|
import { SupportedSites } from "@utils/siteSupport";
|
||||||
import {
|
import {
|
||||||
|
@ -66,8 +66,8 @@ import { VERSION } from "astro:env/client";
|
||||||
cloak,
|
cloak,
|
||||||
settings,
|
settings,
|
||||||
} from "@utils/settings/index";
|
} from "@utils/settings/index";
|
||||||
import { search } from "@utils/search.ts"; //../../utils/search.ts
|
import { search } from "@utils/search"; //../../utils/search.ts
|
||||||
import { client as libcurlClient } from "@utils/libcurl";
|
import { BareClient } from "@mercuryworkshop/bare-mux";
|
||||||
type Suggestion = {
|
type Suggestion = {
|
||||||
phrase: string;
|
phrase: string;
|
||||||
};
|
};
|
||||||
|
@ -97,12 +97,11 @@ import { VERSION } from "astro:env/client";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function uv(iframe: HTMLIFrameElement, term: string) {
|
async function uv(iframe: HTMLIFrameElement, term: string) {
|
||||||
const conn = await loadProxyScripts();
|
const { sw, conn } = getSWStuff();
|
||||||
await setTransport(
|
await setTransport(
|
||||||
conn,
|
conn,
|
||||||
localStorage.getItem(Settings.ProxySettings.transport) as string
|
localStorage.getItem(Settings.ProxySettings.transport) as string
|
||||||
);
|
);
|
||||||
const sw = await initSw();
|
|
||||||
await settings.marketPlaceSettings.handlePlugins(sw);
|
await settings.marketPlaceSettings.handlePlugins(sw);
|
||||||
iframe.classList.remove("hidden");
|
iframe.classList.remove("hidden");
|
||||||
const url = await proxy(term);
|
const url = await proxy(term);
|
||||||
|
@ -148,12 +147,10 @@ import { VERSION } from "astro:env/client";
|
||||||
omnibox.classList.add("hidden");
|
omnibox.classList.add("hidden");
|
||||||
}
|
}
|
||||||
if (value.length >= 3) {
|
if (value.length >= 3) {
|
||||||
await libcurlClient.initLibcurl();
|
const client = new BareClient();
|
||||||
const data = (await libcurlClient.fetchFromLibcurl(
|
const data = await client.fetch(`https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json`);
|
||||||
`https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json`,
|
const dataRes = await data.json();
|
||||||
"json"
|
const filteredData = dataRes.slice(0, 8); //Trim to only about 8 results. Any more and our omnibox dies
|
||||||
)) as [];
|
|
||||||
const filteredData = data.slice(0, 8); //Trim to only about 8 results. Any more and our omnibox dies
|
|
||||||
if (filteredData) {
|
if (filteredData) {
|
||||||
omnibox.innerHTML = "";
|
omnibox.innerHTML = "";
|
||||||
filteredData.map((results: Suggestion) => {
|
filteredData.map((results: Suggestion) => {
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
import { WispServerURLS } from "@utils/settings/index";
|
|
||||||
//helper for libcurl as we have to use it in multiple locations and we don't want to re-download the WASM every time
|
|
||||||
//@ts-expect-error No types, expected. See: https://github.com/ading2210/libcurl.js for docs on how to use.
|
|
||||||
import { libcurl } from "libcurl.js-new/bundled";
|
|
||||||
let clientExists: boolean = false;
|
|
||||||
async function initLibcurl() {
|
|
||||||
if (!clientExists) {
|
|
||||||
await libcurl.load_wasm();
|
|
||||||
libcurl.set_websocket(WispServerURLS.default);
|
|
||||||
console.debug("Libcurl ready?", libcurl.ready);
|
|
||||||
clientExists = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type fetchType = "json" | "text";
|
|
||||||
|
|
||||||
async function fetchFromLibcurl(url: string, type: fetchType): Promise<string | [] | {}> {
|
|
||||||
const res = await libcurl.fetch(url);
|
|
||||||
const data = type === "json" ? await res.json() : await res.text();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
const client = {
|
|
||||||
initLibcurl,
|
|
||||||
fetchFromLibcurl
|
|
||||||
};
|
|
||||||
|
|
||||||
export { client };
|
|
|
@ -1,5 +1,9 @@
|
||||||
import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
|
import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
|
||||||
import { Settings, WispServerURLS } from "./settings/index";
|
import { Settings, WispServerURLS } from "./settings/index";
|
||||||
|
|
||||||
|
let baremuxConn: BareMuxConnection;
|
||||||
|
let swReg: ServiceWorkerRegistration;
|
||||||
|
|
||||||
function loadProxyScripts() {
|
function loadProxyScripts() {
|
||||||
//wrap everything in a promise to avoid race conditions
|
//wrap everything in a promise to avoid race conditions
|
||||||
return new Promise<BareMuxConnection>((resolve) => {
|
return new Promise<BareMuxConnection>((resolve) => {
|
||||||
|
@ -57,4 +61,25 @@ function initSw() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { initSw, setTransport, loadProxyScripts };
|
interface SWStuff {
|
||||||
|
sw: ServiceWorkerRegistration;
|
||||||
|
conn: BareMuxConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setSWStuff(stuff: SWStuff): Promise<void> {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
swReg = stuff.sw;
|
||||||
|
baremuxConn = stuff.conn;
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSWStuff(): SWStuff {
|
||||||
|
const stuff: SWStuff = {
|
||||||
|
sw: swReg,
|
||||||
|
conn: baremuxConn
|
||||||
|
}
|
||||||
|
return stuff;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { initSw, setTransport, loadProxyScripts, setSWStuff, getSWStuff };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue