mirror of
https://github.com/coder/code-server.git
synced 2026-02-05 06:23:35 -06:00
* Make proxies decide how to handle disconnects * Connect to a new terminal instance on disconnect * Use our retry for the watcher * Specify method when proxy doesn't exist * Don't error when closing/killing disconnected proxy * Specify proxy ID when a method doesn't exist * Use our retry for the searcher Also dispose some things for the watcher because it doesn't seem that was done properly. The searcher also now starts immediately so there won't be lag when you perform your first search. * Use our retry for the extension host * Emit error in parent proxy class Reduces duplicate code. Not all items are "supposed" to have an error event according to the original implementation we are filling, but there is no reason why we can't emit our own events (and are already doing so for the "disconnected" event anyway). * Reconnect spdlog * Add error message when shared process disconnects * Pass method resolve to parse * Don't pass method to getProxy It doesn't tell you anything that trace logging wouldn't and has no relation to what the function actually does. * Fix infinite recursion when disposing protocol client in tests
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import * as pty from "node-pty";
|
|
import { ClientProxy } from "../../common/proxy";
|
|
import { NodePtyModuleProxy, NodePtyProcessProxy } from "../../node/modules/node-pty";
|
|
|
|
export class NodePtyProcess extends ClientProxy<NodePtyProcessProxy> implements pty.IPty {
|
|
private _pid = -1;
|
|
private _process = "";
|
|
|
|
public constructor(
|
|
private readonly moduleProxy: NodePtyModuleProxy,
|
|
private readonly file: string,
|
|
private readonly args: string[] | string,
|
|
private readonly options: pty.IPtyForkOptions,
|
|
) {
|
|
super(moduleProxy.spawn(file, args, options));
|
|
this.on("process", (process) => this._process = process);
|
|
}
|
|
|
|
protected initialize(proxyPromise: Promise<NodePtyProcessProxy>) {
|
|
super.initialize(proxyPromise);
|
|
this.proxy.getPid().then((pid) => this._pid = pid);
|
|
this.proxy.getProcess().then((process) => this._process = process);
|
|
}
|
|
|
|
public get pid(): number {
|
|
return this._pid;
|
|
}
|
|
|
|
public get process(): string {
|
|
return this._process;
|
|
}
|
|
|
|
public resize(columns: number, rows: number): void {
|
|
this.proxy.resize(columns, rows);
|
|
}
|
|
|
|
public write(data: string): void {
|
|
this.proxy.write(data);
|
|
}
|
|
|
|
public kill(signal?: string): void {
|
|
this.proxy.kill(signal);
|
|
}
|
|
|
|
protected handleDisconnect(): void {
|
|
this._process += " (disconnected)";
|
|
this.emit("data", "\r\n\nLost connection...\r\n\n");
|
|
this.initialize(this.moduleProxy.spawn(this.file, this.args, this.options));
|
|
}
|
|
}
|
|
|
|
type NodePty = typeof pty;
|
|
|
|
export class NodePtyModule implements NodePty {
|
|
public constructor(private readonly proxy: NodePtyModuleProxy) {}
|
|
|
|
public spawn = (file: string, args: string[] | string, options: pty.IPtyForkOptions): pty.IPty => {
|
|
return new NodePtyProcess(this.proxy, file, args, options);
|
|
}
|
|
}
|