Fix handling of PTYs when renderer is reloaded (#4346)

Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Sebastian MaltonandJari Kolehmainen authored and GitHub committed 2021-11-17 13:48:46 -05:00
1 parent e146dff9da
commit 0f2801552f
6 files changed
+294 -176

No files matched your search

+11 -2
View File
@@ -22,7 +22,7 @@
import { autorun, observable, when } from "mobx";
import { autoBind, noop, Singleton } from "../../utils";
import { Terminal } from "./terminal";
import { TerminalApi } from "../../api/terminal-api";
import { TerminalApi, TerminalChannels } from "../../api/terminal-api";
import { dockStore, DockTab, DockTabCreateSpecific, TabId, TabKind } from "./dock.store";
import { WebSocketApiState } from "../../api/websocket-api";
import { Notifications } from "../notifications";
@@ -78,6 +78,8 @@ export class TerminalStore extends Singleton {
this.connections.set(tabId, api);
this.terminals.set(tabId, terminal);
api.connect();
}
disconnect(tabId: TabId) {
@@ -135,7 +137,14 @@ export class TerminalStore extends Singleton {
const terminalApi = this.connections.get(dockStore.selectedTabId);
if (terminalApi) {
terminalApi.sendCommand(command + (enter ? "\r" : ""));
if (enter) {
command += "\r";
}
terminalApi.sendMessage({
type: TerminalChannels.STDIN,
data: command,
});
} else {
console.warn("The selected tab is does not have a connection. Cannot send command.", { tabId: dockStore.selectedTabId, command });
}
+10 -5
View File
@@ -24,11 +24,11 @@ import { reaction } from "mobx";
import { Terminal as XTerm } from "xterm";
import { FitAddon } from "xterm-addon-fit";
import { dockStore, TabId } from "./dock.store";
import type { TerminalApi } from "../../api/terminal-api";
import { TerminalApi, TerminalChannels } from "../../api/terminal-api";
import { ThemeStore } from "../../theme.store";
import { boundMethod, disposer } from "../../utils";
import { isMac } from "../../../common/vars";
import { camelCase } from "lodash";
import { camelCase, once } from "lodash";
import { UserStore } from "../../../common/user-store";
import { clipboard } from "electron";
import logger from "../../../common/logger";
@@ -119,11 +119,13 @@ export class Terminal {
// bind events
const onDataHandler = this.xterm.onData(this.onData);
const clearOnce = once(this.onClear);
this.viewport.addEventListener("scroll", this.onScroll);
this.elem.addEventListener("contextmenu", this.onContextMenu);
this.api.onReady.addListener(this.onClear, { once: true }); // clear status logs (connecting..)
this.api.onData.addListener(this.onApiData);
this.api.once("ready", clearOnce);
this.api.once("connected", clearOnce);
this.api.on("data", this.onApiData);
window.addEventListener("resize", this.onResize);
this.disposer.push(
@@ -176,7 +178,10 @@ export class Terminal {
onData = (data: string) => {
if (!this.api.isReady) return;
this.api.sendCommand(data);
this.api.sendMessage({
type: TerminalChannels.STDIN,
data,
});
};
onScroll = () => {