Skip to content

Commit

Permalink
fix #26 add global timeout setting
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdong262 committed Jan 2, 2018
1 parent 4250548 commit d505481
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function() {
port: freePort,
host: '127.0.0.1',
hotkey: 'Control+2',
sshReadyTimeout: 50000,
showMenu: true
}
extend(conf, override)
Expand Down
3 changes: 3 additions & 0 deletions app/config.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {

// hotkey, systerm hotkey to bring window back to front,default is 'Control+2'
// hotkey: 'Control+2'

//ssh/sftp timeout(in millisecond)
// sshReadyTimeout: 50000
}


Expand Down
19 changes: 12 additions & 7 deletions app/lib/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {Client} = require('ssh2')
const _ = require('lodash')
const {generate} = require('shortid')


class Terminal {

constructor(initOptions) {
Expand Down Expand Up @@ -38,12 +37,18 @@ class Terminal {
remoteInit(initOptions) {
return new Promise((resolve, reject) => {
const conn = new Client()
let opts = _.pick(initOptions, [
'host',
'port',
'username',
'password'
])
let opts = Object.assign(
{},
{
readyTimeout: _.get(global, '_config.sshReadyTimeout')
},
_.pick(initOptions, [
'host',
'port',
'username',
'password'
])
)
conn.on('ready', () => {
conn.shell(
_.pick(initOptions, ['rows', 'cols', 'mode']),
Expand Down
15 changes: 13 additions & 2 deletions app/lib/user-config-controller.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@


/**
* user-controll.json controll
*/
const fs = require('fs')
const {resolve} = require('path')
const appPath = require('./app-path')
let userConfig = {}
const userConfigPath = resolve(appPath, 'electerm-user-config.json')

try {
userConfig = require(userConfigPath)
} catch (e) {
console.log('no user config, but it is ok')
}

exports.saveUserConfig = (conf) => {
Object.assign(global._config, conf)
Object.assign(userConfig, conf)
fs.writeFileSync(
resolve(appPath, 'user-config.json'),
JSON.stringify(conf)
userConfigPath,
JSON.stringify(userConfig)
)
}

19 changes: 17 additions & 2 deletions src/client/components/setting/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import React from 'react'
import {message, Select} from 'antd'
import {message, Select, InputNumber} from 'antd'

const {Option} = Select
const {getGlobal} = window
Expand All @@ -27,6 +27,12 @@ export default class Setting extends React.Component {
})
}

onChangeTimeout = sshReadyTimeout => {
return this.saveConfig({
sshReadyTimeout: sshReadyTimeout
})
}

onChangeKey = key => {
let {hotkey} = this.props.config
let modifier = hotkey.split('+')[0]
Expand Down Expand Up @@ -64,7 +70,7 @@ export default class Setting extends React.Component {
}

render() {
let {hotkey} = this.props.config
let {hotkey, sshReadyTimeout} = this.props.config
let [modifier, key] = hotkey.split('+')
return (
<div className="form-wrap pd1y pd2x">
Expand Down Expand Up @@ -93,6 +99,15 @@ export default class Setting extends React.Component {
}
</Select>
</div>
<div className="pd1b">ssh timeout(in millisecond)</div>
<div className="pd2b">
<InputNumber
onChange={this.onChangeTimeout}
step={1000}
min={100}
value={sshReadyTimeout}
/>
</div>
</div>
)
}
Expand Down

0 comments on commit d505481

Please sign in to comment.