Svelte: Pass a configuration object to the WebVM component

The config is loaded from files
This commit is contained in:
Alessandro Pignotti 2024-10-14 15:37:59 +02:00
parent b1e87af6f2
commit d4fd5f1be5
2 changed files with 9 additions and 10 deletions

View file

@ -13,8 +13,7 @@
import { cpuActivity, diskActivity } from '$lib/activities.js' import { cpuActivity, diskActivity } from '$lib/activities.js'
import { introMessage, errorMessage } from '$lib/messages.js' import { introMessage, errorMessage } from '$lib/messages.js'
export let diskImageUrl = null; export let configObj = null;
export let diskImageType = null;
var term = new Terminal({cursorBlink:true, convertEol:true, fontFamily:"monospace", fontWeight: 400, fontWeightBold: 700}); var term = new Terminal({cursorBlink:true, convertEol:true, fontFamily:"monospace", fontWeight: 400, fontWeightBold: 700});
var cx = null; var cx = null;
@ -72,22 +71,22 @@
{ {
// TODO: Check for SAB support // TODO: Check for SAB support
var blockDevice = null; var blockDevice = null;
switch(diskImageType) switch(configObj.diskImageType)
{ {
case "cloud": case "cloud":
try try
{ {
blockDevice = await CheerpX.CloudDevice.create(diskImageUrl); blockDevice = await CheerpX.CloudDevice.create(configObj.diskImageUrl);
} }
catch(e) catch(e)
{ {
// Report the failure and try again with plain HTTP // Report the failure and try again with plain HTTP
var wssProtocol = "wss:"; var wssProtocol = "wss:";
if(diskImageUrl.startsWith(wssProtocol)) if(configObj.diskImageUrl.startsWith(wssProtocol))
{ {
// WebSocket protocol failed, try agin using plain HTTP // WebSocket protocol failed, try agin using plain HTTP
plausible("WS Disk failure"); plausible("WS Disk failure");
blockDevice = await CheerpX.CloudDevice.create("https:" + diskImageUrl.substr(wssProtocol.length)); blockDevice = await CheerpX.CloudDevice.create("https:" + configObj.diskImageUrl.substr(wssProtocol.length));
} }
else else
{ {
@ -97,10 +96,10 @@
} }
break; break;
case "bytes": case "bytes":
blockDevice = await CheerpX.HttpBytesDevice.create(diskImageUrl); blockDevice = await CheerpX.HttpBytesDevice.create(configObj.diskImageUrl);
break; break;
case "github": case "github":
blockDevice = await CheerpX.GitHubDevice.create(diskImageUrl); blockDevice = await CheerpX.GitHubDevice.create(configObj.diskImageUrl);
break; break;
default: default:
throw new Error("Unrecognized device type"); throw new Error("Unrecognized device type");

View file

@ -1,6 +1,6 @@
<script> <script>
import WebVM from '$lib/WebVM.svelte'; import WebVM from '$lib/WebVM.svelte';
import { diskImageUrl, diskImageType } from 'diskConfig' import * as configObj from 'diskConfig'
</script> </script>
<WebVM diskImageUrl={diskImageUrl} diskImageType={diskImageType} /> <WebVM configObj={configObj} />