From d4fd5f1be548ae6beeebbd75e323d85cc7d4b4e5 Mon Sep 17 00:00:00 2001 From: Alessandro Pignotti Date: Mon, 14 Oct 2024 15:37:59 +0200 Subject: [PATCH] Svelte: Pass a configuration object to the WebVM component The config is loaded from files --- src/lib/WebVM.svelte | 15 +++++++-------- src/routes/+page.svelte | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lib/WebVM.svelte b/src/lib/WebVM.svelte index 0248511..07ab43d 100644 --- a/src/lib/WebVM.svelte +++ b/src/lib/WebVM.svelte @@ -13,8 +13,7 @@ import { cpuActivity, diskActivity } from '$lib/activities.js' import { introMessage, errorMessage } from '$lib/messages.js' - export let diskImageUrl = null; - export let diskImageType = null; + export let configObj = null; var term = new Terminal({cursorBlink:true, convertEol:true, fontFamily:"monospace", fontWeight: 400, fontWeightBold: 700}); var cx = null; @@ -72,22 +71,22 @@ { // TODO: Check for SAB support var blockDevice = null; - switch(diskImageType) + switch(configObj.diskImageType) { case "cloud": try { - blockDevice = await CheerpX.CloudDevice.create(diskImageUrl); + blockDevice = await CheerpX.CloudDevice.create(configObj.diskImageUrl); } catch(e) { // Report the failure and try again with plain HTTP var wssProtocol = "wss:"; - if(diskImageUrl.startsWith(wssProtocol)) + if(configObj.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)); + blockDevice = await CheerpX.CloudDevice.create("https:" + configObj.diskImageUrl.substr(wssProtocol.length)); } else { @@ -97,10 +96,10 @@ } break; case "bytes": - blockDevice = await CheerpX.HttpBytesDevice.create(diskImageUrl); + blockDevice = await CheerpX.HttpBytesDevice.create(configObj.diskImageUrl); break; case "github": - blockDevice = await CheerpX.GitHubDevice.create(diskImageUrl); + blockDevice = await CheerpX.GitHubDevice.create(configObj.diskImageUrl); break; default: throw new Error("Unrecognized device type"); diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 5003bfe..56e7a1c 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,6 +1,6 @@ - +