diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-03-05 14:13:30 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-03-07 13:48:30 +0100 |
| commit | a6aaf3d9b2f36ddcaf3361d558e6ee029e4843ac (patch) | |
| tree | c8b64c9c3f11a0b8636052361a38fa23402bf7a4 /gui/src | |
| parent | 18281d38f396e40e7c7bed58d922bdb79196c061 (diff) | |
| download | mullvadvpn-a6aaf3d9b2f36ddcaf3361d558e6ee029e4843ac.tar.xz mullvadvpn-a6aaf3d9b2f36ddcaf3361d558e6ee029e4843ac.zip | |
Take into account the block_when_connected setting to determine if the connection is blocked
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/app.tsx | 30 | ||||
| -rw-r--r-- | gui/src/renderer/redux/connection/actions.ts | 16 | ||||
| -rw-r--r-- | gui/src/renderer/redux/connection/reducers.ts | 12 |
3 files changed, 51 insertions, 7 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 079f9be5df..51b2983bcd 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -101,6 +101,7 @@ export default class AppRenderer { IpcRendererEventChannel.tunnel.listen((newState: TunnelStateTransition) => { this.setTunnelState(newState); + this.updateBlockedState(newState, this.settings.blockWhenDisconnected); }); IpcRendererEventChannel.settings.listen((newSettings: ISettings) => { @@ -108,6 +109,7 @@ export default class AppRenderer { this.setSettings(newSettings); this.handleAccountChange(oldSettings.accountToken, newSettings.accountToken); + this.updateBlockedState(this.tunnelState, newSettings.blockWhenDisconnected); }); IpcRendererEventChannel.location.listen((newLocation: ILocation) => { @@ -142,8 +144,9 @@ export default class AppRenderer { this.guiSettings = initialState.guiSettings; this.setAccountHistory(initialState.accountHistory); - this.setTunnelState(initialState.tunnelState); this.setSettings(initialState.settings); + this.setTunnelState(initialState.tunnelState); + this.updateBlockedState(initialState.tunnelState, initialState.settings.blockWhenDisconnected); if (initialState.location) { this.setLocation(initialState.location); @@ -478,6 +481,31 @@ export default class AppRenderer { } } + private updateBlockedState(tunnelState: TunnelStateTransition, blockWhenDisconnected: boolean) { + const actions = this.reduxActions.connection; + switch (tunnelState.state) { + case 'connecting': + actions.updateBlockState(true); + break; + + case 'connected': + actions.updateBlockState(false); + break; + + case 'disconnected': + actions.updateBlockState(blockWhenDisconnected); + break; + + case 'disconnecting': + actions.updateBlockState(true); + break; + + case 'blocked': + actions.updateBlockState(tunnelState.details.reason !== 'set_firewall_policy_error'); + break; + } + } + private handleAccountChange(oldAccount?: string, newAccount?: string) { if (oldAccount && !newAccount) { this.accountDataCache.invalidate(); diff --git a/gui/src/renderer/redux/connection/actions.ts b/gui/src/renderer/redux/connection/actions.ts index 5966635a2e..b84e85f8e6 100644 --- a/gui/src/renderer/redux/connection/actions.ts +++ b/gui/src/renderer/redux/connection/actions.ts @@ -34,13 +34,19 @@ interface INewLocationAction { newLocation: ILocation; } +interface IUpdateBlockStateAction { + type: 'UPDATE_BLOCK_STATE'; + isBlocked: boolean; +} + export type ConnectionAction = | INewLocationAction | IConnectingAction | IConnectedAction | IDisconnectedAction | IDisconnectingAction - | IBlockedAction; + | IBlockedAction + | IUpdateBlockStateAction; function connecting(tunnelEndpoint?: ITunnelEndpoint): IConnectingAction { return { @@ -83,8 +89,16 @@ function newLocation(location: ILocation): INewLocationAction { }; } +function updateBlockState(isBlocked: boolean): IUpdateBlockStateAction { + return { + type: 'UPDATE_BLOCK_STATE', + isBlocked, + }; +} + export default { newLocation, + updateBlockState, connecting, connected, disconnected, diff --git a/gui/src/renderer/redux/connection/reducers.ts b/gui/src/renderer/redux/connection/reducers.ts index 3d1098b9d2..a0918f53ee 100644 --- a/gui/src/renderer/redux/connection/reducers.ts +++ b/gui/src/renderer/redux/connection/reducers.ts @@ -31,35 +31,37 @@ export default function( case 'NEW_LOCATION': return { ...state, ...action.newLocation }; + case 'UPDATE_BLOCK_STATE': + return { ...state, isBlocked: action.isBlocked }; + case 'CONNECTING': return { ...state, status: { state: 'connecting', details: action.tunnelEndpoint }, - isBlocked: true, }; case 'CONNECTED': return { ...state, status: { state: 'connected', details: action.tunnelEndpoint }, - isBlocked: false, }; case 'DISCONNECTED': - return { ...state, status: { state: 'disconnected' }, isBlocked: false }; + return { + ...state, + status: { state: 'disconnected' }, + }; case 'DISCONNECTING': return { ...state, status: { state: 'disconnecting', details: action.afterDisconnect }, - isBlocked: true, }; case 'BLOCKED': return { ...state, status: { state: 'blocked', details: action.reason }, - isBlocked: action.reason.reason !== 'set_firewall_policy_error', }; default: |
