summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-03-20 14:45:50 +0000
committerAndrej Mihajlov <and@codeispoetry.ru>2017-03-20 14:45:50 +0000
commit8fd8accfa18436ff2367ff020cab0b5279c1ce38 (patch)
tree3e8be477a7f9869a586be25ddeb8e207ed7c7df3
parentc97cd1231075296a7985e1e2992c56b14e230152 (diff)
downloadmullvadvpn-8fd8accfa18436ff2367ff020cab0b5279c1ce38.tar.xz
mullvadvpn-8fd8accfa18436ff2367ff020cab0b5279c1ce38.zip
Copy ip address to clipboard
-rw-r--r--app/actions/connect.js18
-rw-r--r--app/components/Connect.js24
-rw-r--r--app/containers/ConnectPage.js4
3 files changed, 42 insertions, 4 deletions
diff --git a/app/actions/connect.js b/app/actions/connect.js
index dc794a01d7..a63496661a 100644
--- a/app/actions/connect.js
+++ b/app/actions/connect.js
@@ -1,7 +1,23 @@
+import { clipboard } from 'electron';
import { createAction } from 'redux-actions';
+/** Action for changing connection state */
const connectionChange = createAction('CONNECTION_CHANGE');
+
+/** Action for connecting to server */
const connect = (backend, addr) => () => backend.connect(addr);
+
+/** Action for disconnecting from server */
const disconnect = (backend) => () => backend.disconnect();
-export default { connect, disconnect, connectionChange };
+/** Action for copying IP address in memory */
+const copyIPAddress = () => {
+ return (_, getState) => {
+ const ip = getState().connect.clientIp;
+ if(typeof(ip) === 'string') {
+ clipboard.writeText(ip);
+ }
+ };
+};
+
+export default { connect, disconnect, copyIPAddress, connectionChange };
diff --git a/app/components/Connect.js b/app/components/Connect.js
index 5e44fdd8ae..429b617526 100644
--- a/app/components/Connect.js
+++ b/app/components/Connect.js
@@ -13,6 +13,7 @@ export default class Connect extends Component {
settings: PropTypes.object.isRequired,
onSettings: PropTypes.func.isRequired,
onConnect: PropTypes.func.isRequired,
+ onCopyIP: PropTypes.func.isRequired,
onDisconnect: PropTypes.func.isRequired,
getServerInfo: PropTypes.func.isRequired
};
@@ -20,8 +21,15 @@ export default class Connect extends Component {
constructor() {
super();
+ // timer used along with `state.showCopyIPMessage`
+ this._copyTimer = null;
+
this.state = {
- isFirstPass: true
+ isFirstPass: true,
+
+ // this flag is used together with timer to display
+ // a message that IP address has been copied to clipboard
+ showCopyIPMessage: false
};
}
@@ -158,7 +166,12 @@ export default class Connect extends Component {
**********************************
*/ }
- <div className={ this.ipAddressClass() }>{ this.props.connect.clientIp }</div>
+ <div className={ this.ipAddressClass() } onClick={ ::this.onIPAddressClick }>
+ <If condition={ this.state.showCopyIPMessage }>
+ <Then><span>{ "IP copied to clipboard!" }</span></Then>
+ <Else><span>{ this.props.connect.clientIp }</span></Else>
+ </If>
+ </div>
</div>
@@ -254,6 +267,13 @@ export default class Connect extends Component {
this.props.onConnect(serverInfo.address);
}
+ onIPAddressClick() {
+ this._copyTimer && clearTimeout(this._copyTimer);
+ this._copyTimer = setTimeout(() => this.setState({ showCopyIPMessage: false }), 3000);
+ this.setState({ showCopyIPMessage: true });
+ this.props.onCopyIP();
+ }
+
// Private
headerStyle() {
diff --git a/app/containers/ConnectPage.js b/app/containers/ConnectPage.js
index f7d9939257..7b01258f18 100644
--- a/app/containers/ConnectPage.js
+++ b/app/containers/ConnectPage.js
@@ -8,12 +8,14 @@ const mapStateToProps = (state) => {
};
const mapDispatchToProps = (dispatch, props) => {
- const { connect, disconnect } = bindActionCreators(connectActions, dispatch);
+ const { connect, disconnect, copyIPAddress } = bindActionCreators(connectActions, dispatch);
const { backend } = props;
+
return {
onSettings: () => props.router.push('/settings'),
onSelectLocation: () => props.router.push('/select-location'),
onConnect: (addr) => connect(backend, addr),
+ onCopyIP: () => copyIPAddress(),
onDisconnect: () => disconnect(backend),
getServerInfo: (key) => backend.serverInfo(key)
};