Formatting

This commit is contained in:
MotorTruck1221 2024-03-06 01:19:16 -07:00
parent 69823802f5
commit 8f531aff11
No known key found for this signature in database
GPG key ID: 06901A625432AC21
14 changed files with 568 additions and 541 deletions

View file

@ -158,9 +158,8 @@ server.on("upgrade", (req: Request, socket: Socket, head: Head) => {
bare.routeUpgrade(req, socket, head);
} else if (shouldRouteRh(req)) {
routeRhUpgrade(req, socket, head);
}
else if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
} else if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
}
});

View file

@ -9,7 +9,7 @@ interface Option {
const Dropdown = ({
storageKey,
options,
refresh,
refresh
}: {
storageKey: string;
options: Option[];

View file

@ -29,11 +29,12 @@ const Proxy = ({ id, active }) => {
{ id: "https://bing.com/search?q=%s", label: "Bing" }
];
const wispUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
const wispUrl =
(location.protocol === "https:" ? "wss://" : "ws://") +
location.host +
"/wisp/";
//libcurl can be added here when it's stable
const transports = [
{ id: "epoxy", label: "Epoxy" }
];
const transports = [{ id: "epoxy", label: "Epoxy" }];
return (
<motion.div
@ -93,22 +94,27 @@ const Proxy = ({ id, active }) => {
<BareInput placeholder="/bare/" storageKey="bare" />
</div>
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
<div className="p-2 text-3xl font-bold text-input-text">
Wisp Server
</div>
<div className="text-md p-4 font-bold text-input-text">
Enter the url of a Wisp server
</div>
<WispInput placeholder={wispUrl} />
<div className="p-2 text-3xl font-bold text-input-text">
Wisp Server
</div>
<div className="text-md p-4 font-bold text-input-text">
Enter the url of a Wisp server
</div>
<WispInput placeholder={wispUrl} />
</div>
<div className="flex h-64 w-80 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
<div className="p-2 text-3xl font-bold text-input-text">
Transport
</div>
<div className="text-md p-4 font-bold text-input-text">
Select the transport to use
</div>
<Dropdown storageKey="transport" options={transports} refresh={false} onChange={(value) => changeTransport(value, wispUrl)} />
<div className="p-2 text-3xl font-bold text-input-text">
Transport
</div>
<div className="text-md p-4 font-bold text-input-text">
Select the transport to use
</div>
<Dropdown
storageKey="transport"
options={transports}
refresh={false}
onChange={(value) => changeTransport(value, wispUrl)}
/>
</div>
<div className="flex h-96 w-96 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
<div className="p-2 text-3xl font-bold text-input-text">

View file

@ -9,22 +9,30 @@ interface WispInputProps {
function WispInput(props: WispInputProps) {
const { t } = useTranslation();
const value = localStorage.getItem("wispUrl") || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
const value =
localStorage.getItem("wispUrl") ||
(location.protocol === "https:" ? "wss://" : "ws://") +
location.host +
"/wisp/";
const [inputValue, setInputValue] = useState(value);
function validateUrl(url: string) {
let finalUrl = url;
if (finalUrl.startsWith("http://")) {
finalUrl = finalUrl.replace("http://", "ws://");
finalUrl = finalUrl.replace("http://", "ws://");
} else if (finalUrl.startsWith("https://")) {
finalUrl = finalUrl.replace("https://", "wss://");
}
else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) {
finalUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
finalUrl = finalUrl.replace("https://", "wss://");
} else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) {
finalUrl =
(location.protocol === "https:" ? "wss://" : "ws://") +
location.host +
"/wisp/";
}
return finalUrl;
}
function handleChange() {
const url = validateUrl((document.getElementById("wispinput") as HTMLInputElement).value);
const url = validateUrl(
(document.getElementById("wispinput") as HTMLInputElement).value
);
localStorage.setItem("wispUrl", url);
changeTransport(localStorage.getItem("transport") || "epoxy", url);
}

View file

@ -1,40 +1,54 @@
import { SetTransport, registerRemoteListener } from "@mercuryworkshop/bare-mux";
import {
SetTransport,
registerRemoteListener
} from "@mercuryworkshop/bare-mux";
declare global {
interface Window {
BareMux: any;
p: any;
}
interface Window {
BareMux: any;
p: any;
}
}
function changeTransport(transport: string, wispUrl: string) {
switch (transport) {
case "epoxy":
localStorage.setItem("transport", "epoxy");
SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl });
break;
//libcurl when supported can be easily added here
//and stuff like bare-as-module3 COULD also be added
default:
SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl });
break;
}
switch (transport) {
case "epoxy":
localStorage.setItem("transport", "epoxy");
SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl });
break;
//libcurl when supported can be easily added here
//and stuff like bare-as-module3 COULD also be added
default:
SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl });
break;
}
}
function getTransport() {
return localStorage.getItem("transport") || "epoxy";
return localStorage.getItem("transport") || "epoxy";
}
function restartTransport() {
changeTransport(getTransport(), localStorage.getItem("wispUrl") || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/");
changeTransport(
getTransport(),
localStorage.getItem("wispUrl") ||
(location.protocol === "https:" ? "wss://" : "ws://") +
location.host +
"/wisp/"
);
}
//restart transport every minute
setInterval(restartTransport, 60000); //60000ms = 60s = 1m
const wispUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
const wispUrl =
(location.protocol === "https:" ? "wss://" : "ws://") +
location.host +
"/wisp/";
registerRemoteListener(navigator.serviceWorker.controller!);
changeTransport(localStorage.getItem("transport") || "epoxy", localStorage.getItem("wispUrl") || wispUrl);
changeTransport(
localStorage.getItem("transport") || "epoxy",
localStorage.getItem("wispUrl") || wispUrl
);
export { changeTransport, getTransport };

View file

@ -25,10 +25,10 @@ export default defineConfig({
// overwrite: false
//},
{
//include ALL files types
src: `${epoxyPath}/**/*`,
dest: "epoxy",
overwrite: false
//include ALL files types
src: `${epoxyPath}/**/*`,
dest: "epoxy",
overwrite: false
},
{
// .replace fixes weird paths on Windows