More changes?
This commit is contained in:
parent
5bd87033e2
commit
b34b24e783
2 changed files with 25 additions and 8 deletions
|
|
@ -3,11 +3,12 @@ import LoadingComponent from "@components/Loading.astro";
|
||||||
import Layout from "@layouts/Layout.astro";
|
import Layout from "@layouts/Layout.astro";
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="Loading page..." noHeader="true">
|
<!-- Layout title="Loading page..." noHeader="true">
|
||||||
<LoadingComponent />
|
<LoadingComponent />
|
||||||
</Layout>
|
</Layout-->
|
||||||
<script>
|
<script>
|
||||||
import { EventHandler } from "@utils/events";
|
import { EventHandler } from "@utils/events";
|
||||||
|
import { createBareMuxConn, createProxyScripts, SW } from "@utils/serviceWorker";
|
||||||
import { navigate } from "astro:transitions/client";
|
import { navigate } from "astro:transitions/client";
|
||||||
function isComingFromIframe() {
|
function isComingFromIframe() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -24,8 +25,20 @@ import Layout from "@layouts/Layout.astro";
|
||||||
const isIframe = isComingFromIframe();
|
const isIframe = isComingFromIframe();
|
||||||
if (!isIframe) {
|
if (!isIframe) {
|
||||||
console.log("Assuming request isn't coming from iframe. Redirecting...");
|
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
|
logging: false
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ const createScript = (src: string, defer?: boolean): HTMLScriptElement => {
|
||||||
function* createProxyScripts() {
|
function* createProxyScripts() {
|
||||||
const uv = createScript("/uv/uv.bundle.js", true);
|
const uv = createScript("/uv/uv.bundle.js", true);
|
||||||
yield uv;
|
yield uv;
|
||||||
|
const uvConfig = createScript("/uv/uv.config.js", true);
|
||||||
|
yield uvConfig;
|
||||||
const sj = createScript("/scram/scramjet.controller.js", true);
|
const sj = createScript("/scram/scramjet.controller.js", true);
|
||||||
yield sj;
|
yield sj;
|
||||||
};
|
};
|
||||||
|
|
@ -78,7 +80,7 @@ type SWInit = {
|
||||||
class SW {
|
class SW {
|
||||||
#init!: SWInit;
|
#init!: SWInit;
|
||||||
constructor(conn: BareMuxConnection) {
|
constructor(conn: BareMuxConnection) {
|
||||||
const sj = async (): Promise<ScramjetController> => {
|
const sj = (): ScramjetController => {
|
||||||
const sj = new ScramjetController({
|
const sj = new ScramjetController({
|
||||||
prefix: '/~/scramjet',
|
prefix: '/~/scramjet',
|
||||||
files: {
|
files: {
|
||||||
|
|
@ -89,13 +91,14 @@ class SW {
|
||||||
sync: "/scram/scramjet.sync.js"
|
sync: "/scram/scramjet.sync.js"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await sj.init();
|
|
||||||
return sj;
|
return sj;
|
||||||
}
|
}
|
||||||
if ("serviceWorker" in navigator) {
|
if ("serviceWorker" in navigator) {
|
||||||
|
const scram = sj();
|
||||||
|
(async () => await scram.init())();
|
||||||
navigator.serviceWorker.ready.then(async (reg) => {
|
navigator.serviceWorker.ready.then(async (reg) => {
|
||||||
console.log("Service worker ready and active!");
|
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: '/' });
|
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.
|
* Returns an object with the service worker, scramjet controller and baremux connection all in one method.
|
||||||
*/
|
*/
|
||||||
getSWInfo(): SWInit {
|
getSWInfo(): SWInit | Error {
|
||||||
return this.#init;
|
if (this.#init !== undefined) return this.#init;
|
||||||
|
return new Error("this object is undefined!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue