Skip to content

Commit 268c6ee

Browse files
committed
send background commands
1 parent 058e250 commit 268c6ee

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

packages/runtime/index.html

+16-19
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,27 @@
5656

5757
var emulator = new V86Starter(options);
5858

59+
function initTerm() {
60+
const fitAddon = new FitAddon.FitAddon();
61+
emulator.serial_adapter.term.loadAddon(fitAddon);
62+
fitAddon.fit();
63+
window.addEventListener("resize", () => fitAddon.fit());
64+
}
65+
66+
function sendBackgroundCommands(commands) {
67+
const filename = `${(Math.random() + 1).toString(36).substring(7)}.sh`
68+
emulator.create_file(`/inbox/${filename}`, (new TextEncoder('UTF-8')).encode(commands.join("\n")));
69+
}
70+
5971
if (!boot) {
6072
emulator.add_listener("emulator-ready", function () {
61-
const fitAddon = new FitAddon.FitAddon();
62-
emulator.serial_adapter.term.loadAddon(fitAddon);
63-
fitAddon.fit();
64-
window.addEventListener("resize", () => fitAddon.fit());
65-
// emulator.serial_adapter.term.setOption("allowTransparency", true);
66-
// emulator.serial_adapter.term.setOption("theme", { background: "transparent" });
73+
initTerm();
6774
setTimeout(() => {
68-
emulator.serial0_send('/etc/init.d/S40network restart\n');
69-
emulator.serial0_send('psql -U postgres\n');
70-
emulator.serial0_send('\\! echo "boot_completed"; reset\n');
75+
sendBackgroundCommands(["/etc/init.d/S40network restart"]);
76+
emulator.serial0_send('\\! reset\n');
77+
emulator.serial_adapter.term.focus();
7178
}, 0);
7279
});
73-
74-
function handleBoot(line) {
75-
if (line.startsWith("postgres=# boot_completed")) {
76-
emulator.remove_listener(handleBoot);
77-
setTimeout(() => {
78-
emulator.serial_adapter.term.focus();
79-
}, 300);
80-
}
81-
}
82-
emulator.add_listener("serial0-output-line", handleBoot);
8380
}
8481

8582
var state;

0 commit comments

Comments
 (0)