mirror of
https://github.com/Eugeny/tabby
synced 2024-11-15 01:17:14 +00:00
parent
c7eb19386d
commit
0f0f61f432
3 changed files with 25 additions and 21 deletions
|
@ -84,9 +84,9 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
|
|||
super.ngOnInit()
|
||||
}
|
||||
|
||||
async setupOneSession (injector: Injector, profile: SSHProfile): Promise<SSHSession> {
|
||||
async setupOneSession (injector: Injector, profile: SSHProfile, multiplex = true): Promise<SSHSession> {
|
||||
let session = await this.sshMultiplexer.getSession(profile)
|
||||
if (!session || !profile.options.reuseSession) {
|
||||
if (!multiplex || !session || !profile.options.reuseSession) {
|
||||
session = new SSHSession(injector, profile)
|
||||
|
||||
if (profile.options.jumpHost) {
|
||||
|
@ -146,11 +146,8 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
|
|||
|
||||
try {
|
||||
await session.start()
|
||||
} finally {
|
||||
this.stopSpinner()
|
||||
} catch (e) {
|
||||
this.stopSpinner()
|
||||
this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n')
|
||||
return session
|
||||
}
|
||||
|
||||
this.sshMultiplexer.addSession(session)
|
||||
|
@ -186,21 +183,14 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
|
|||
super.attachSessionHandlers()
|
||||
}
|
||||
|
||||
async initializeSession (): Promise<void> {
|
||||
this.reconnectOffered = false
|
||||
private async initializeSessionMaybeMultiplex (multiplex = true): Promise<void> {
|
||||
if (!this.profile) {
|
||||
this.logger.error('No SSH connection info supplied')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
this.sshSession = await this.setupOneSession(this.injector, this.profile)
|
||||
} catch (e) {
|
||||
this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n')
|
||||
return
|
||||
throw new Error('No SSH connection info supplied')
|
||||
}
|
||||
|
||||
this.sshSession = await this.setupOneSession(this.injector, this.profile, multiplex)
|
||||
const session = new SSHShellSession(this.injector, this.sshSession, this.profile)
|
||||
|
||||
this.setSession(session)
|
||||
this.attachSessionHandler(session.serviceMessage$, msg => {
|
||||
msg = msg.replace(/\n/g, '\r\n ')
|
||||
|
@ -212,6 +202,20 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
|
|||
this.session?.resize(this.size.columns, this.size.rows)
|
||||
}
|
||||
|
||||
async initializeSession (): Promise<void> {
|
||||
this.reconnectOffered = false
|
||||
try {
|
||||
await this.initializeSessionMaybeMultiplex(true)
|
||||
} catch {
|
||||
try {
|
||||
await this.initializeSessionMaybeMultiplex(false)
|
||||
} catch (e) {
|
||||
this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n')
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise<RecoveryToken> {
|
||||
return {
|
||||
type: 'app:ssh-tab',
|
||||
|
|
|
@ -15,7 +15,9 @@ export class SSHMultiplexerService {
|
|||
const key = await this.getMultiplexerKey(session.profile)
|
||||
this.sessions.set(key, session)
|
||||
session.willDestroy$.subscribe(() => {
|
||||
this.sessions.delete(key)
|
||||
if (this.sessions.get(key) === session) {
|
||||
this.sessions.delete(key)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Observable, Subject } from 'rxjs'
|
||||
import colors from 'ansi-colors'
|
||||
import stripAnsi from 'strip-ansi'
|
||||
import { ClientChannel } from 'ssh2'
|
||||
import { Injector } from '@angular/core'
|
||||
|
@ -41,11 +40,10 @@ export class SSHShellSession extends BaseSession {
|
|||
try {
|
||||
this.shell = await this.ssh.openShellChannel({ x11: this.profile.options.x11 ?? false })
|
||||
} catch (err) {
|
||||
this.emitServiceMessage(colors.bgRed.black(' X ') + ` Remote rejected opening a shell channel: ${err}`)
|
||||
if (err.toString().includes('Unable to request X11')) {
|
||||
this.emitServiceMessage(' Make sure `xauth` is installed on the remote side')
|
||||
}
|
||||
return
|
||||
throw new Error(`Remote rejected opening a shell channel: ${err}`)
|
||||
}
|
||||
|
||||
this.open = true
|
||||
|
|
Loading…
Reference in a new issue