added message popups

This commit is contained in:
Eugene Pankov
2018-01-19 15:31:28 +01:00
parent 4259d3b53d
commit ee2fadbf60
13 changed files with 36 additions and 58 deletions

View File

@@ -1,5 +1,6 @@
import { Component } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { ToastrService } from 'ngx-toastr'
import { ConfigService, AppService } from 'terminus-core'
import { SettingsTabComponent } from 'terminus-settings'
import { SSHService } from '../services/ssh.service'
@@ -19,6 +20,7 @@ export class SSHModalComponent {
private config: ConfigService,
private ssh: SSHService,
private app: AppService,
private toastr: ToastrService,
) { }
ngOnInit () {
@@ -45,7 +47,7 @@ export class SSHModalComponent {
connect (connection: SSHConnection) {
this.close()
this.ssh.connect(connection).catch(error => {
alert(`Could not connect: ${error}`)
this.toastr.error(`Could not connect: ${error}`)
})
}

View File

@@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr'
import { ToolbarButtonProvider, ConfigProvider } from 'terminus-core'
import { SettingsTabProvider } from 'terminus-settings'
@@ -21,6 +22,7 @@ import { SSHSettingsTabProvider } from './settings'
NgbModule,
CommonModule,
FormsModule,
ToastrModule,
],
providers: [
PasswordStorageService,

View File

@@ -3,6 +3,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { Client } from 'ssh2'
import * as fs from 'mz/fs'
import * as path from 'path'
import { ToastrService } from 'ngx-toastr'
import { AppService, HostAppService, Platform, Logger, LogService } from 'terminus-core'
import { TerminalTabComponent } from 'terminus-terminal'
import { SSHConnection, SSHSession } from '../api'
@@ -21,6 +22,7 @@ export class SSHService {
private ngbModal: NgbModal,
private hostApp: HostAppService,
private passwordStorage: PasswordStorageService,
private toastr: ToastrService,
) {
this.logger = log.create('ssh')
}
@@ -41,7 +43,7 @@ export class SSHService {
try {
privateKey = (await fs.readFile(privateKeyPath)).toString()
} catch (error) {
// notify: couldn't read key
this.toastr.warning('Could not read the private key file')
}
if (privateKey) {
@@ -73,7 +75,7 @@ export class SSHService {
this.passwordStorage.deletePassword(connection)
this.zone.run(() => {
if (connected) {
alert(`SSH error: ${error}`)
this.toastr.error(error.toString())
} else {
reject(error)
}
@@ -101,7 +103,7 @@ export class SSHService {
ssh.connect({
host: connection.host,
username: connection.user,
password: privateKey ? undefined : '',
password: connection.privateKey ? undefined : '',
privateKey,
passphrase: privateKeyPassphrase,
tryKeyboard: true,
@@ -113,12 +115,14 @@ export class SSHService {
;(ssh as any).config.password = () => this.zone.run(async () => {
if (connection.password) {
this.logger.info('Using preset password')
return connection.password
}
if (!keychainPasswordUsed) {
let password = await this.passwordStorage.loadPassword(connection)
if (password) {
this.logger.info('Using saved password')
keychainPasswordUsed = true
return password
}