Initialize CheerpX disk backend for the main image

This commit is contained in:
Alessandro Pignotti 2024-10-05 18:51:20 +02:00
parent 74e18f2b38
commit f586c4bcf2
2 changed files with 43 additions and 2 deletions

View file

@ -1 +1,2 @@
export const imageUrl = "wss://disks-staging.webvm.io/debian_large_20230522_5044875331.ext2";
export const diskImageUrl = "wss://disks-staging.webvm.io/debian_large_20230522_5044875331.ext2";
export const diskImageType = "cloud";

View file

@ -6,7 +6,7 @@
import Nav from 'labs/packages/global-navbar/src/Nav.svelte';
import SideBar from './SideBar.svelte';
import * as CheerpX from '@leaningtech/cheerpx';
import { imageUrl } from 'diskConfig'
import { diskImageUrl, diskImageType } from 'diskConfig'
var term = new Terminal({cursorBlink:true, convertEol:true, fontFamily:"monospace", fontWeight: 400, fontWeightBold: 700});
var fitAddon = new FitAddon();
@ -21,6 +21,46 @@
fitAddon.fit();
window.addEventListener("resize", function(ev){ fitAddon.fit(); });
term.focus();
initCheerpX();
}
async function initCheerpX()
{
// TODO: Check for SAB support
// TODO: Initialize network
var blockDevice = null;
switch(diskImageType)
{
case "cloud":
try
{
blockDevice = await CheerpX.CloudDevice.create(diskImageUrl);
}
catch(e)
{
// Report the failure and try again with plain HTTP
var wssProtocol = "wss:";
if(diskImageUrl.startsWith(wssProtocol))
{
// WebSocket protocol failed, try agin using plain HTTP
plausible("WS Disk failure");
blockDevice = await CheerpX.CloudDevice.create("https:" + diskImageUrl.substr(wssProtocol.length));
}
else
{
// No other recovery option
throw e;
}
}
break;
case "bytes":
blockDevice = await CheerpX.HttpBytesDevice.create(diskImageUrl);
break;
case "github":
blockDevice = await CheerpX.GitHubDevice.create(diskImageUrl);
break;
default:
throw new Error("Unrecognized device type");
}
}
onMount(initTerminal);
</script>