|
56 | 56 |
|
57 | 57 | var emulator = new V86Starter(options);
|
58 | 58 |
|
| 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 | + |
59 | 71 | if (!boot) {
|
60 | 72 | 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(); |
67 | 74 | 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(); |
71 | 78 | }, 0);
|
72 | 79 | });
|
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); |
83 | 80 | }
|
84 | 81 |
|
85 | 82 | var state;
|
|
0 commit comments