diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 58884d07..d648dac4 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 } from 'tabby-terminal' +import { BaseTerminalTabComponent, 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 { +export class SerialTabComponent extends BaseTerminalTabComponent 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 1694813a..11af1368 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 } from 'tabby-terminal' +import { BaseTerminalTabComponent, 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 { +export class SSHTabComponent extends BaseTerminalTabComponent implements Reconnectable { Platform = Platform sshSession: SSHSession|null = null session: SSHShellSession|null = null diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 48458b61..440e3432 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 } from 'tabby-terminal' +import { BaseTerminalTabComponent, Reconnectable } from 'tabby-terminal' import { TelnetProfile, TelnetSession } from '../session' @@ -14,7 +14,7 @@ import { TelnetProfile, TelnetSession } from '../session' styleUrls: ['./telnetTab.component.scss', ...BaseTerminalTabComponent.styles], animations: BaseTerminalTabComponent.animations, }) -export class TelnetTabComponent extends BaseTerminalTabComponent { +export class TelnetTabComponent extends BaseTerminalTabComponent implements Reconnectable { Platform = Platform session: TelnetSession|null = null private reconnectOffered = false diff --git a/tabby-terminal/src/api/interfaces.ts b/tabby-terminal/src/api/interfaces.ts index 74143339..76d6acf2 100644 --- a/tabby-terminal/src/api/interfaces.ts +++ b/tabby-terminal/src/api/interfaces.ts @@ -19,3 +19,11 @@ export interface TerminalColorScheme { export interface BaseTerminalProfile extends Profile { terminalColorScheme?: TerminalColorScheme } + +export interface Reconnectable { + reconnect: () => Promise; +} + +export function tabIsReconnectable (object: any): object is Reconnectable { + return 'reconnect' in object +} diff --git a/tabby-terminal/src/index.ts b/tabby-terminal/src/index.ts index 99f3e225..01405dbb 100644 --- a/tabby-terminal/src/index.ts +++ b/tabby-terminal/src/index.ts @@ -28,7 +28,7 @@ import { PathDropDecorator } from './features/pathDrop' import { ZModemDecorator } from './features/zmodem' import { TerminalConfigProvider } from './config' import { TerminalHotkeyProvider } from './hotkeys' -import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu } from './tabContextMenu' +import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu, ReconnectContextMenu } from './tabContextMenu' import { Frontend } from './frontends/frontend' import { XTermFrontend, XTermWebGLFrontend } from './frontends/xtermFrontend' @@ -58,6 +58,7 @@ import { TerminalCLIHandler } from './cli' { provide: TabContextMenuItemProvider, useClass: CopyPasteContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: MiscContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: LegacyContextMenu, multi: true }, + { provide: TabContextMenuItemProvider, useClass: ReconnectContextMenu, multi: true }, { provide: CLIHandler, useClass: TerminalCLIHandler, multi: true }, ], diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index fab843a1..a4ee56f6 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,6 +1,7 @@ import { Injectable, Optional, Inject } from '@angular/core' import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' +import { tabIsReconnectable } from './api/interfaces' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' @@ -85,6 +86,35 @@ export class MiscContextMenu extends TabContextMenuItemProvider { } } +/** @hidden */ +@Injectable() +export class ReconnectContextMenu extends TabContextMenuItemProvider { + weight = 1 + + constructor ( + private translate: TranslateService, + private notifications: NotificationsService, + ) { super() } + + async getItems (tab: BaseTabComponent): Promise { + if (tabIsReconnectable(tab)) { + return [ + { + label: this.translate.instant('Reconnect'), + click: (): void => { + setTimeout(() => { + tab.reconnect() + this.notifications.notice(this.translate.instant('Reconnect')) + }) + }, + }, + ] + } + return [] + } + +} + /** @hidden */ @Injectable() export class LegacyContextMenu extends TabContextMenuItemProvider { @@ -109,4 +139,5 @@ export class LegacyContextMenu extends TabContextMenuItemProvider { } return [] } + }