automatically recover ssh tabs (fixes #583)

This commit is contained in:
Eugene Pankov 2019-01-06 11:54:26 +01:00
parent d03430fb2e
commit ce3610c2da
6 changed files with 29 additions and 10 deletions

View file

@ -6,7 +6,7 @@ import { SettingsTabComponent } from './components/settingsTab.component'
@Injectable() @Injectable()
export class RecoveryProvider extends TabRecoveryProvider { export class RecoveryProvider extends TabRecoveryProvider {
async recover (recoveryToken: any): Promise<RecoveredTab> { async recover (recoveryToken: any): Promise<RecoveredTab> {
if (recoveryToken.type === 'app:settings') { if (recoveryToken && recoveryToken.type === 'app:settings') {
return { type: SettingsTabComponent } return { type: SettingsTabComponent }
} }
return null return null

View file

@ -53,4 +53,11 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
this.session.resize(this.size.columns, this.size.rows) this.session.resize(this.size.columns, this.size.rows)
this.session.start() this.session.start()
} }
async getRecoveryToken (): Promise<any> {
return {
type: 'app:ssh-tab',
connection: this.connection,
}
}
} }

View file

@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common'
import { FormsModule } from '@angular/forms' import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr' import { ToastrModule } from 'ngx-toastr'
import TerminusCoreModule, { ToolbarButtonProvider, ConfigProvider } from 'terminus-core' import TerminusCoreModule, { ToolbarButtonProvider, ConfigProvider, TabRecoveryProvider } from 'terminus-core'
import { SettingsTabProvider } from 'terminus-settings' import { SettingsTabProvider } from 'terminus-settings'
import { EditConnectionModalComponent } from './components/editConnectionModal.component' import { EditConnectionModalComponent } from './components/editConnectionModal.component'
@ -15,6 +15,7 @@ import { SSHTabComponent } from './components/sshTab.component'
import { ButtonProvider } from './buttonProvider' import { ButtonProvider } from './buttonProvider'
import { SSHConfigProvider } from './config' import { SSHConfigProvider } from './config'
import { SSHSettingsTabProvider } from './settings' import { SSHSettingsTabProvider } from './settings'
import { RecoveryProvider } from './recoveryProvider'
@NgModule({ @NgModule({
imports: [ imports: [
@ -28,6 +29,7 @@ import { SSHSettingsTabProvider } from './settings'
{ provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true }, { provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true },
{ provide: ConfigProvider, useClass: SSHConfigProvider, multi: true }, { provide: ConfigProvider, useClass: SSHConfigProvider, multi: true },
{ provide: SettingsTabProvider, useClass: SSHSettingsTabProvider, multi: true }, { provide: SettingsTabProvider, useClass: SSHSettingsTabProvider, multi: true },
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
], ],
entryComponents: [ entryComponents: [
EditConnectionModalComponent, EditConnectionModalComponent,

View file

@ -0,0 +1,17 @@
import { Injectable } from '@angular/core'
import { TabRecoveryProvider, RecoveredTab } from 'terminus-core'
import { SSHTabComponent } from './components/sshTab.component'
@Injectable()
export class RecoveryProvider extends TabRecoveryProvider {
async recover (recoveryToken: any): Promise<RecoveredTab> {
if (recoveryToken && recoveryToken.type === 'app:ssh-tab') {
return {
type: SSHTabComponent,
options: { connection: recoveryToken.connection },
}
}
return null
}
}

View file

@ -159,7 +159,6 @@ export class SSHService {
keepaliveInterval: session.connection.keepaliveInterval, keepaliveInterval: session.connection.keepaliveInterval,
keepaliveCountMax: session.connection.keepaliveCountMax, keepaliveCountMax: session.connection.keepaliveCountMax,
readyTimeout: session.connection.readyTimeout, readyTimeout: session.connection.readyTimeout,
debug: (...x) => console.log(...x),
hostVerifier: digest => { hostVerifier: digest => {
log('SHA256 fingerprint: ' + digest) log('SHA256 fingerprint: ' + digest)
return true return true

View file

@ -5,14 +5,8 @@ import { TerminalTabComponent } from './components/terminalTab.component'
@Injectable() @Injectable()
export class RecoveryProvider extends TabRecoveryProvider { export class RecoveryProvider extends TabRecoveryProvider {
constructor (
// private sessions: SessionsService,
) {
super()
}
async recover (recoveryToken: any): Promise<RecoveredTab> { async recover (recoveryToken: any): Promise<RecoveredTab> {
if (recoveryToken.type === 'app:terminal-tab') { if (recoveryToken && recoveryToken.type === 'app:terminal-tab') {
return { return {
type: TerminalTabComponent, type: TerminalTabComponent,
options: { sessionOptions: recoveryToken.sessionOptions }, options: { sessionOptions: recoveryToken.sessionOptions },