From fd9505c18f0e4917beb8aad463890f2ca72f0d34 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Thu, 11 May 2023 21:17:12 +0200 Subject: [PATCH 01/11] ref(tabby-terminal): make Reconnectable interface deprecated --- tabby-terminal/src/api/interfaces.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tabby-terminal/src/api/interfaces.ts b/tabby-terminal/src/api/interfaces.ts index 8e7d54c3..b9052dc7 100644 --- a/tabby-terminal/src/api/interfaces.ts +++ b/tabby-terminal/src/api/interfaces.ts @@ -20,10 +20,19 @@ export interface BaseTerminalProfile extends Profile { terminalColorScheme?: TerminalColorScheme } + +/** + * Use ConnectableTerminalTab instead + * @deprecated + */ export interface Reconnectable { reconnect: () => Promise; } +/** + * Use ConnectableTerminalTab instead + * @deprecated + */ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function isReconnectable (object: any): object is Reconnectable { return 'reconnect' in object From 901181f6810223da8dbd8ca145dc77247e34e791 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Thu, 11 May 2023 21:49:32 +0200 Subject: [PATCH 02/11] ref(tabby-terminal): create ConnectableTerminalTabComponent class --- .../src/components/serialTab.component.ts | 4 +-- tabby-ssh/src/components/sshTab.component.ts | 5 ++-- .../src/components/telnetTab.component.ts | 5 ++-- .../api/connectableTerminalTab.component.ts | 26 +++++++++++++++++++ tabby-terminal/src/index.ts | 1 + 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 tabby-terminal/src/api/connectableTerminalTab.component.ts diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 3e332f81..cc11189b 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -4,7 +4,7 @@ import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, SelectorService } from 'tabby-core' -import { BaseTerminalTabComponent, Reconnectable } from 'tabby-terminal' +import { BaseTerminalTabComponent, ConnectableTerminalTabComponent, Reconnectable } from 'tabby-terminal' import { SerialSession, BAUD_RATES, SerialProfile } from '../api' /** @hidden */ @@ -14,7 +14,7 @@ import { SerialSession, BAUD_RATES, SerialProfile } from '../api' styleUrls: ['./serialTab.component.scss', ...BaseTerminalTabComponent.styles], animations: BaseTerminalTabComponent.animations, }) -export class SerialTabComponent extends BaseTerminalTabComponent implements Reconnectable { +export class SerialTabComponent extends ConnectableTerminalTabComponent implements Reconnectable { session: SerialSession|null = null Platform = Platform diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 97bc2da5..a5be1bc2 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -4,7 +4,7 @@ import { Component, Injector, HostListener } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, ProfilesService, RecoveryToken } from 'tabby-core' -import { BaseTerminalTabComponent, Reconnectable } from 'tabby-terminal' +import { BaseTerminalTabComponent, ConnectableTerminalTabComponent, Reconnectable } from 'tabby-terminal' import { SSHService } from '../services/ssh.service' import { KeyboardInteractivePrompt, SSHSession } from '../session/ssh' import { SSHPortForwardingModalComponent } from './sshPortForwardingModal.component' @@ -22,7 +22,7 @@ import { SSHMultiplexerService } from '../services/sshMultiplexer.service' ], animations: BaseTerminalTabComponent.animations, }) -export class SSHTabComponent extends BaseTerminalTabComponent implements Reconnectable { +export class SSHTabComponent extends ConnectableTerminalTabComponent implements Reconnectable { Platform = Platform sshSession: SSHSession|null = null session: SSHShellSession|null = null @@ -30,7 +30,6 @@ export class SSHTabComponent extends BaseTerminalTabComponent implem sftpPath = '/' enableToolbar = true activeKIPrompt: KeyboardInteractivePrompt|null = null - private reconnectOffered = false constructor ( injector: Injector, diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index d3ae2cf4..1cced0dd 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -3,7 +3,7 @@ import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, RecoveryToken } from 'tabby-core' -import { BaseTerminalTabComponent, Reconnectable } from 'tabby-terminal' +import { BaseTerminalTabComponent, ConnectableTerminalTabComponent, Reconnectable } from 'tabby-terminal' import { TelnetProfile, TelnetSession } from '../session' @@ -14,10 +14,9 @@ import { TelnetProfile, TelnetSession } from '../session' styleUrls: ['./telnetTab.component.scss', ...BaseTerminalTabComponent.styles], animations: BaseTerminalTabComponent.animations, }) -export class TelnetTabComponent extends BaseTerminalTabComponent implements Reconnectable { +export class TelnetTabComponent extends ConnectableTerminalTabComponent implements Reconnectable { Platform = Platform session: TelnetSession|null = null - private reconnectOffered = false // eslint-disable-next-line @typescript-eslint/no-useless-constructor constructor ( diff --git a/tabby-terminal/src/api/connectableTerminalTab.component.ts b/tabby-terminal/src/api/connectableTerminalTab.component.ts new file mode 100644 index 00000000..6eacb3f8 --- /dev/null +++ b/tabby-terminal/src/api/connectableTerminalTab.component.ts @@ -0,0 +1,26 @@ +import { Injector, Component } from '@angular/core' + +import { BaseTerminalProfile } from './interfaces' +import { BaseTerminalTabComponent } from './baseTerminalTab.component' + +/** + * A class to base your custom connectable terminal tabs on + */ +@Component({ template: '' }) +export abstract class ConnectableTerminalTabComponent

extends BaseTerminalTabComponent

{ + + protected reconnectOffered = false + + constructor (protected injector: Injector) { + super(injector) + } + + abstract initializeSession (): Promise + + async reconnect (): Promise { + this.session?.destroy() + await this.initializeSession() + this.session?.releaseInitialDataBuffer() + } + +} diff --git a/tabby-terminal/src/index.ts b/tabby-terminal/src/index.ts index f41b5007..9c00c0ef 100644 --- a/tabby-terminal/src/index.ts +++ b/tabby-terminal/src/index.ts @@ -90,6 +90,7 @@ export default class TerminalModule { } // eslint-disable-line @typescript-eslin export { TerminalDecorator, TerminalContextMenuItemProvider, TerminalColorSchemeProvider } export { Frontend, XTermFrontend, XTermWebGLFrontend } export { BaseTerminalTabComponent } from './api/baseTerminalTab.component' +export { ConnectableTerminalTabComponent } from './api/connectableTerminalTab.component' export * from './api/interfaces' export * from './middleware/streamProcessing' export * from './middleware/loginScriptProcessing' From 1e6f6af5ed766ba24f63f021239e409683ee406c Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Fri, 12 May 2023 19:09:33 +0200 Subject: [PATCH 03/11] ref(connectable tab) reconnect context menu & hotkey --- .../src/components/serialTab.component.ts | 12 ++----- tabby-ssh/src/components/sshTab.component.ts | 17 +++------- .../src/components/telnetTab.component.ts | 17 +++------- .../api/connectableTerminalTab.component.ts | 34 ++++++++++++++++++- tabby-terminal/src/tabContextMenu.ts | 3 +- 5 files changed, 46 insertions(+), 37 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index cc11189b..47e90815 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -2,9 +2,8 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' -import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, SelectorService } from 'tabby-core' -import { BaseTerminalTabComponent, ConnectableTerminalTabComponent, Reconnectable } from 'tabby-terminal' +import { BaseTerminalTabComponent, ConnectableTerminalTabComponent } from 'tabby-terminal' import { SerialSession, BAUD_RATES, SerialProfile } from '../api' /** @hidden */ @@ -14,7 +13,7 @@ import { SerialSession, BAUD_RATES, SerialProfile } from '../api' styleUrls: ['./serialTab.component.scss', ...BaseTerminalTabComponent.styles], animations: BaseTerminalTabComponent.animations, }) -export class SerialTabComponent extends ConnectableTerminalTabComponent implements Reconnectable { +export class SerialTabComponent extends ConnectableTerminalTabComponent { session: SerialSession|null = null Platform = Platform @@ -90,12 +89,7 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent { - if (!this.session?.open) { - this.reconnect() - } - }) + this.offerReconnection() } } }) diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index a5be1bc2..f024ce8c 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -2,9 +2,8 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import colors from 'ansi-colors' import { Component, Injector, HostListener } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, ProfilesService, RecoveryToken } from 'tabby-core' -import { BaseTerminalTabComponent, ConnectableTerminalTabComponent, Reconnectable } from 'tabby-terminal' +import { BaseTerminalTabComponent, ConnectableTerminalTabComponent } from 'tabby-terminal' import { SSHService } from '../services/ssh.service' import { KeyboardInteractivePrompt, SSHSession } from '../session/ssh' import { SSHPortForwardingModalComponent } from './sshPortForwardingModal.component' @@ -22,7 +21,7 @@ import { SSHMultiplexerService } from '../services/sshMultiplexer.service' ], animations: BaseTerminalTabComponent.animations, }) -export class SSHTabComponent extends ConnectableTerminalTabComponent implements Reconnectable { +export class SSHTabComponent extends ConnectableTerminalTabComponent { Platform = Platform sshSession: SSHSession|null = null session: SSHShellSession|null = null @@ -159,15 +158,7 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent if (this.profile.behaviorOnSessionEnd === 'reconnect') { this.reconnect() } else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) { - if (!this.reconnectOffered) { - this.reconnectOffered = true - this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n') - this.input$.pipe(first()).subscribe(() => { - if (!this.session?.open && this.reconnectOffered) { - this.reconnect() - } - }) - } + this.offerReconnection() } } }) @@ -195,7 +186,7 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent } async initializeSession (): Promise { - this.reconnectOffered = false + await super.initializeSession() try { await this.initializeSessionMaybeMultiplex(true) } catch { diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 1cced0dd..3b589ccd 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -1,9 +1,8 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' -import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, RecoveryToken } from 'tabby-core' -import { BaseTerminalTabComponent, ConnectableTerminalTabComponent, Reconnectable } from 'tabby-terminal' +import { BaseTerminalTabComponent, ConnectableTerminalTabComponent } from 'tabby-terminal' import { TelnetProfile, TelnetSession } from '../session' @@ -14,7 +13,7 @@ import { TelnetProfile, TelnetSession } from '../session' styleUrls: ['./telnetTab.component.scss', ...BaseTerminalTabComponent.styles], animations: BaseTerminalTabComponent.animations, }) -export class TelnetTabComponent extends ConnectableTerminalTabComponent implements Reconnectable { +export class TelnetTabComponent extends ConnectableTerminalTabComponent { Platform = Platform session: TelnetSession|null = null @@ -53,15 +52,7 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent { - if (!this.session?.open && this.reconnectOffered) { - this.reconnect() - } - }) - } + this.offerReconnection() } } }) @@ -69,7 +60,7 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent { - this.reconnectOffered = false + await super.initializeSession() const session = new TelnetSession(this.injector, this.profile) this.setSession(session) diff --git a/tabby-terminal/src/api/connectableTerminalTab.component.ts b/tabby-terminal/src/api/connectableTerminalTab.component.ts index 6eacb3f8..cb8f6fd1 100644 --- a/tabby-terminal/src/api/connectableTerminalTab.component.ts +++ b/tabby-terminal/src/api/connectableTerminalTab.component.ts @@ -1,5 +1,9 @@ +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' + import { Injector, Component } from '@angular/core' +import { first } from 'rxjs' + import { BaseTerminalProfile } from './interfaces' import { BaseTerminalTabComponent } from './baseTerminalTab.component' @@ -13,9 +17,37 @@ export abstract class ConnectableTerminalTabComponent

{ + if (this.hasFocus && hotkey === 'reconnect-tab') { + this.reconnect() + } + }) } - abstract initializeSession (): Promise + /** + * Initialize Connectable Session. + * Set reconnectOffered to false + */ + async initializeSession (): Promise { + this.reconnectOffered = false + } + + /** + * Offering reconnection to the user if it hasn't been done yet. + * Set reconnectOffered to true + */ + offerReconnection () { + if (!this.reconnectOffered) { + this.reconnectOffered = true + this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n') + this.input$.pipe(first()).subscribe(() => { + if (!this.session?.open && this.reconnectOffered) { + this.reconnect() + } + }) + } + } async reconnect (): Promise { this.session?.destroy() diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index 962c12e4..f44eec1f 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -4,6 +4,7 @@ import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' import { isReconnectable } from './api/interfaces' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' +import { ConnectableTerminalTabComponent } from './api/connectableTerminalTab.component' /** @hidden */ @Injectable() @@ -97,7 +98,7 @@ export class ReconnectContextMenu extends TabContextMenuItemProvider { ) { super() } async getItems (tab: BaseTabComponent): Promise { - if (isReconnectable(tab)) { + if (isReconnectable(tab) || tab instanceof ConnectableTerminalTabComponent) { return [ { label: this.translate.instant('Reconnect'), From 2b5976f20253c02f5042e4d5ca9cf33c25ff8e75 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Fri, 12 May 2023 19:30:24 +0200 Subject: [PATCH 04/11] =?UTF-8?q?ref(connectable=20tab)=20reconnect=20cont?= =?UTF-8?q?ext=20menu=20&=20hotkey=20n=C2=B02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tabby-serial/src/components/serialTab.component.ts | 8 ++------ tabby-ssh/src/components/sshTab.component.ts | 6 ------ tabby-telnet/src/components/telnetTab.component.ts | 6 ------ 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 47e90815..7a04b599 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -59,6 +59,8 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent { - this.session?.destroy() - await this.initializeSession() - this.session?.releaseInitialDataBuffer() - } - async changeBaudRate () { const rate = await this.selector.show( this.translate.instant(_('Baud rate')), diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index f024ce8c..eae39e4e 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -212,12 +212,6 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent modal.session = this.sshSession! } - async reconnect (): Promise { - this.session?.destroy() - await this.initializeSession() - this.session?.releaseInitialDataBuffer() - } - async canClose (): Promise { if (!this.session?.open) { return true diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 3b589ccd..cfa6f7f0 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -94,12 +94,6 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent { - this.session?.destroy() - await this.initializeSession() - this.session?.releaseInitialDataBuffer() - } - async canClose (): Promise { if (!this.session?.open) { return true From 312b3658512dd8af700b8deff2cc9623a7ff3003 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Fri, 12 May 2023 19:39:44 +0200 Subject: [PATCH 05/11] ref(connectable tab) on session destroyed --- .../src/components/serialTab.component.ts | 21 ++++++++----------- tabby-ssh/src/components/sshTab.component.ts | 20 ++++++------------ .../src/components/telnetTab.component.ts | 20 ++++++------------ .../src/api/baseTerminalTab.component.ts | 9 +++++++- .../api/connectableTerminalTab.component.ts | 15 +++++++++++++ 5 files changed, 44 insertions(+), 41 deletions(-) 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. From 38302622b8e834236620caa9dbc01aba370976b7 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Fri, 12 May 2023 19:46:43 +0200 Subject: [PATCH 06/11] lint --- tabby-serial/src/components/serialTab.component.ts | 2 +- tabby-ssh/src/components/sshTab.component.ts | 2 +- tabby-telnet/src/components/telnetTab.component.ts | 2 +- tabby-terminal/src/api/baseTerminalTab.component.ts | 4 ++-- .../src/api/connectableTerminalTab.component.ts | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index d1042fe1..acac9b4a 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -86,7 +86,7 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent return session } - protected onSessionDestroyed() { + protected onSessionDestroyed (): void { if (this.frontend) { // Session was closed abruptly this.write('\r\n' + colors.black.bgWhite(' SSH ') + ` ${this.sshSession?.profile.options.host}: session closed\r\n`) diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 767cea97..e1af86ff 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -42,7 +42,7 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent extends Bas }) this.attachSessionHandler(this.session.destroyed$, () => { - this.onSessionDestroyed() + this.onSessionDestroyed() }) this.attachSessionHandler(this.session.oscProcessor.copyRequested$, content => { @@ -796,7 +796,7 @@ export class BaseTerminalTabComponent

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

{ @@ -36,7 +36,7 @@ export abstract class ConnectableTerminalTabComponent

Date: Fri, 12 May 2023 20:01:06 +0200 Subject: [PATCH 07/11] ref(connectable tab) on frontend ready --- tabby-serial/src/components/serialTab.component.ts | 5 ----- tabby-ssh/src/components/sshTab.component.ts | 5 ----- tabby-telnet/src/components/telnetTab.component.ts | 5 ----- tabby-terminal/src/api/connectableTerminalTab.component.ts | 5 +++++ 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index acac9b4a..7ae355a3 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -53,11 +53,6 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent super.ngOnInit() } - protected onFrontendReady (): void { - this.initializeSession() - super.onFrontendReady() - } - async setupOneSession (injector: Injector, profile: SSHProfile, multiplex = true): Promise { let session = await this.sshMultiplexer.getSession(profile) if (!multiplex || !session || !profile.options.reuseSession) { diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index e1af86ff..38bf5782 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -37,11 +37,6 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent Date: Fri, 12 May 2023 20:06:40 +0200 Subject: [PATCH 08/11] ref(connectable tab) getRecoveryToken method --- tabby-serial/src/components/serialTab.component.ts | 8 -------- tabby-ssh/src/components/sshTab.component.ts | 8 -------- tabby-telnet/src/components/telnetTab.component.ts | 8 -------- .../src/api/connectableTerminalTab.component.ts | 10 ++++++++++ 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 7ae355a3..ff1e3651 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -90,14 +90,6 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent { - return { - type: 'app:serial-tab', - profile: this.profile, - savedState: options?.includeState && this.frontend?.saveState(), - } - } - async changeBaudRate () { const rate = await this.selector.show( this.translate.instant(_('Baud rate')), diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 21b14e89..8afa4810 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -186,14 +186,6 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent } } - async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise { - return { - type: 'app:ssh-tab', - profile: this.profile, - savedState: options?.includeState && this.frontend?.saveState(), - } - } - showPortForwarding (): void { const modal = this.ngbModal.open(SSHPortForwardingModalComponent).componentInstance as SSHPortForwardingModalComponent modal.session = this.sshSession! diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 38bf5782..1b9a2963 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -73,14 +73,6 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent { - return { - type: 'app:telnet-tab', - profile: this.profile, - savedState: options?.includeState && this.frontend?.saveState(), - } - } - async canClose (): Promise { if (!this.session?.open) { return true diff --git a/tabby-terminal/src/api/connectableTerminalTab.component.ts b/tabby-terminal/src/api/connectableTerminalTab.component.ts index 36944a3d..595e27cb 100644 --- a/tabby-terminal/src/api/connectableTerminalTab.component.ts +++ b/tabby-terminal/src/api/connectableTerminalTab.component.ts @@ -6,6 +6,8 @@ import { first } from 'rxjs' import { BaseTerminalProfile } from './interfaces' import { BaseTerminalTabComponent } from './baseTerminalTab.component' +import { GetRecoveryTokenOptions } from 'tabby-core' + /** * A class to base your custom connectable terminal tabs on @@ -69,6 +71,14 @@ export abstract class ConnectableTerminalTabComponent

{ + return { + type: `app:${this.profile.type}-tab`, + profile: this.profile, + savedState: options?.includeState && this.frontend?.saveState(), + } + } + async reconnect (): Promise { this.session?.destroy() await this.initializeSession() From 37226f66e38e28548408be739a72c48e091f5d15 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Fri, 12 May 2023 20:27:58 +0200 Subject: [PATCH 09/11] ref(connectable tab) ngOnInit logger --- tabby-serial/src/components/serialTab.component.ts | 2 -- tabby-ssh/src/components/sshTab.component.ts | 2 -- tabby-telnet/src/components/telnetTab.component.ts | 2 -- tabby-terminal/src/api/connectableTerminalTab.component.ts | 6 ++++++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index ff1e3651..fcf54edf 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -27,8 +27,6 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent { if (!this.hasFocus) { return diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 8afa4810..3bfc779a 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -44,8 +44,6 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent } ngOnInit (): void { - this.logger = this.log.create('terminalTab') - this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => { if (!this.hasFocus) { return diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 1b9a2963..60ae6c25 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -26,8 +26,6 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent { if (this.hasFocus && hotkey === 'restart-telnet-session') { this.reconnect() diff --git a/tabby-terminal/src/api/connectableTerminalTab.component.ts b/tabby-terminal/src/api/connectableTerminalTab.component.ts index 595e27cb..c800040e 100644 --- a/tabby-terminal/src/api/connectableTerminalTab.component.ts +++ b/tabby-terminal/src/api/connectableTerminalTab.component.ts @@ -27,6 +27,12 @@ export abstract class ConnectableTerminalTabComponent

Date: Fri, 12 May 2023 20:32:58 +0200 Subject: [PATCH 10/11] ref(connectable tab) unused import --- tabby-serial/src/components/serialTab.component.ts | 2 +- tabby-ssh/src/components/sshTab.component.ts | 2 +- tabby-telnet/src/components/telnetTab.component.ts | 2 +- tabby-terminal/src/api/connectableTerminalTab.component.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index fcf54edf..7ff0afb1 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -2,7 +2,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' -import { GetRecoveryTokenOptions, Platform, SelectorService } from 'tabby-core' +import { Platform, SelectorService } from 'tabby-core' import { BaseTerminalTabComponent, ConnectableTerminalTabComponent } from 'tabby-terminal' import { SerialSession, BAUD_RATES, SerialProfile } from '../api' diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 3bfc779a..b6c6d3eb 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -2,7 +2,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import colors from 'ansi-colors' import { Component, Injector, HostListener } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { GetRecoveryTokenOptions, Platform, ProfilesService, RecoveryToken } from 'tabby-core' +import { Platform, ProfilesService } from 'tabby-core' import { BaseTerminalTabComponent, ConnectableTerminalTabComponent } from 'tabby-terminal' import { SSHService } from '../services/ssh.service' import { KeyboardInteractivePrompt, SSHSession } from '../session/ssh' diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 60ae6c25..3b785bd5 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -1,7 +1,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' -import { GetRecoveryTokenOptions, Platform, RecoveryToken } from 'tabby-core' +import { Platform } from 'tabby-core' import { BaseTerminalTabComponent, ConnectableTerminalTabComponent } from 'tabby-terminal' import { TelnetProfile, TelnetSession } from '../session' diff --git a/tabby-terminal/src/api/connectableTerminalTab.component.ts b/tabby-terminal/src/api/connectableTerminalTab.component.ts index c800040e..0d63ff2d 100644 --- a/tabby-terminal/src/api/connectableTerminalTab.component.ts +++ b/tabby-terminal/src/api/connectableTerminalTab.component.ts @@ -6,7 +6,7 @@ import { first } from 'rxjs' import { BaseTerminalProfile } from './interfaces' import { BaseTerminalTabComponent } from './baseTerminalTab.component' -import { GetRecoveryTokenOptions } from 'tabby-core' +import { GetRecoveryTokenOptions, RecoveryToken } from 'tabby-core' /** @@ -77,7 +77,7 @@ export abstract class ConnectableTerminalTabComponent

{ + async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise { return { type: `app:${this.profile.type}-tab`, profile: this.profile, From 539ad0bddc070a8d2ef6a576d86b1f9ea7433766 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Tue, 16 May 2023 19:13:00 +0200 Subject: [PATCH 11/11] ref(tabby-terminal): remove deprecated Reconnectable interface --- .../src/api/baseTerminalTab.component.ts | 7 +------ tabby-terminal/src/api/interfaces.ts | 18 ------------------ tabby-terminal/src/tabContextMenu.ts | 3 +-- 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/tabby-terminal/src/api/baseTerminalTab.component.ts b/tabby-terminal/src/api/baseTerminalTab.component.ts index 107c617c..a5285293 100644 --- a/tabby-terminal/src/api/baseTerminalTab.component.ts +++ b/tabby-terminal/src/api/baseTerminalTab.component.ts @@ -9,7 +9,7 @@ import { BaseSession } from '../session' import { Frontend } from '../frontends/frontend' import { XTermFrontend, XTermWebGLFrontend } from '../frontends/xtermFrontend' -import { ResizeEvent, BaseTerminalProfile, isReconnectable } from './interfaces' +import { ResizeEvent, BaseTerminalProfile } from './interfaces' import { TerminalDecorator } from './decorator' import { SearchPanelComponent } from '../components/searchPanel.component' import { MultifocusService } from '../services/multifocus.service' @@ -312,11 +312,6 @@ export class BaseTerminalTabComponent

extends Bas case 'scroll-to-bottom': this.frontend?.scrollToBottom() break - case 'reconnect-tab': - if (isReconnectable(this)) { - this.reconnect() - } - break } }) diff --git a/tabby-terminal/src/api/interfaces.ts b/tabby-terminal/src/api/interfaces.ts index b9052dc7..74143339 100644 --- a/tabby-terminal/src/api/interfaces.ts +++ b/tabby-terminal/src/api/interfaces.ts @@ -19,21 +19,3 @@ export interface TerminalColorScheme { export interface BaseTerminalProfile extends Profile { terminalColorScheme?: TerminalColorScheme } - - -/** - * Use ConnectableTerminalTab instead - * @deprecated - */ -export interface Reconnectable { - reconnect: () => Promise; -} - -/** - * Use ConnectableTerminalTab instead - * @deprecated - */ -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export function isReconnectable (object: any): object is Reconnectable { - return 'reconnect' in object -} diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index f44eec1f..5d485022 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,7 +1,6 @@ import { Injectable, Optional, Inject } from '@angular/core' import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' -import { isReconnectable } from './api/interfaces' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' import { ConnectableTerminalTabComponent } from './api/connectableTerminalTab.component' @@ -98,7 +97,7 @@ export class ReconnectContextMenu extends TabContextMenuItemProvider { ) { super() } async getItems (tab: BaseTabComponent): Promise { - if (isReconnectable(tab) || tab instanceof ConnectableTerminalTabComponent) { + if (tab instanceof ConnectableTerminalTabComponent) { return [ { label: this.translate.instant('Reconnect'),