From f7fc244db4cf4e0011505b3ef2b08e0475f1e2ef Mon Sep 17 00:00:00 2001 From: Alessandro Pignotti Date: Mon, 14 Oct 2024 16:39:19 +0200 Subject: [PATCH] Svelte: Expose more extensive configuration from the main WebVM component --- config_public_terminal.js | 21 +++++++++++++++++++++ src/lib/WebVM.svelte | 25 +++---------------------- src/routes/+page.svelte | 2 +- vite.config.js | 2 +- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/config_public_terminal.js b/config_public_terminal.js index d4341a0..8708dbc 100644 --- a/config_public_terminal.js +++ b/config_public_terminal.js @@ -1,2 +1,23 @@ +// The root filesystem location export const diskImageUrl = "wss://disks.webvm.io/debian_large_20230522_5044875331.ext2"; +// The root filesystem backend type export const diskImageType = "cloud"; +// Print an introduction message about the technology +export const printIntro = true; +// Is a graphical display needed +export const needsDisplay = false; +// Executable full path (Required) +export const cmd = "/bin/bash"; +// Arguments, as an array (Required) +export const args = ["--login"]; +// Optional extra parameters +export const opts = { + // Environment variables + env: ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"], + // Current working directory + cwd: "/home/user", + // User id + uid: 1000, + // Group id + gid: 1000 +}; diff --git a/src/lib/WebVM.svelte b/src/lib/WebVM.svelte index 07ab43d..d25b72f 100644 --- a/src/lib/WebVM.svelte +++ b/src/lib/WebVM.svelte @@ -64,7 +64,8 @@ consoleDiv.addEventListener("dragenter", preventDefaults, false); consoleDiv.addEventListener("dragleave", preventDefaults, false); consoleDiv.addEventListener("drop", preventDefaults, false); - printMessage(introMessage); + if(configObj.printIntro) + printMessage(introMessage); initCheerpX(); } async function initCheerpX() @@ -133,30 +134,10 @@ cx.registerCallback("diskActivity", hddCallback); term.scrollToBottom(); cxReadFunc = cx.setCustomConsole(writeData, term.cols, term.rows); - // Reasonable defaults for local deployments - // var cmd = "/bin/bash"; - // var args = ["--login"]; - // var env = ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"]; - // var cwd = "/home/user"; - // Executable full path (Required) - var cmd = "/bin/bash"; - // Arguments, as an array (Required) - var args = ["--login"] - // Optional extra parameters - var opts = { - // Environment variables - env: ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"], - // Current working directory - cwd: "/home/user", - // User id - uid: 1000, - // Group id - gid: 1000 - }; // Run the command in a loop, in case the user exits while (true) { - await cx.run(cmd, args, opts); + await cx.run(configObj.cmd, configObj.args, configObj.opts); } } onMount(initTerminal); diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7a55ea6..a9de55b 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,6 +1,6 @@ diff --git a/vite.config.js b/vite.config.js index 70eb7e3..05a5e6d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,7 +5,7 @@ import { viteStaticCopy } from 'vite-plugin-static-copy'; export default defineConfig({ resolve: { alias: { - 'config_terminal': 'config_public_terminal.js' + '/config_terminal': 'config_public_terminal.js' } }, build: {