-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Launch web page for virtual terminal (#2)
Add source files for the web demo.
- Loading branch information
Showing
11 changed files
with
1,347 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/*! coi-serviceworker v0.1.6 - Guido Zuidhof, licensed under MIT */ | ||
let coepCredentialless = false; | ||
if (typeof window === 'undefined') { | ||
self.addEventListener("install", () => self.skipWaiting()); | ||
self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim())); | ||
|
||
self.addEventListener("message", (ev) => { | ||
if (!ev.data) { | ||
return; | ||
} else if (ev.data.type === "deregister") { | ||
self.registration | ||
.unregister() | ||
.then(() => { | ||
return self.clients.matchAll(); | ||
}) | ||
.then(clients => { | ||
clients.forEach((client) => client.navigate(client.url)); | ||
}); | ||
} else if (ev.data.type === "coepCredentialless") { | ||
coepCredentialless = ev.data.value; | ||
} | ||
}); | ||
|
||
self.addEventListener("fetch", function (event) { | ||
const r = event.request; | ||
if (r.cache === "only-if-cached" && r.mode !== "same-origin") { | ||
return; | ||
} | ||
|
||
const request = (coepCredentialless && r.mode === "no-cors") | ||
? new Request(r, { | ||
credentials: "omit", | ||
}) | ||
: r; | ||
event.respondWith( | ||
fetch(request) | ||
.then((response) => { | ||
if (response.status === 0) { | ||
return response; | ||
} | ||
|
||
const newHeaders = new Headers(response.headers); | ||
newHeaders.set("Cross-Origin-Embedder-Policy", | ||
coepCredentialless ? "credentialless" : "require-corp" | ||
); | ||
newHeaders.set("Cross-Origin-Opener-Policy", "same-origin"); | ||
|
||
return new Response(response.body, { | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: newHeaders, | ||
}); | ||
}) | ||
.catch((e) => console.error(e)) | ||
); | ||
}); | ||
|
||
} else { | ||
(() => { | ||
// You can customize the behavior of this script through a global `coi` variable. | ||
const coi = { | ||
shouldRegister: () => true, | ||
shouldDeregister: () => false, | ||
coepCredentialless: () => false, | ||
doReload: () => window.location.reload(), | ||
quiet: false, | ||
...window.coi | ||
}; | ||
|
||
const n = navigator; | ||
|
||
if (n.serviceWorker && n.serviceWorker.controller) { | ||
n.serviceWorker.controller.postMessage({ | ||
type: "coepCredentialless", | ||
value: coi.coepCredentialless(), | ||
}); | ||
|
||
if (coi.shouldDeregister()) { | ||
n.serviceWorker.controller.postMessage({ type: "deregister" }); | ||
} | ||
} | ||
|
||
// If we're already coi: do nothing. Perhaps it's due to this script doing its job, or COOP/COEP are | ||
// already set from the origin server. Also if the browser has no notion of crossOriginIsolated, just give up here. | ||
if (window.crossOriginIsolated !== false || !coi.shouldRegister()) return; | ||
|
||
if (!window.isSecureContext) { | ||
!coi.quiet && console.log("COOP/COEP Service Worker not registered, a secure context is required."); | ||
return; | ||
} | ||
|
||
// In some environments (e.g. Chrome incognito mode) this won't be available | ||
if (n.serviceWorker) { | ||
n.serviceWorker.register(window.document.currentScript.src).then( | ||
(registration) => { | ||
!coi.quiet && console.log("COOP/COEP Service Worker registered", registration.scope); | ||
|
||
registration.addEventListener("updatefound", () => { | ||
!coi.quiet && console.log("Reloading page to make use of updated COOP/COEP Service Worker."); | ||
coi.doReload(); | ||
}); | ||
|
||
// If the registration is active, but it's not controlling the page | ||
if (registration.active && !n.serviceWorker.controller) { | ||
!coi.quiet && console.log("Reloading page to make use of COOP/COEP Service Worker."); | ||
coi.doReload(); | ||
} | ||
}, | ||
(err) => { | ||
!coi.quiet && console.error("COOP/COEP Service Worker failed to register:", err); | ||
} | ||
); | ||
} | ||
})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Thistle OTA update demo (x86_64)</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/xterm.css"> | ||
</head> | ||
<body> | ||
<main class="container"> | ||
|
||
<h1>Thistle Demo</h1> | ||
|
||
<h2>Terminal</h2> | ||
<div class="d-inline-block" id="tib"></div> | ||
|
||
<p>It can take some time to load and start the console.</p> | ||
|
||
<hr> | ||
|
||
<p>Tested on Chromium Version 126.0.6478.126 (Official Build) (64-bit).</p> | ||
|
||
<p><a href="./index.html">Back to top</a></p> | ||
|
||
</main> | ||
<script src="./coi-serviceworker.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/xterm.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/index.js"></script> | ||
<script src="./src/stack.js"></script> | ||
<script src="./worker.js"></script> | ||
<!-- Modify the 4th and 5th input arguments of startWasi to use a different container image --> | ||
<script>startWasi("tib", "./src/worker.js"+location.search, location.origin + "/tib-demo" + "/tib_containers/tib-1.1.1_", 3);</script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.