From 1e6f6af5ed766ba24f63f021239e409683ee406c Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Fri, 12 May 2023 19:09:33 +0200 Subject: [PATCH] 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'),