diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/components/AdvancedSettings.js | 11 | ||||
| -rw-r--r-- | app/containers/AdvancedSettingsPage.js | 47 |
2 files changed, 27 insertions, 31 deletions
diff --git a/app/components/AdvancedSettings.js b/app/components/AdvancedSettings.js index 227499a1a8..1821309369 100644 --- a/app/components/AdvancedSettings.js +++ b/app/components/AdvancedSettings.js @@ -7,14 +7,16 @@ import CustomScrollbars from './CustomScrollbars'; export class AdvancedSettings extends React.Component { props: { - onClose: () => void, + host: string, protocol: string, port: string|number, - updateConstraints: (string, string|number) => void, + onUpdateConstraints: (host: string, protocol: string, port: string|number) => void, + onClose: () => void, }; render() { let portSelector = null; + const host = this.props.host; let protocol = this.props.protocol.toUpperCase(); if (protocol === 'AUTOMATIC') { @@ -30,7 +32,7 @@ export class AdvancedSettings extends React.Component { values={ ['Automatic', 'UDP', 'TCP'] } value={ protocol } onSelect={ protocol => { - this.props.updateConstraints(protocol, 'Automatic'); + this.props.onUpdateConstraints(host, protocol, 'Automatic'); }}/> <div className="settings__cell-spacer"></div> @@ -41,6 +43,7 @@ export class AdvancedSettings extends React.Component { } _createPortSelector() { + const host = this.props.host; const protocol = this.props.protocol.toUpperCase(); const ports = protocol === 'TCP' ? ['Automatic', 80, 443] @@ -51,7 +54,7 @@ export class AdvancedSettings extends React.Component { values={ ports } value={ this.props.port } onSelect={ port => { - this.props.updateConstraints(protocol, port); + this.props.onUpdateConstraints(host, protocol, port); }} />; } } diff --git a/app/containers/AdvancedSettingsPage.js b/app/containers/AdvancedSettingsPage.js index 632ce089be..fd83406c25 100644 --- a/app/containers/AdvancedSettingsPage.js +++ b/app/containers/AdvancedSettingsPage.js @@ -5,47 +5,40 @@ import settingsActions from '../redux/settings/actions'; import log from 'electron-log'; const mapStateToProps = (state) => { - const contraints = state.settings.relaySettings; + const constraints = state.settings.relaySettings; + const { host, protocol, port } = constraints; return { - protocol: anyToAuto(contraints.protocol), - port: anyToAuto(contraints.port), + host: host, + protocol: protocol === 'any' ? 'Automatic' : protocol, + port: port === 'any' ? 'Automatic' : port, }; }; -function anyToAuto(constraint) { - if (constraint === 'any') { - return 'Automatic'; - } else { - return constraint; - } -} - const mapDispatchToProps = (dispatch, props) => { const { backend } = props; return { onClose: () => dispatch(push('/settings')), - updateConstraints: (protocol, port) => { - - const protConstraint = protocol === 'Automatic' - ? 'any' - : { only: protocol.toLowerCase() }; - - const portConstraint = port === 'Automatic' - ? 'any' - : { only: port }; - + onUpdateConstraints: (host, protocol, port) => { + // TODO: udp and 1300 are automatic because we cannot pass `any` when using custom tunnel + const protocolConstraint = protocol === 'Automatic' ? 'udp' : protocol.toLowerCase(); + const portConstraint = port === 'Automatic' ? (protocolConstraint === 'tcp' ? 443 : 1300) : port; const update = { - tunnel: { openvpn: { - protocol: protConstraint, - port: portConstraint, - }}, + custom_tunnel_endpoint: { + host: host, + tunnel: { + openvpn: { + protocol: protocolConstraint, + port: portConstraint, + } + } + }, }; backend.updateRelaySettings(update) .then( () => dispatch(settingsActions.updateRelay({ - port: typeof(portConstraint) === 'object' ? portConstraint.only : portConstraint, - protocol: typeof(protConstraint) === 'object' ? protConstraint.only : protConstraint, + protocol: protocolConstraint, + port: portConstraint, }))) .catch( e => log.error('Failed updating relay constraints', e.message)); }, |
