diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-08-31 16:20:25 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-08-31 16:20:25 +0200 |
| commit | ef7c3ca7e712354376cb7994264bd2dc5371bc90 (patch) | |
| tree | 1d32e5d837f7b801338828abc6b2ea91a2b881a4 /gui/src | |
| parent | aaebbfbc932a2412ac33571ca194d26382f2082b (diff) | |
| parent | dac8d27670b706f87cce30c491c740928fc13c69 (diff) | |
| download | mullvadvpn-ef7c3ca7e712354376cb7994264bd2dc5371bc90.tar.xz mullvadvpn-ef7c3ca7e712354376cb7994264bd2dc5371bc90.zip | |
Merge branch 'fix-tunnel-control'
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/app.tsx | 57 | ||||
| -rw-r--r-- | gui/src/renderer/redux/connection/actions.ts | 4 |
2 files changed, 55 insertions, 6 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 5cb32d3517..28d2c8b480 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -332,18 +332,36 @@ export default class AppRenderer { // connect only if tunnel is disconnected or blocked. if (state === 'disconnecting' || state === 'disconnected' || state === 'error') { // switch to the connecting state ahead of time to make the app look more responsive + this.resetLocationToConstraints(); this.reduxActions.connection.connecting(); return IpcRendererEventChannel.tunnel.connect(); } } - public disconnectTunnel(): Promise<void> { - return IpcRendererEventChannel.tunnel.disconnect(); + public async disconnectTunnel(): Promise<void> { + const state = this.tunnelState.state; + + // disconnect only if tunnel is connected, connecting or blocked. + if (state === 'connecting' || state === 'connected' || state === 'error') { + // switch to the disconnecting state ahead of time to make the app look more responsive + this.reduxActions.connection.disconnecting('nothing'); + + return IpcRendererEventChannel.tunnel.disconnect(); + } } - public reconnectTunnel(): Promise<void> { - return IpcRendererEventChannel.tunnel.reconnect(); + public async reconnectTunnel(): Promise<void> { + const state = this.tunnelState.state; + + // reconnect only if tunnel is connected or connecting. + if (state === 'connecting' || state === 'connected') { + // switch to the connecting state ahead of time to make the app look more responsive + this.resetLocationToConstraints(); + this.reduxActions.connection.connecting(); + + return IpcRendererEventChannel.tunnel.reconnect(); + } } public updateRelaySettings(relaySettings: RelaySettingsUpdate) { @@ -587,6 +605,37 @@ export default class AppRenderer { this.reduxActions.userInterface.updateLocale(locale); } + private resetLocationToConstraints() { + const relaySettings = this.settings.relaySettings; + if ('normal' in relaySettings) { + const location = relaySettings.normal.location; + if (location !== 'any' && 'only' in location) { + const constraint = location.only; + + const relayLocations = this.reduxStore.getState().settings.relayLocations; + if ('country' in constraint) { + const country = relayLocations.find(({ code }) => constraint.country === code); + + this.reduxActions.connection.newLocation({ country: country?.name }); + } else if ('city' in constraint) { + const country = relayLocations.find(({ code }) => constraint.city[0] === code); + const city = country?.cities.find(({ code }) => constraint.city[1] === code); + + this.reduxActions.connection.newLocation({ country: country?.name, city: city?.name }); + } else if ('hostname' in constraint) { + const country = relayLocations.find(({ code }) => constraint.hostname[0] === code); + const city = country?.cities.find((location) => location.code === constraint.hostname[1]); + + this.reduxActions.connection.newLocation({ + country: country?.name, + city: city?.name, + hostname: constraint.hostname[2], + }); + } + } + } + } + private setRelaySettings(relaySettings: RelaySettings) { const actions = this.reduxActions; diff --git a/gui/src/renderer/redux/connection/actions.ts b/gui/src/renderer/redux/connection/actions.ts index 95d2332ed3..20c63d433d 100644 --- a/gui/src/renderer/redux/connection/actions.ts +++ b/gui/src/renderer/redux/connection/actions.ts @@ -31,7 +31,7 @@ interface IBlockedAction { interface INewLocationAction { type: 'NEW_LOCATION'; - newLocation: ILocation; + newLocation: Partial<ILocation>; } interface IUpdateBlockStateAction { @@ -82,7 +82,7 @@ function blocked(errorState: IErrorState): IBlockedAction { }; } -function newLocation(location: ILocation): INewLocationAction { +function newLocation(location: Partial<ILocation>): INewLocationAction { return { type: 'NEW_LOCATION', newLocation: location, |
