Skip to content

Commit 61d8727

Browse files
committed
User of library has to provide paths to images
The reason is that Vite force-inlines all imported files as base64-encoded data URLs. v86 does *not* like that.
1 parent 31ecfb4 commit 61d8727

File tree

8 files changed

+33
-31
lines changed

8 files changed

+33
-31
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"name": "web-shell",
2+
"name": "linux-browser-shell",
33
"version": "0.1.0",
44
"type": "module",
5-
"main": "./dist/web-shell.umd.cjs",
6-
"module": "./dist/web-shell.js",
5+
"main": "./dist/linux-browser-shell.umd.cjs",
6+
"module": "./dist/linux-browser-shell.js",
77
"types": "./dist/index.d.ts",
88
"exports": {
99
".": {
1010
"import": {
1111
"types": "./dist/index.d.ts",
12-
"default": "./dist/web-shell.js"
12+
"default": "./dist/linux-browser-shell.js"
1313
},
1414
"require": {
1515
"types": "./dist/index.d.ts",
16-
"default": "./dist/web-shell.umd.cjs"
16+
"default": "./dist/linux-browser-shell.umd.cjs"
1717
}
1818
}
1919
},

src/index.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
//@ts-ignore
22
import V86Starter from "../v86/libv86.js"
3-
//@ts-ignore
4-
import wasmPath from "../v86/v86.wasm?url"
5-
//@ts-ignore
6-
import biosPath from "../v86/seabios.bin?url"
7-
//@ts-ignore
8-
import vgaBiosPath from "../v86/vgabios.bin?url"
9-
//@ts-ignore
10-
import cdromPath from "../v86/image.iso.zst?url"
11-
//@ts-ignore
12-
import bootedStatePath from "../v86/booted-state.bin.zst?url"
133

144
import {Mutex} from "async-mutex"
155

16-
class WebShell {
6+
class LinuxBrowserShell {
177
private mutex: Mutex
188
private mutex2: Mutex
199
private emulator: any
2010

21-
// Whether or not to restore the VM state from a file. Set to false to perform a regular boot.
22-
private restoreState = true
2311
private config: any = {
24-
wasm_path: wasmPath,
2512
memory_size: 64 * 1024 * 1024,
2613
vga_memory_size: 2 * 1024 * 1024,
27-
bios: {url: biosPath},
28-
vga_bios: {url: vgaBiosPath},
29-
cdrom: {url: cdromPath},
3014
disable_mouse: true,
3115
autostart: true,
3216
}
@@ -36,14 +20,29 @@ class WebShell {
3620

3721
//private serialBuffer = ""
3822

39-
constructor(screen?: HTMLDivElement, serial?: HTMLDivElement) {
23+
constructor(
24+
paths: {
25+
wasm: string
26+
bios: string
27+
vga_bios: string
28+
cdrom: string
29+
initial_state?: string
30+
},
31+
screen?: HTMLDivElement,
32+
serial?: HTMLDivElement,
33+
) {
4034
this.mutex = new Mutex()
4135
this.mutex2 = new Mutex()
4236

37+
this.config["wasm_path"] = paths.wasm
38+
this.config["bios"] = {url: paths.bios}
39+
this.config["vga_bios"] = {url: paths.vga_bios}
40+
this.config["cdrom"] = {url: paths.cdrom}
41+
4342
if (screen) {
4443
let screenDiv = screen
4544
screenDiv.style.whiteSpace = "pre"
46-
screenDiv.style.fontFamily = "Iosevka"
45+
screenDiv.style.fontFamily = "monospace"
4746
screenDiv.style.fontSize = "18px"
4847
screenDiv.style.lineHeight = "20px"
4948

@@ -61,11 +60,10 @@ class WebShell {
6160
this.serialDiv = serial
6261
}
6362

64-
if (this.restoreState) {
65-
this.config["initial_state"] = {
66-
url: bootedStatePath,
67-
}
63+
if (typeof paths.initial_state !== "undefined") {
64+
this.config["initial_state"] = {url: paths.initial_state}
6865
}
66+
console.log("constructor done")
6967
}
7068

7169
private appendToSerialDiv(_: string) {
@@ -205,6 +203,9 @@ class WebShell {
205203

206204
boot(): Promise<void> {
207205
return new Promise((resolve, _) => {
206+
console.log("booting")
207+
console.log(this.config)
208+
208209
// Start the this.emulator!
209210
//@ts-ignore
210211
this.emulator = new V86Starter(this.config)
@@ -248,4 +249,4 @@ class WebShell {
248249
}
249250
}
250251

251-
export default WebShell
252+
export default LinuxBrowserShell

v86/booted-state.bin.zst

-25.5 MB
Binary file not shown.

v86/image.iso.zst

-15.2 MB
Binary file not shown.

v86/seabios.bin

-128 KB
Binary file not shown.

v86/v86.wasm

-1.63 MB
Binary file not shown.

v86/vgabios.bin

-35 KB
Binary file not shown.

vite.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export default defineConfig({
77
build: {
88
lib: {
99
entry: resolve(__dirname, "src/index.ts"),
10-
name: "web-shell",
11-
fileName: "web-shell",
10+
name: "linux-browser-shell",
11+
fileName: "linux-browser-shell",
1212
},
13+
assetsInlineLimit: 0,
1314
},
1415
plugins: [
1516
legacy({

0 commit comments

Comments
 (0)