|
1 | 1 | import { EventEmitter, Injectable, Output } from '@angular/core';
|
2 | 2 | import type {
|
| 3 | + MsgResizePort, |
3 | 4 | MsgSendPort,
|
4 | 5 | WorkerMsgWithoutCID,
|
5 | 6 | WorkerResponseMsg,
|
6 | 7 | } from './emulator.worker';
|
7 | 8 | import { environment } from '../environments/environment';
|
8 | 9 | import { Port, vmRemoteUrlSearchParameter } from '../utils/literalConstants';
|
9 | 10 |
|
| 11 | +export interface TerminalDimensions { |
| 12 | + rows: number; |
| 13 | + cols: number; |
| 14 | +} |
| 15 | + |
10 | 16 | const encoder = new TextEncoder();
|
11 | 17 |
|
12 | 18 | @Injectable({
|
13 | 19 | providedIn: 'root',
|
14 | 20 | })
|
15 | 21 | export class EmulatorService {
|
16 | 22 | @Output()
|
17 |
| - public resetOutputConsole = new EventEmitter<void>(); |
| 23 | + public readonly resetOutputConsole = new EventEmitter<void>(); |
18 | 24 | @Output()
|
19 |
| - public receivedOutput = new EventEmitter<[Port, string]>(); |
| 25 | + public readonly receivedOutput = new EventEmitter<[Port, string]>(); |
| 26 | + |
| 27 | + private readonly worker; |
| 28 | + |
| 29 | + private readonly asyncCallbacks = new Map<number, Function>(); |
20 | 30 |
|
21 |
| - private worker; |
| 31 | + public resolveSystemBooted!: Function; |
| 32 | + public readonly systemBooted = new Promise<void>( |
| 33 | + (resolve) => (this.resolveSystemBooted = resolve), |
| 34 | + ); |
22 | 35 |
|
23 |
| - private asyncCallbacks = new Map<number, Function>(); |
| 36 | + private readonly savedDimensions = new Map<Port, TerminalDimensions>(); |
24 | 37 |
|
25 | 38 | constructor() {
|
| 39 | + this.systemBooted.then(() => { |
| 40 | + for (const [port, dims] of this.savedDimensions) { |
| 41 | + this.resizePort(port, dims); |
| 42 | + } |
| 43 | + }); |
| 44 | + |
26 | 45 | interface FakeWorker {
|
27 | 46 | new (url: URL): Worker;
|
28 | 47 | }
|
@@ -73,11 +92,16 @@ export class EmulatorService {
|
73 | 92 | public sendPort(...data: MsgSendPort['data']) {
|
74 | 93 | this.sendCommand({ command: 'sendPort', data });
|
75 | 94 | }
|
| 95 | + public resizePort(...data: MsgResizePort['data']) { |
| 96 | + this.savedDimensions.set(data[0], data[1]); |
| 97 | + this.sendCommand({ command: 'resizePort', data }); |
| 98 | + } |
76 | 99 | public pause() {
|
77 | 100 | return this.sendCommandAsync({ command: 'pause' });
|
78 | 101 | }
|
79 | 102 | public start() {
|
80 |
| - return this.sendCommandAsync({ command: 'start' }); |
| 103 | + this.sendCommand({ command: 'start' }); |
| 104 | + return this.systemBooted; |
81 | 105 | }
|
82 | 106 | public sendFile(name: string, content: Uint8Array | string) {
|
83 | 107 | if (typeof content === 'string') content = encoder.encode(content);
|
|
0 commit comments