Skip to content

Commit 4ddb437

Browse files
committed
Add downloadState method and show its use in the example
1 parent 5983318 commit 4ddb437

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

examples/simple/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
</head>
77
<body>
88
<div id="screen"></div>
9+
10+
<button id="save">Save state</button>
911
</body>
1012
</html>

examples/simple/script.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ const shell = new LinuxBrowserShell(
66
wasm: "./v86/v86.wasm",
77
bios: "./v86/seabios.bin",
88
vga_bios: "./v86/vgabios.bin",
9-
cdrom: "./v86/image.iso.zst",
9+
cdrom: "./v86/image.iso",
1010
initial_state: "./v86/initial-state.bin.zst",
1111
},
1212
screenDiv,
1313
)
1414
shell.boot()
15+
16+
document.getElementById("save").onclick = async function () {
17+
shell.downloadState()
18+
}

examples/simple/v86/image.iso

28.9 MB
Binary file not shown.

examples/simple/v86/image.iso.zst

-15.2 MB
Binary file not shown.
11.2 MB
Binary file not shown.

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ class LinuxBrowserShell {
247247
setKeyboardActive(active: boolean): void {
248248
this.emulator.keyboard_set_status(active)
249249
}
250+
251+
downloadState(filename: string = "linux-browser-shell-state.bin"): void {
252+
this.emulator.save_state().then((state: any) => {
253+
var a = document.createElement("a")
254+
a.download = filename
255+
a.href = window.URL.createObjectURL(new Blob([state]))
256+
a.dataset.downloadurl =
257+
"application/octet-stream:" + a.download + ":" + a.href
258+
a.click()
259+
})
260+
}
250261
}
251262

252263
export default LinuxBrowserShell

0 commit comments

Comments
 (0)