diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-09-13 16:06:34 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-09-13 16:06:34 +0200 |
| commit | ed527997886dad36671518b3bc888657e4a2b565 (patch) | |
| tree | 6c8e4a28a38e038964c482a67cc7a6380a66f8c6 | |
| parent | e651f066833c3fb5f80abf4d6e7f7d5ed20c37cd (diff) | |
| parent | 5105fe058780d6ebde2106da3f244f198bed5856 (diff) | |
| download | mullvadvpn-ed527997886dad36671518b3bc888657e4a2b565.tar.xz mullvadvpn-ed527997886dad36671518b3bc888657e4a2b565.zip | |
Merge branch 'add-bridge-location-reset'
| -rw-r--r-- | gui/src/main/index.ts | 21 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 11 | ||||
| -rw-r--r-- | gui/src/renderer/components/CityRow.tsx | 4 | ||||
| -rw-r--r-- | gui/src/renderer/components/CountryRow.tsx | 4 | ||||
| -rw-r--r-- | gui/src/renderer/components/RelayRow.tsx | 4 | ||||
| -rw-r--r-- | gui/src/renderer/components/RelayStatusIndicator.tsx | 27 | ||||
| -rw-r--r-- | gui/src/renderer/components/SelectLocation.tsx | 55 | ||||
| -rw-r--r-- | gui/src/renderer/components/SelectLocationStyles.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/containers/AdvancedSettingsPage.tsx | 2 | ||||
| -rw-r--r-- | gui/src/renderer/containers/SelectLocationPage.tsx | 29 | ||||
| -rw-r--r-- | gui/src/shared/bridge-settings-builder.ts | 24 | ||||
| -rw-r--r-- | gui/src/shared/ipc-event-channel.ts | 12 | ||||
| -rw-r--r-- | gui/src/shared/relay-location-builder.ts | 41 | ||||
| -rw-r--r-- | gui/src/shared/relay-settings-builder.ts (renamed from gui/src/renderer/lib/relay-settings-builder.ts) | 51 | ||||
| -rw-r--r-- | gui/test/relay-settings-builder.spec.ts | 2 |
15 files changed, 170 insertions, 120 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 05edd6af6c..19517352bf 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -4,6 +4,7 @@ import log from 'electron-log'; import mkdirp from 'mkdirp'; import * as path from 'path'; import * as uuid from 'uuid'; +import BridgeSettingsBuilder from '../shared/bridge-settings-builder'; import { AccountToken, BridgeSettings, @@ -17,7 +18,6 @@ import { IWireguardPublicKey, KeygenEvent, liftConstraint, - RelayLocation, RelaySettings, RelaySettingsUpdate, TunnelState, @@ -948,22 +948,21 @@ class ApplicationMain { IpcMainEventChannel.settings.handleBlockWhenDisconnected((blockWhenDisconnected: boolean) => this.daemonRpc.setBlockWhenDisconnected(blockWhenDisconnected), ); - IpcMainEventChannel.settings.handleBridgeState((bridgeState: BridgeState) => - this.daemonRpc.setBridgeState(bridgeState), - ); + IpcMainEventChannel.settings.handleBridgeState(async (bridgeState: BridgeState) => { + await this.daemonRpc.setBridgeState(bridgeState); + + // Reset bridge constraints to `any` when the state is set to auto or off + if (bridgeState === 'auto' || bridgeState === 'off') { + await this.daemonRpc.setBridgeSettings(new BridgeSettingsBuilder().location.any().build()); + } + }); IpcMainEventChannel.settings.handleOpenVpnMssfix((mssfix?: number) => this.daemonRpc.setOpenVpnMssfix(mssfix), ); IpcMainEventChannel.settings.handleUpdateRelaySettings((update: RelaySettingsUpdate) => this.daemonRpc.updateRelaySettings(update), ); - IpcMainEventChannel.settings.handleUpdateBridgeLocation((location: RelayLocation) => { - const bridgeSettings: BridgeSettings = { - normal: { - location: { only: location }, - }, - }; - + IpcMainEventChannel.settings.handleUpdateBridgeSettings((bridgeSettings: BridgeSettings) => { return this.daemonRpc.setBridgeSettings(bridgeSettings); }); IpcMainEventChannel.autoStart.handleSet((autoStart: boolean) => { diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index b3c044a44f..69c55d4000 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -38,7 +38,6 @@ import { IWireguardPublicKey, KeygenEvent, liftConstraint, - RelayLocation, RelaySettings, RelaySettingsUpdate, TunnelState, @@ -253,8 +252,8 @@ export default class AppRenderer { return IpcRendererEventChannel.settings.updateRelaySettings(relaySettings); } - public updateBridgeLocation(bridgeLocation: RelayLocation) { - return IpcRendererEventChannel.settings.updateBridgeLocation(bridgeLocation); + public updateBridgeSettings(bridgeSettings: BridgeSettings) { + return IpcRendererEventChannel.settings.updateBridgeSettings(bridgeSettings); } public async removeAccountFromHistory(accountToken: AccountToken): Promise<void> { @@ -550,7 +549,7 @@ export default class AppRenderer { this.reduxActions.connection.newLocation(location); } - private covertRelayListToLocationList(relayList: IRelayList): IRelayLocationRedux[] { + private convertRelayListToLocationList(relayList: IRelayList): IRelayLocationRedux[] { return relayList.countries .map((country) => ({ name: country.name, @@ -573,13 +572,13 @@ export default class AppRenderer { } private setRelays(relayList: IRelayList) { - const locations = this.covertRelayListToLocationList(relayList); + const locations = this.convertRelayListToLocationList(relayList); this.reduxActions.settings.updateRelayLocations(locations); } private setBridges(relayList: IRelayList) { - const locations = this.covertRelayListToLocationList(relayList); + const locations = this.convertRelayListToLocationList(relayList); this.reduxActions.settings.updateBridgeLocations(locations); } diff --git a/gui/src/renderer/components/CityRow.tsx b/gui/src/renderer/components/CityRow.tsx index 9f95aa2289..331c6b9fdd 100644 --- a/gui/src/renderer/components/CityRow.tsx +++ b/gui/src/renderer/components/CityRow.tsx @@ -23,10 +23,8 @@ interface IProps { const styles = { base: Styles.createButtonStyle({ - paddingTop: 0, - paddingBottom: 0, paddingRight: 0, - paddingLeft: 40, + paddingLeft: 32, backgroundColor: colors.blue40, }), selected: Styles.createButtonStyle({ diff --git a/gui/src/renderer/components/CountryRow.tsx b/gui/src/renderer/components/CountryRow.tsx index e468dea109..54e1003736 100644 --- a/gui/src/renderer/components/CountryRow.tsx +++ b/gui/src/renderer/components/CountryRow.tsx @@ -27,10 +27,8 @@ const styles = { flex: 0, }), base: Styles.createViewStyle({ - paddingTop: 0, - paddingBottom: 0, - paddingLeft: 20, paddingRight: 0, + paddingLeft: 16, }), selected: Styles.createViewStyle({ backgroundColor: colors.green, diff --git a/gui/src/renderer/components/RelayRow.tsx b/gui/src/renderer/components/RelayRow.tsx index 5dff0a33f1..35cb1d2be3 100644 --- a/gui/src/renderer/components/RelayRow.tsx +++ b/gui/src/renderer/components/RelayRow.tsx @@ -15,10 +15,8 @@ interface IProps { const styles = { base: Styles.createViewStyle({ - paddingTop: 0, - paddingBottom: 0, paddingRight: 0, - paddingLeft: 60, + paddingLeft: 48, backgroundColor: colors.blue20, }), selected: Styles.createViewStyle({ diff --git a/gui/src/renderer/components/RelayStatusIndicator.tsx b/gui/src/renderer/components/RelayStatusIndicator.tsx index 3409d78331..594dbec141 100644 --- a/gui/src/renderer/components/RelayStatusIndicator.tsx +++ b/gui/src/renderer/components/RelayStatusIndicator.tsx @@ -4,23 +4,19 @@ import { colors } from '../../config.json'; import * as Cell from './Cell'; const styles = { - relay_status: Styles.createViewStyle({ + relayStatus: Styles.createViewStyle({ width: 16, height: 16, borderRadius: 8, - marginLeft: 4, + marginLeft: 12, marginRight: 4, }), - relay_status__inactive: Styles.createViewStyle({ + inactive: Styles.createViewStyle({ backgroundColor: colors.red95, }), - relay_status__active: Styles.createViewStyle({ + active: Styles.createViewStyle({ backgroundColor: colors.green90, }), - tick_icon: Styles.createViewStyle({ - marginLeft: 0, - marginRight: 0, - }), }; interface IProps { @@ -31,20 +27,9 @@ interface IProps { export default class RelayStatusIndicator extends Component<IProps> { public render() { return this.props.isSelected ? ( - <Cell.Icon - style={styles.tick_icon} - tintColor={colors.white} - source="icon-tick" - height={24} - width={24} - /> + <Cell.Icon tintColor={colors.white} source="icon-tick" height={24} width={24} /> ) : ( - <View - style={[ - styles.relay_status, - this.props.isActive ? styles.relay_status__active : styles.relay_status__inactive, - ]} - /> + <View style={[styles.relayStatus, this.props.isActive ? styles.active : styles.inactive]} /> ); } } diff --git a/gui/src/renderer/components/SelectLocation.tsx b/gui/src/renderer/components/SelectLocation.tsx index 2f0a162b51..7a1340c44f 100644 --- a/gui/src/renderer/components/SelectLocation.tsx +++ b/gui/src/renderer/components/SelectLocation.tsx @@ -1,10 +1,12 @@ import * as React from 'react'; import ReactDOM from 'react-dom'; import { Component, View } from 'reactxp'; -import { RelayLocation } from '../../shared/daemon-rpc-types'; +import { colors } from '../../config.json'; +import { LiftedConstraint, RelayLocation } from '../../shared/daemon-rpc-types'; import { messages } from '../../shared/gettext'; import { IRelayLocationRedux } from '../redux/settings/reducers'; import { LocationScope } from '../redux/userinterface/reducers'; +import * as Cell from './Cell'; import CustomScrollbars from './CustomScrollbars'; import { Container, Layout } from './Layout'; import LocationList from './LocationList'; @@ -25,7 +27,7 @@ import SettingsHeader, { HeaderSubTitle, HeaderTitle } from './SettingsHeader'; interface IProps { locationScope: LocationScope; selectedExitLocation?: RelayLocation; - selectedBridgeLocation?: RelayLocation; + selectedBridgeLocation?: LiftedConstraint<RelayLocation>; relayLocations: IRelayLocationRedux[]; bridgeLocations: IRelayLocationRedux[]; allowBridgeSelection: boolean; @@ -33,6 +35,7 @@ interface IProps { onChangeLocationScope: (location: LocationScope) => void; onSelectExitLocation: (location: RelayLocation) => void; onSelectBridgeLocation: (location: RelayLocation) => void; + onSelectClosestToExit: () => void; } export default class SelectLocation extends Component<IProps> { @@ -110,13 +113,25 @@ export default class SelectLocation extends Component<IProps> { onSelect={this.props.onSelectExitLocation} /> ) : ( - <LocationList - key={'bridge-locations'} - ref={this.bridgeLocationList} - selectedLocation={this.props.selectedBridgeLocation} - relayLocations={this.props.bridgeLocations} - onSelect={this.props.onSelectBridgeLocation} - /> + <React.Fragment> + <View> + <ClosestToExitCell + onSelect={this.props.onSelectClosestToExit} + isSelected={this.props.selectedBridgeLocation === 'any'} + /> + </View> + <LocationList + key={'bridge-locations'} + ref={this.bridgeLocationList} + selectedLocation={ + this.props.selectedBridgeLocation !== 'any' + ? this.props.selectedBridgeLocation + : undefined + } + relayLocations={this.props.bridgeLocations} + onSelect={this.props.onSelectBridgeLocation} + /> + </React.Fragment> )} </View> </NavigationScrollbars> @@ -152,3 +167,25 @@ export default class SelectLocation extends Component<IProps> { } } } + +interface IClosestToExitCellProps { + isSelected: boolean; + onSelect: () => void; +} + +function ClosestToExitCell(props: IClosestToExitCellProps) { + return ( + <Cell.CellButton + style={props.isSelected ? styles.selectedCell : undefined} + cellHoverStyle={props.isSelected ? styles.selectedCell : undefined} + onPress={props.onSelect}> + <Cell.Icon + source={props.isSelected ? 'icon-tick' : 'icon-nearest'} + tintColor={colors.white} + height={24} + width={24} + /> + <Cell.Label>{messages.pgettext('select-location-view', 'Closest to exit server')}</Cell.Label> + </Cell.CellButton> + ); +} diff --git a/gui/src/renderer/components/SelectLocationStyles.tsx b/gui/src/renderer/components/SelectLocationStyles.tsx index bc326bb4a7..bfda9c1055 100644 --- a/gui/src/renderer/components/SelectLocationStyles.tsx +++ b/gui/src/renderer/components/SelectLocationStyles.tsx @@ -26,4 +26,7 @@ export default { // NavigationBar already adds some spacing paddingTop: 0, }), + selectedCell: Styles.createViewStyle({ + backgroundColor: colors.green, + }), }; diff --git a/gui/src/renderer/containers/AdvancedSettingsPage.tsx b/gui/src/renderer/containers/AdvancedSettingsPage.tsx index 9440a0077b..8feafe8e58 100644 --- a/gui/src/renderer/containers/AdvancedSettingsPage.tsx +++ b/gui/src/renderer/containers/AdvancedSettingsPage.tsx @@ -3,8 +3,8 @@ import log from 'electron-log'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { BridgeState, RelayProtocol, TunnelProtocol } from '../../shared/daemon-rpc-types'; +import RelaySettingsBuilder from '../../shared/relay-settings-builder'; import AdvancedSettings from '../components/AdvancedSettings'; -import RelaySettingsBuilder from '../lib/relay-settings-builder'; import { RelaySettingsRedux } from '../redux/settings/reducers'; import { IReduxState, ReduxDispatch } from '../redux/store'; diff --git a/gui/src/renderer/containers/SelectLocationPage.tsx b/gui/src/renderer/containers/SelectLocationPage.tsx index 24bae9f24d..85cd29dc09 100644 --- a/gui/src/renderer/containers/SelectLocationPage.tsx +++ b/gui/src/renderer/containers/SelectLocationPage.tsx @@ -2,18 +2,18 @@ import { goBack } from 'connected-react-router'; import log from 'electron-log'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import { RelayLocation } from '../../shared/daemon-rpc-types'; +import BridgeSettingsBuilder from '../../shared/bridge-settings-builder'; +import { LiftedConstraint, RelayLocation } from '../../shared/daemon-rpc-types'; +import RelaySettingsBuilder from '../../shared/relay-settings-builder'; import SelectLocation from '../components/SelectLocation'; -import RelaySettingsBuilder from '../lib/relay-settings-builder'; +import { IReduxState, ReduxDispatch } from '../redux/store'; import userInterfaceActions from '../redux/userinterface/actions'; import { LocationScope } from '../redux/userinterface/reducers'; - -import { IReduxState, ReduxDispatch } from '../redux/store'; import { ISharedRouteProps } from '../routes'; const mapStateToProps = (state: IReduxState) => { let selectedExitLocation: RelayLocation | undefined; - let selectedBridgeLocation: RelayLocation | undefined; + let selectedBridgeLocation: LiftedConstraint<RelayLocation> | undefined; if ('normal' in state.settings.relaySettings) { const exitLocation = state.settings.relaySettings.normal.location; @@ -23,10 +23,7 @@ const mapStateToProps = (state: IReduxState) => { } if ('normal' in state.settings.bridgeSettings) { - const bridgeLocation = state.settings.bridgeSettings.normal.location; - if (bridgeLocation !== 'any') { - selectedBridgeLocation = bridgeLocation; - } + selectedBridgeLocation = state.settings.bridgeSettings.normal.location; } const allowBridgeSelection = state.settings.bridgeState === 'on'; @@ -72,11 +69,23 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: ISharedRouteProps) = history.goBack(); try { - await props.app.updateBridgeLocation(bridgeLocation); + await props.app.updateBridgeSettings( + new BridgeSettingsBuilder().location.fromRaw(bridgeLocation).build(), + ); } catch (e) { log.error(`Failed to select the bridge location: ${e.message}`); } }, + onSelectClosestToExit: async () => { + // dismiss the view first + history.goBack(); + + try { + await props.app.updateBridgeSettings(new BridgeSettingsBuilder().location.any().build()); + } catch (e) { + log.error(`Failed to set the bridge location to closest to exit: ${e.message}`); + } + }, }; }; diff --git a/gui/src/shared/bridge-settings-builder.ts b/gui/src/shared/bridge-settings-builder.ts new file mode 100644 index 0000000000..28e701ec0a --- /dev/null +++ b/gui/src/shared/bridge-settings-builder.ts @@ -0,0 +1,24 @@ +import { BridgeSettings, IBridgeConstraints } from './daemon-rpc-types'; +import makeLocationBuilder, { ILocationBuilder } from './relay-location-builder'; + +export default class BridgeSettingsBuilder { + private payload: Partial<IBridgeConstraints> = {}; + + public build(): BridgeSettings { + if (this.payload.location) { + return { + normal: { + location: this.payload.location, + }, + }; + } else { + throw new Error('Unsupported configuration'); + } + } + + get location(): ILocationBuilder<BridgeSettingsBuilder> { + return makeLocationBuilder(this, (location) => { + this.payload.location = location; + }); + } +} diff --git a/gui/src/shared/ipc-event-channel.ts b/gui/src/shared/ipc-event-channel.ts index 3df81c2eea..2800ab50ea 100644 --- a/gui/src/shared/ipc-event-channel.ts +++ b/gui/src/shared/ipc-event-channel.ts @@ -8,6 +8,7 @@ import { IAppUpgradeInfo, ICurrentAppVersionInfo } from '../main/index'; import { IWindowShapeParameters } from '../main/window-controller'; import { AccountToken, + BridgeSettings, BridgeState, IAccountData, ILocation, @@ -15,7 +16,6 @@ import { ISettings, IWireguardPublicKey, KeygenEvent, - RelayLocation, RelaySettingsUpdate, TunnelState, } from './daemon-rpc-types'; @@ -71,7 +71,7 @@ interface ISettingsMethods extends IReceiver<ISettings> { setBridgeState(state: BridgeState): Promise<void>; setOpenVpnMssfix(mssfix?: number): Promise<void>; updateRelaySettings(update: RelaySettingsUpdate): Promise<void>; - updateBridgeLocation(location: RelayLocation): Promise<void>; + updateBridgeSettings(bridgeSettings: BridgeSettings): Promise<void>; } interface ISettingsHandlers extends ISender<ISettings> { @@ -81,7 +81,7 @@ interface ISettingsHandlers extends ISender<ISettings> { handleBridgeState(fn: (state: BridgeState) => Promise<void>): void; handleOpenVpnMssfix(fn: (mssfix?: number) => Promise<void>): void; handleUpdateRelaySettings(fn: (update: RelaySettingsUpdate) => Promise<void>): void; - handleUpdateBridgeLocation(fn: (location: RelayLocation) => Promise<void>): void; + handleUpdateBridgeSettings(fn: (bridgeSettings: BridgeSettings) => Promise<void>): void; } interface IGuiSettingsMethods extends IReceiver<IGuiSettingsState> { @@ -154,7 +154,7 @@ const SET_BLOCK_WHEN_DISCONNECTED = 'set-block-when-disconnected'; const SET_BRIDGE_STATE = 'set-bridge-state'; const SET_OPENVPN_MSSFIX = 'set-openvpn-mssfix'; const UPDATE_RELAY_SETTINGS = 'update-relay-settings'; -const UPDATE_BRIDGE_LOCATION = 'update-bridge-location'; +const UPDATE_BRIDGE_SETTINGS = 'update-bridge-location'; const LOCATION_CHANGED = 'location-changed'; const RELAYS_CHANGED = 'relays-changed'; @@ -223,7 +223,7 @@ export class IpcRendererEventChannel { setBridgeState: requestSender(SET_BRIDGE_STATE), setOpenVpnMssfix: requestSender(SET_OPENVPN_MSSFIX), updateRelaySettings: requestSender(UPDATE_RELAY_SETTINGS), - updateBridgeLocation: requestSender(UPDATE_BRIDGE_LOCATION), + updateBridgeSettings: requestSender(UPDATE_BRIDGE_SETTINGS), }; public static location: IReceiver<ILocation> = { @@ -313,7 +313,7 @@ export class IpcMainEventChannel { handleBridgeState: requestHandler(SET_BRIDGE_STATE), handleOpenVpnMssfix: requestHandler(SET_OPENVPN_MSSFIX), handleUpdateRelaySettings: requestHandler(UPDATE_RELAY_SETTINGS), - handleUpdateBridgeLocation: requestHandler(UPDATE_BRIDGE_LOCATION), + handleUpdateBridgeSettings: requestHandler(UPDATE_BRIDGE_SETTINGS), }; public static relays: ISender<IRelayListPair> = { diff --git a/gui/src/shared/relay-location-builder.ts b/gui/src/shared/relay-location-builder.ts new file mode 100644 index 0000000000..14bf72b65f --- /dev/null +++ b/gui/src/shared/relay-location-builder.ts @@ -0,0 +1,41 @@ +import { Constraint, LiftedConstraint, RelayLocation } from './daemon-rpc-types'; + +export interface ILocationBuilder<Self> { + country(country: string): Self; + city(country: string, city: string): Self; + hostname(country: string, city: string, hostname: string): Self; + any(): Self; + fromRaw(location: LiftedConstraint<RelayLocation>): Self; +} + +export default function makeLocationBuilder<T>( + context: T, + receiver: (constraint: Constraint<RelayLocation>) => void, +): ILocationBuilder<T> { + return { + country: (country: string) => { + receiver({ only: { country } }); + return context; + }, + city: (country: string, city: string) => { + receiver({ only: { city: [country, city] } }); + return context; + }, + hostname: (country: string, city: string, hostname: string) => { + receiver({ only: { hostname: [country, city, hostname] } }); + return context; + }, + any: () => { + receiver('any'); + return context; + }, + fromRaw(location: LiftedConstraint<RelayLocation>) { + if (location === 'any') { + return this.any(); + } else { + receiver({ only: location }); + return context; + } + }, + }; +} diff --git a/gui/src/renderer/lib/relay-settings-builder.ts b/gui/src/shared/relay-settings-builder.ts index 344ddff267..182e44063f 100644 --- a/gui/src/renderer/lib/relay-settings-builder.ts +++ b/gui/src/shared/relay-settings-builder.ts @@ -2,21 +2,12 @@ import { Constraint, IOpenVpnConstraints, IWireguardConstraints, - LiftedConstraint, - RelayLocation, RelayProtocol, RelaySettingsNormalUpdate, RelaySettingsUpdate, TunnelProtocol, -} from '../../shared/daemon-rpc-types'; - -interface ILocationBuilder<Self> { - country: (country: string) => Self; - city: (country: string, city: string) => Self; - hostname: (country: string, city: string, hostname: string) => Self; - any: () => Self; - fromRaw: (location: LiftedConstraint<RelayLocation>) => Self; -} +} from './daemon-rpc-types'; +import makeLocationBuilder, { ILocationBuilder } from './relay-location-builder'; interface IExactOrAny<T, Self> { exact(value: T): Self; @@ -58,41 +49,9 @@ class NormalRelaySettingsBuilder { } get location(): ILocationBuilder<NormalRelaySettingsBuilder> { - return { - country: (country: string) => { - this.payload.location = { only: { country } }; - return this; - }, - city: (country: string, city: string) => { - this.payload.location = { only: { city: [country, city] } }; - return this; - }, - hostname: (country: string, city: string, hostname: string) => { - this.payload.location = { only: { hostname: [country, city, hostname] } }; - return this; - }, - any: () => { - this.payload.location = 'any'; - return this; - }, - fromRaw(location: LiftedConstraint<RelayLocation>) { - if (location === 'any') { - return this.any(); - } else if ('hostname' in location) { - const [country, city, hostname] = location.hostname; - return this.hostname(country, city, hostname); - } else if ('city' in location) { - const [country, city] = location.city; - return this.city(country, city); - } else if ('country' in location) { - return this.country(location.country); - } - - throw new Error( - 'Unsupported value of RelayLocation' + (location && JSON.stringify(location)), - ); - }, - }; + return makeLocationBuilder(this, (location) => { + this.payload.location = location; + }); } get tunnel(): ITunnelBuilder { diff --git a/gui/test/relay-settings-builder.spec.ts b/gui/test/relay-settings-builder.spec.ts index f9ceccd744..009ddfa301 100644 --- a/gui/test/relay-settings-builder.spec.ts +++ b/gui/test/relay-settings-builder.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { it, describe } from 'mocha'; -import RelaySettingsBuilder from '../src/renderer/lib/relay-settings-builder'; +import RelaySettingsBuilder from '../src/shared/relay-settings-builder'; describe('Relay settings builder', () => { it('should set location to any', () => { |
