diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 7a04b599..d1042fe1 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -83,21 +83,18 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent { - if (this.frontend) { - // Session was closed abruptly - this.write('\r\n' + colors.black.bgWhite(' SERIAL ') + ` session closed\r\n`) - - if (this.profile.behaviorOnSessionEnd === 'reconnect') { - this.reconnect() - } else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) { - this.offerReconnection() - } - } - }) super.attachSessionHandlers() } + protected onSessionDestroyed() { + if (this.frontend) { + // Session was closed abruptly + this.write('\r\n' + colors.black.bgWhite(' SERIAL ') + ` session closed\r\n`) + + super.onSessionDestroyed() + } + } + async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise { return { type: 'app:serial-tab', diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index eae39e4e..dcd7c8cd 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -148,21 +148,13 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent return session } - protected attachSessionHandlers (): void { - const session = this.session! - this.attachSessionHandler(session.destroyed$, () => { - if (this.frontend) { - // Session was closed abruptly - this.write('\r\n' + colors.black.bgWhite(' SSH ') + ` ${this.sshSession?.profile.options.host}: session closed\r\n`) + protected onSessionDestroyed() { + if (this.frontend) { + // Session was closed abruptly + this.write('\r\n' + colors.black.bgWhite(' SSH ') + ` ${this.sshSession?.profile.options.host}: session closed\r\n`) - if (this.profile.behaviorOnSessionEnd === 'reconnect') { - this.reconnect() - } else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) { - this.offerReconnection() - } - } - }) - super.attachSessionHandlers() + super.onSessionDestroyed() + } } private async initializeSessionMaybeMultiplex (multiplex = true): Promise { diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index cfa6f7f0..767cea97 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -42,21 +42,13 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent { - if (this.frontend) { - // Session was closed abruptly - this.write('\r\n' + colors.black.bgWhite(' TELNET ') + ` ${this.session?.profile.options.host}: session closed\r\n`) + protected onSessionDestroyed() { + if (this.frontend) { + // Session was closed abruptly + this.write('\r\n' + colors.black.bgWhite(' TELNET ') + ` ${this.session?.profile.options.host}: session closed\r\n`) - if (this.profile.behaviorOnSessionEnd === 'reconnect') { - this.reconnect() - } else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) { - this.offerReconnection() - } - } - }) - super.attachSessionHandlers() + super.onSessionDestroyed() + } } async initializeSession (): Promise { diff --git a/tabby-terminal/src/api/baseTerminalTab.component.ts b/tabby-terminal/src/api/baseTerminalTab.component.ts index dcea967d..1a0cfd74 100644 --- a/tabby-terminal/src/api/baseTerminalTab.component.ts +++ b/tabby-terminal/src/api/baseTerminalTab.component.ts @@ -784,7 +784,7 @@ export class BaseTerminalTabComponent

extends Bas }) this.attachSessionHandler(this.session.destroyed$, () => { - this.setSession(null) + this.onSessionDestroyed() }) this.attachSessionHandler(this.session.oscProcessor.copyRequested$, content => { @@ -793,6 +793,13 @@ export class BaseTerminalTabComponent

extends Bas }) } + /** + * Method called when session is destroyed. Set the session to null + */ + protected onSessionDestroyed() { + this.setSession(null) + } + protected detachSessionHandlers (): void { this.sessionHandlers.cancelAll() } diff --git a/tabby-terminal/src/api/connectableTerminalTab.component.ts b/tabby-terminal/src/api/connectableTerminalTab.component.ts index cb8f6fd1..7309929e 100644 --- a/tabby-terminal/src/api/connectableTerminalTab.component.ts +++ b/tabby-terminal/src/api/connectableTerminalTab.component.ts @@ -32,6 +32,21 @@ export abstract class ConnectableTerminalTabComponent

{ this.reconnectOffered = false } + + /** + * Method called when session is destroyed. Handle the tab behavior on session end for connectable tab + */ + protected onSessionDestroyed() { + super.onSessionDestroyed() + + if (this.frontend) { + if (this.profile.behaviorOnSessionEnd === 'reconnect') { + this.reconnect() + } else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) { + this.offerReconnection() + } + } + } /** * Offering reconnection to the user if it hasn't been done yet.