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); bare.routeUpgrade(req, socket, head);
} else if (shouldRouteRh(req)) { } else if (shouldRouteRh(req)) {
routeRhUpgrade(req, socket, head); routeRhUpgrade(req, socket, head);
} } else if (req.url.endsWith("/wisp/")) {
else if (req.url.endsWith("/wisp/")) { wisp.routeRequest(req, socket, head);
wisp.routeRequest(req, socket, head);
} }
}); });

View file

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

View file

@ -29,11 +29,12 @@ const Proxy = ({ id, active }) => {
{ id: "https://bing.com/search?q=%s", label: "Bing" } { 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 //libcurl can be added here when it's stable
const transports = [ const transports = [{ id: "epoxy", label: "Epoxy" }];
{ id: "epoxy", label: "Epoxy" }
];
return ( return (
<motion.div <motion.div
@ -93,22 +94,27 @@ const Proxy = ({ id, active }) => {
<BareInput placeholder="/bare/" storageKey="bare" /> <BareInput placeholder="/bare/" storageKey="bare" />
</div> </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="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"> <div className="p-2 text-3xl font-bold text-input-text">
Wisp Server Wisp Server
</div> </div>
<div className="text-md p-4 font-bold text-input-text"> <div className="text-md p-4 font-bold text-input-text">
Enter the url of a Wisp server Enter the url of a Wisp server
</div> </div>
<WispInput placeholder={wispUrl} /> <WispInput placeholder={wispUrl} />
</div> </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="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"> <div className="p-2 text-3xl font-bold text-input-text">
Transport Transport
</div> </div>
<div className="text-md p-4 font-bold text-input-text"> <div className="text-md p-4 font-bold text-input-text">
Select the transport to use Select the transport to use
</div> </div>
<Dropdown storageKey="transport" options={transports} refresh={false} onChange={(value) => changeTransport(value, wispUrl)} /> <Dropdown
storageKey="transport"
options={transports}
refresh={false}
onChange={(value) => changeTransport(value, wispUrl)}
/>
</div> </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="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"> <div className="p-2 text-3xl font-bold text-input-text">

View file

@ -9,22 +9,30 @@ interface WispInputProps {
function WispInput(props: WispInputProps) { function WispInput(props: WispInputProps) {
const { t } = useTranslation(); 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); const [inputValue, setInputValue] = useState(value);
function validateUrl(url: string) { function validateUrl(url: string) {
let finalUrl = url; let finalUrl = url;
if (finalUrl.startsWith("http://")) { if (finalUrl.startsWith("http://")) {
finalUrl = finalUrl.replace("http://", "ws://"); finalUrl = finalUrl.replace("http://", "ws://");
} else if (finalUrl.startsWith("https://")) { } else if (finalUrl.startsWith("https://")) {
finalUrl = finalUrl.replace("https://", "wss://"); finalUrl = finalUrl.replace("https://", "wss://");
} } else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) {
else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) { finalUrl =
finalUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"; (location.protocol === "https:" ? "wss://" : "ws://") +
location.host +
"/wisp/";
} }
return finalUrl; return finalUrl;
} }
function handleChange() { function handleChange() {
const url = validateUrl((document.getElementById("wispinput") as HTMLInputElement).value); const url = validateUrl(
(document.getElementById("wispinput") as HTMLInputElement).value
);
localStorage.setItem("wispUrl", url); localStorage.setItem("wispUrl", url);
changeTransport(localStorage.getItem("transport") || "epoxy", 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 { declare global {
interface Window { interface Window {
BareMux: any; BareMux: any;
p: any; p: any;
} }
} }
function changeTransport(transport: string, wispUrl: string) { function changeTransport(transport: string, wispUrl: string) {
switch (transport) { switch (transport) {
case "epoxy": case "epoxy":
localStorage.setItem("transport", "epoxy"); localStorage.setItem("transport", "epoxy");
SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl }); SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl });
break; break;
//libcurl when supported can be easily added here //libcurl when supported can be easily added here
//and stuff like bare-as-module3 COULD also be added //and stuff like bare-as-module3 COULD also be added
default: default:
SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl }); SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl });
break; break;
} }
} }
function getTransport() { function getTransport() {
return localStorage.getItem("transport") || "epoxy"; return localStorage.getItem("transport") || "epoxy";
} }
function restartTransport() { 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 //restart transport every minute
setInterval(restartTransport, 60000); //60000ms = 60s = 1m 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!); 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 }; export { changeTransport, getTransport };

View file

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