summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/src/renderer/app.tsx57
-rw-r--r--gui/src/renderer/redux/connection/actions.ts4
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,