mirror of
https://github.com/Eugeny/tabby.git
synced 2024-11-27 06:00:26 +08:00
ref(connectable tab) reconnect context menu & hotkey
This commit is contained in:
parent
901181f681
commit
1e6f6af5ed
@ -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<SerialProfile> implements Reconnectable {
|
||||
export class SerialTabComponent extends ConnectableTerminalTabComponent<SerialProfile> {
|
||||
session: SerialSession|null = null
|
||||
Platform = Platform
|
||||
|
||||
@ -90,12 +89,7 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent<SerialPr
|
||||
if (this.profile.behaviorOnSessionEnd === 'reconnect') {
|
||||
this.reconnect()
|
||||
} else if (this.profile.behaviorOnSessionEnd === 'keep' || this.profile.behaviorOnSessionEnd === 'auto' && !this.isSessionExplicitlyTerminated()) {
|
||||
this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n')
|
||||
this.input$.pipe(first()).subscribe(() => {
|
||||
if (!this.session?.open) {
|
||||
this.reconnect()
|
||||
}
|
||||
})
|
||||
this.offerReconnection()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -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<SSHProfile> implements Reconnectable {
|
||||
export class SSHTabComponent extends ConnectableTerminalTabComponent<SSHProfile> {
|
||||
Platform = Platform
|
||||
sshSession: SSHSession|null = null
|
||||
session: SSHShellSession|null = null
|
||||
@ -159,15 +158,7 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent<SSHProfile>
|
||||
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<SSHProfile>
|
||||
}
|
||||
|
||||
async initializeSession (): Promise<void> {
|
||||
this.reconnectOffered = false
|
||||
await super.initializeSession()
|
||||
try {
|
||||
await this.initializeSessionMaybeMultiplex(true)
|
||||
} catch {
|
||||
|
@ -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<TelnetProfile> implements Reconnectable {
|
||||
export class TelnetTabComponent extends ConnectableTerminalTabComponent<TelnetProfile> {
|
||||
Platform = Platform
|
||||
session: TelnetSession|null = null
|
||||
|
||||
@ -53,15 +52,7 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent<TelnetPr
|
||||
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()
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -69,7 +60,7 @@ export class TelnetTabComponent extends ConnectableTerminalTabComponent<TelnetPr
|
||||
}
|
||||
|
||||
async initializeSession (): Promise<void> {
|
||||
this.reconnectOffered = false
|
||||
await super.initializeSession()
|
||||
|
||||
const session = new TelnetSession(this.injector, this.profile)
|
||||
this.setSession(session)
|
||||
|
@ -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<P extends BaseTerminalProf
|
||||
|
||||
constructor (protected injector: Injector) {
|
||||
super(injector)
|
||||
|
||||
this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
|
||||
if (this.hasFocus && hotkey === 'reconnect-tab') {
|
||||
this.reconnect()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
abstract initializeSession (): Promise<void>
|
||||
/**
|
||||
* Initialize Connectable Session.
|
||||
* Set reconnectOffered to false
|
||||
*/
|
||||
async initializeSession (): Promise<void> {
|
||||
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<void> {
|
||||
this.session?.destroy()
|
||||
|
@ -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<MenuItemOptions[]> {
|
||||
if (isReconnectable(tab)) {
|
||||
if (isReconnectable(tab) || tab instanceof ConnectableTerminalTabComponent) {
|
||||
return [
|
||||
{
|
||||
label: this.translate.instant('Reconnect'),
|
||||
|
Loading…
Reference in New Issue
Block a user