More changes?

This commit is contained in:
MotorTruck1221 2025-01-03 12:52:58 -07:00
parent 5bd87033e2
commit b34b24e783
No known key found for this signature in database
GPG key ID: 08F417E2B8B61EA4
2 changed files with 25 additions and 8 deletions

View file

@ -3,11 +3,12 @@ import LoadingComponent from "@components/Loading.astro";
import Layout from "@layouts/Layout.astro";
---
<Layout title="Loading page..." noHeader="true">
<!-- Layout title="Loading page..." noHeader="true">
<LoadingComponent />
</Layout>
</Layout-->
<script>
import { EventHandler } from "@utils/events";
import { createBareMuxConn, createProxyScripts, SW } from "@utils/serviceWorker";
import { navigate } from "astro:transitions/client";
function isComingFromIframe() {
try {
@ -24,8 +25,20 @@ import Layout from "@layouts/Layout.astro";
const isIframe = isComingFromIframe();
if (!isIframe) {
console.log("Assuming request isn't coming from iframe. Redirecting...");
navigate("/");
//navigate("/");
}
}),
"DOMContentLoaded": (async () => {
for (let item of createProxyScripts()) {
document.body.appendChild(item);
}
const checkScript = setInterval(async () => {
if (typeof __uv$config !== "undefined" && typeof ScramjetController !== "undefined") {
clearInterval(checkScript);
const conn = await createBareMuxConn("/baremux/worker.js");
window.sw = new SW(conn);
}
}, 100);
})
},
logging: false

View file

@ -27,6 +27,8 @@ const createScript = (src: string, defer?: boolean): HTMLScriptElement => {
function* createProxyScripts() {
const uv = createScript("/uv/uv.bundle.js", true);
yield uv;
const uvConfig = createScript("/uv/uv.config.js", true);
yield uvConfig;
const sj = createScript("/scram/scramjet.controller.js", true);
yield sj;
};
@ -78,7 +80,7 @@ type SWInit = {
class SW {
#init!: SWInit;
constructor(conn: BareMuxConnection) {
const sj = async (): Promise<ScramjetController> => {
const sj = (): ScramjetController => {
const sj = new ScramjetController({
prefix: '/~/scramjet',
files: {
@ -89,13 +91,14 @@ class SW {
sync: "/scram/scramjet.sync.js"
}
});
await sj.init();
return sj;
}
if ("serviceWorker" in navigator) {
const scram = sj();
(async () => await scram.init())();
navigator.serviceWorker.ready.then(async (reg) => {
console.log("Service worker ready and active!");
this.#init = { serviceWorker: reg, sj: await sj(), bareMuxConn: conn }
this.#init = { serviceWorker: reg, sj: scram, bareMuxConn: conn }
});
navigator.serviceWorker.register("/sw.js", { scope: '/' });
}
@ -114,8 +117,9 @@ class SW {
/**
* Returns an object with the service worker, scramjet controller and baremux connection all in one method.
*/
getSWInfo(): SWInit {
return this.#init;
getSWInfo(): SWInit | Error {
if (this.#init !== undefined) return this.#init;
return new Error("this object is undefined!");
}
}