From 18e56298dc0c08bfd82688c9f7a4638f6d4fa1db Mon Sep 17 00:00:00 2001 From: luin Date: Sat, 3 Dec 2016 15:41:10 +0800 Subject: [PATCH] feat: support Elastic Cache Redis & RedisLabs for selecting database Closes: #16, #33, #50 --- client/actions.js | 4 ++ .../main/Main/ConnectionSelector/Config.jsx | 6 ++- .../main/Main/ConnectionSelector/Config.scss | 4 +- .../main/Main/Database/KeyBrowser/Footer.jsx | 39 ++++++++++++++++--- .../main/Main/Database/KeyBrowser/KeyList.jsx | 2 +- server/main.js | 6 +++ 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/client/actions.js b/client/actions.js index 9e8f92b8..467a896d 100644 --- a/client/actions.js +++ b/client/actions.js @@ -57,6 +57,10 @@ const actions = { function handleRedis(config, override) { dispatch({ type: 'updateConnectStatus', data: 'Redis connecting...' }); + if (config.ssl) { + config.tls = { + } + } const redis = new Redis(_.assign({}, config, override, { showFriendlyErrorStack: true, retryStrategy() { diff --git a/client/components/main/Main/ConnectionSelector/Config.jsx b/client/components/main/Main/ConnectionSelector/Config.jsx index d35b50d6..9839e421 100644 --- a/client/components/main/Main/ConnectionSelector/Config.jsx +++ b/client/components/main/Main/ConnectionSelector/Config.jsx @@ -49,7 +49,7 @@ class Config extends React.Component { handleChange(property, e) { let value = e.target.value; - if (property === 'ssh') { + if (property === 'ssh' || property === 'ssl') { value = e.target.checked; } this.setProp(property, value); @@ -81,6 +81,10 @@ class Config extends React.Component { +
+ + +
diff --git a/client/components/main/Main/ConnectionSelector/Config.scss b/client/components/main/Main/ConnectionSelector/Config.scss index 9fdeb8a3..206a8dce 100644 --- a/client/components/main/Main/ConnectionSelector/Config.scss +++ b/client/components/main/Main/ConnectionSelector/Config.scss @@ -3,13 +3,13 @@ } .ssh-key { - height: 20px; + height: 19px; line-height: 20px; padding: 0; text-align: center; width: 30px; position: relative; - top: -1px; + top: 0; left: -30px; border-top: 0; border-bottom: 0; diff --git a/client/components/main/Main/Database/KeyBrowser/Footer.jsx b/client/components/main/Main/Database/KeyBrowser/Footer.jsx index 4ebb47c2..60f9c929 100644 --- a/client/components/main/Main/Database/KeyBrowser/Footer.jsx +++ b/client/components/main/Main/Database/KeyBrowser/Footer.jsx @@ -10,6 +10,7 @@ class Footer extends React.Component { componentDidMount() { this.updateInfo(); + this.updateDBCount(); this.interval = setInterval(this.updateInfo.bind(this), 10000); } @@ -19,6 +20,25 @@ class Footer extends React.Component { } } + updateDBCount() { + this.props.redis.config('get', 'databases', (err, res) => { + if (!err) { + if (res[1]) { + this.setState({ databases: Number(res[1]) }); + } else { + const redis = this.props.redis.duplicate(); + const select = redis.select.bind(redis); + this.guessDatabaseNumber(select, 15).then((count) => { + console.log('===', count) + return typeof count === 'number' ? count : this.guessDatabaseNumber(select, 1, 0); + }).then((count) => { + this.setState({ databases: count + 1 }); + }); + } + } + }); + } + updateInfo() { this.props.redis.info((err, res) => { if (err) { @@ -36,12 +56,21 @@ class Footer extends React.Component { this.setState(info); }); + } - this.props.redis.config('get', 'databases', (err, res) => { - if (res && res[1]) { - this.setState({ databases: Number(res[1]) }); + guessDatabaseNumber(select, startIndex, lastSuccessIndex) { + if (startIndex > 30) { + return Promise.resolve(30); + } + return select(startIndex) + .then(() => { + return this.guessDatabaseNumber(select, startIndex + 1, startIndex); + }).catch((err) => { + if (typeof lastSuccessIndex === 'number') { + return lastSuccessIndex; } - }); + return null; + }) } componentWillUnmount() { @@ -87,7 +116,7 @@ class Footer extends React.Component { >{i}); } return items; - })(this.state.databases) + })(this.state.databases || 1) }
diff --git a/client/components/main/Main/Database/KeyBrowser/KeyList.jsx b/client/components/main/Main/Database/KeyBrowser/KeyList.jsx index 6e386c9c..403e01d6 100644 --- a/client/components/main/Main/Database/KeyBrowser/KeyList.jsx +++ b/client/components/main/Main/Database/KeyBrowser/KeyList.jsx @@ -449,7 +449,7 @@ class KeyList extends React.Component { if (this.state.scanning) { return Scanning...(cursor {this.state.cursor}); } - return { + return { evt.preventDefault(); this.scan(); }}>Scan more; diff --git a/server/main.js b/server/main.js index cec472b4..b0adfc27 100644 --- a/server/main.js +++ b/server/main.js @@ -21,6 +21,12 @@ app.on('window-all-closed', function () { } }); +app.on('activate', function (e, hasVisibleWindows) { + if (!hasVisibleWindows) { + windowManager.create(); + } +}); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.on('ready', function () {