summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-08-31 15:52:52 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-08-31 16:20:11 +0200
commitdac8d27670b706f87cce30c491c740928fc13c69 (patch)
tree1d32e5d837f7b801338828abc6b2ea91a2b881a4
parent38fc57b05d11237588ab3ad3cf503925923e7fad (diff)
downloadmullvadvpn-dac8d27670b706f87cce30c491c740928fc13c69.tar.xz
mullvadvpn-dac8d27670b706f87cce30c491c740928fc13c69.zip
Reset location to constraints when connecting or reconnecting
-rw-r--r--gui/src/renderer/app.tsx33
-rw-r--r--gui/src/renderer/redux/connection/actions.ts4
2 files changed, 35 insertions, 2 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx
index c468ab12a5..28d2c8b480 100644
--- a/gui/src/renderer/app.tsx
+++ b/gui/src/renderer/app.tsx
@@ -332,6 +332,7 @@ 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();
@@ -356,6 +357,7 @@ export default class AppRenderer {
// 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();
@@ -603,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,