From ab03b4153a9f796e3bd5a65d21dd74c41d614f70 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 15 Sep 2021 16:17:30 -0400 Subject: [PATCH] Only wait for the connection to be ready Signed-off-by: Sebastian Malton --- src/renderer/api/terminal-api.ts | 20 ------------------- .../components/dock/terminal.store.ts | 6 +++--- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/renderer/api/terminal-api.ts b/src/renderer/api/terminal-api.ts index b17637a800..59e248fba5 100644 --- a/src/renderer/api/terminal-api.ts +++ b/src/renderer/api/terminal-api.ts @@ -58,7 +58,6 @@ export class TerminalApi extends WebSocketApi { public onReady = new EventEmitter<[]>(); @observable public isReady = false; - @observable public shellRunCommandsFinished = false; public readonly url: string; constructor(protected options: TerminalApiQuery) { @@ -92,7 +91,6 @@ export class TerminalApi extends WebSocketApi { connect() { this.emitStatus("Connecting ..."); this.onData.addListener(this._onReady, { prepend: true }); - this.onData.addListener(this._onShellRunCommandsFinished); super.connect(this.url); } @@ -109,24 +107,6 @@ export class TerminalApi extends WebSocketApi { this.onReady.removeAllListeners(); } - _onShellRunCommandsFinished = (data: string) => { - if (!data) { - return; - } - - /** - * This is a heuistic for ditermining when a shell has finished executing - * its own rc file (or RunCommands file) such as `.bashrc` or `.zshrc`. - * - * This heuistic assumes that the prompt line of a terminal is a single line - * and ends with a whitespace character or the > character (windows's CMD). - */ - if (data.match(/\r?\n/) === null && data.match(/(\s|>)$/)) { - this.shellRunCommandsFinished = true; - this.onData.removeListener(this._onShellRunCommandsFinished); - } - }; - @boundMethod protected _onReady(data: string) { if (!data) return true; diff --git a/src/renderer/components/dock/terminal.store.ts b/src/renderer/components/dock/terminal.store.ts index d37dc8cc00..3a0811fbb3 100644 --- a/src/renderer/components/dock/terminal.store.ts +++ b/src/renderer/components/dock/terminal.store.ts @@ -117,9 +117,9 @@ export class TerminalStore extends Singleton { await when(() => this.connections.has(tab.id)); - const rcIsFinished = when(() => this.connections.get(tab.id).shellRunCommandsFinished); + const shellIsReady = when(() => this.connections.get(tab.id).isReady); const notifyVeryLong = setTimeout(() => { - rcIsFinished.cancel(); + shellIsReady.cancel(); Notifications.info( "If terminal shell is not ready please check your shell init files, if applicable. You may see this message if you have set a custom shell prompt.", { @@ -128,7 +128,7 @@ export class TerminalStore extends Singleton { ); }, 10_000); - await rcIsFinished.catch(noop); + await shellIsReady.catch(noop); clearTimeout(notifyVeryLong); }