diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-07-18 18:02:54 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-07-26 11:25:54 +0100 |
| commit | 7106c34585f3db116307bc908f1eb1fbf51a73cf (patch) | |
| tree | 196e3baf05d1366ae59d8ac6f1fd0a189defec62 /gui/src/renderer | |
| parent | ace147c273e058e85df619fb4300e3953cedd2dd (diff) | |
| download | mullvadvpn-7106c34585f3db116307bc908f1eb1fbf51a73cf.tar.xz mullvadvpn-7106c34585f3db116307bc908f1eb1fbf51a73cf.zip | |
Adjust GUI code to the new settings schema
Diffstat (limited to 'gui/src/renderer')
| -rw-r--r-- | gui/src/renderer/app.tsx | 44 | ||||
| -rw-r--r-- | gui/src/renderer/lib/relay-settings-builder.ts | 22 | ||||
| -rw-r--r-- | gui/src/renderer/redux/settings/reducers.ts | 3 |
3 files changed, 27 insertions, 42 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 6d5d9ae5ab..d77cf65e89 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -37,6 +37,7 @@ import { IRelayList, ISettings, KeygenEvent, + liftConstraint, RelaySettings, RelaySettingsUpdate, TunnelState, @@ -375,43 +376,30 @@ export default class AppRenderer { if ('normal' in relaySettings) { const normal = relaySettings.normal; - const tunnel = normal.tunnel; + const tunnelProtocol = normal.tunnelProtocol; const location = normal.location; - const relayLocation = location === 'any' ? 'any' : location.only; - if (tunnel === 'any') { + if (tunnelProtocol === 'any' || tunnelProtocol.only === 'openvpn') { + const { port, protocol } = normal.openvpnConstraints; actions.settings.updateRelay({ normal: { location: relayLocation, - port: 'any', - protocol: 'any', + port: port === 'any' ? port : port.only, + protocol: protocol === 'any' ? protocol : protocol.only, + tunnelProtocol: liftConstraint(tunnelProtocol), }, }); } else { - const constraints = tunnel.only; - - if ('openvpn' in constraints) { - const { port, protocol } = constraints.openvpn; - - actions.settings.updateRelay({ - normal: { - location: relayLocation, - port: port === 'any' ? port : port.only, - protocol: protocol === 'any' ? protocol : protocol.only, - }, - }); - } else if ('wireguard' in constraints) { - const { port } = constraints.wireguard; - - actions.settings.updateRelay({ - normal: { - location: relayLocation, - port: port === 'any' ? port : port.only, - protocol: 'udp', - }, - }); - } + const { port } = normal.wireguardConstraints; + actions.settings.updateRelay({ + normal: { + tunnelProtocol: liftConstraint(tunnelProtocol), + location: relayLocation, + port: port === 'any' ? port : port.only, + protocol: 'udp', + }, + }); } } else if ('customTunnelEndpoint' in relaySettings) { const customTunnelEndpoint = relaySettings.customTunnelEndpoint; diff --git a/gui/src/renderer/lib/relay-settings-builder.ts b/gui/src/renderer/lib/relay-settings-builder.ts index 72dc95e759..bbf85b1fed 100644 --- a/gui/src/renderer/lib/relay-settings-builder.ts +++ b/gui/src/renderer/lib/relay-settings-builder.ts @@ -80,19 +80,13 @@ class NormalRelaySettingsBuilder { get tunnel(): ITunnelBuilder { const updateOpenvpn = (next: Partial<IOpenVpnConstraints>) => { - const tunnel = this.payload.tunnel; - if (typeof tunnel === 'string' || typeof tunnel === 'undefined') { - this.payload.tunnel = { - only: { - openvpn: next, - }, - }; - } else if (typeof tunnel === 'object') { - const prev = tunnel.only && 'openvpn' in tunnel.only ? tunnel.only.openvpn : {}; - this.payload.tunnel = { - only: { - openvpn: { ...prev, ...next }, - }, + if (this.payload.openvpnConstraints === undefined) { + this.payload.openvpnConstraints = next; + } else { + const prev = this.payload.openvpnConstraints; + this.payload.openvpnConstraints = { + ...prev, + ...next, }; } }; @@ -127,7 +121,7 @@ class NormalRelaySettingsBuilder { return this; }, any: () => { - this.payload.tunnel = 'any'; + this.payload.tunnelProtocol = 'any'; return this; }, }; diff --git a/gui/src/renderer/redux/settings/reducers.ts b/gui/src/renderer/redux/settings/reducers.ts index 97a6a21ee4..e41750b496 100644 --- a/gui/src/renderer/redux/settings/reducers.ts +++ b/gui/src/renderer/redux/settings/reducers.ts @@ -4,6 +4,7 @@ import { KeygenEvent, RelayLocation, RelayProtocol, + TunnelProtocol, } from '../../../shared/daemon-rpc-types'; import { IGuiSettingsState } from '../../../shared/gui-settings-state'; import { ReduxAction } from '../store'; @@ -11,6 +12,7 @@ import { ReduxAction } from '../store'; export type RelaySettingsRedux = | { normal: { + tunnelProtocol: 'any' | TunnelProtocol; location: 'any' | RelayLocation; port: 'any' | number; protocol: 'any' | RelayProtocol; @@ -108,6 +110,7 @@ const initialState: ISettingsReduxState = { relaySettings: { normal: { location: 'any', + tunnelProtocol: 'any', port: 'any', protocol: 'any', }, |
