summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-08-08 11:44:36 +0200
committerErik Larkö <erik@mullvad.net>2017-08-08 11:44:36 +0200
commit63edffdd0def243f5087039ddaaf3aba3572d8f6 (patch)
treead3d00bd6693b857950e06221d6d20cc7a98f191 /app
parentd375be8e56975d57f1ca67f28459609de6c10fa5 (diff)
parent9696131150239b8dabbff0eb2fcd3256cbc762c8 (diff)
downloadmullvadvpn-63edffdd0def243f5087039ddaaf3aba3572d8f6.tar.xz
mullvadvpn-63edffdd0def243f5087039ddaaf3aba3572d8f6.zip
Merge branch 'connection-actions'
Diffstat (limited to 'app')
-rw-r--r--app/lib/backend.js15
-rw-r--r--app/redux/connection/actions.js45
-rw-r--r--app/redux/connection/reducers.js9
3 files changed, 57 insertions, 12 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index bc6eeeb8ff..02ab2717f0 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -112,7 +112,7 @@ export class Backend {
country: location.country,
city: location.city
};
- this._store.dispatch(connectionActions.connectionChange(newLocation));
+ this._store.dispatch(connectionActions.newLocation(newLocation));
})
.catch(e => {
log.info('Failed getting new location', e);
@@ -227,23 +227,18 @@ export class Backend {
});
}
- connect(addr: string) {
+ connect(addr: string): Promise<void> {
- this._store.dispatch(connectionActions.connectionChange({
- status: 'connecting',
- serverAddress: addr,
- }));
+ this._store.dispatch(connectionActions.connectingTo(addr));
- this._ipc.setCountry(addr)
+ return this._ipc.setCountry(addr)
.then( () => {
return this._ipc.connect();
})
.catch(e => {
log.info('Failed connecting to', addr, e);
- this._store.dispatch(connectionActions.connectionChange({
- status: 'disconnected',
- }));
+ this._store.dispatch(connectionActions.disconnected());
});
}
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index 142feb9d79..e334cfd63b 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -5,6 +5,7 @@ import { clipboard } from 'electron';
import type { Backend } from '../../lib/backend';
import type { ConnectionReduxState } from './reducers.js';
import type { ReduxGetState, ReduxDispatch } from '../store';
+import type { Coordinate2d } from '../../types';
const connect = (backend: Backend, addr: string) => () => backend.connect(addr);
@@ -19,16 +20,49 @@ const copyIPAddress = () => {
};
+type ConnectingAction = {
+ type: 'CONNECTING',
+ serverAddress: string,
+};
+type DisconnectedAction = {
+ type: 'DISCONNECTED',
+};
type ConnectionChangeAction = {
type: 'CONNECTION_CHANGE',
newData: $Shape<ConnectionReduxState>,
};
+
type NewPublicIpAction = {
type: 'NEW_PUBLIC_IP',
ip: string,
};
-export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction;
+
+type Location = {
+ location: Coordinate2d,
+ country: string,
+ city: string,
+};
+
+type NewLocationAction = {
+ type: 'NEW_LOCATION',
+ newLocation: Location,
+};
+
+export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction | NewLocationAction | ConnectingAction | DisconnectedAction;
+
+function connectingTo(serverAddress: string): ConnectingAction {
+ return {
+ type: 'CONNECTING',
+ serverAddress: serverAddress,
+ };
+}
+
+function disconnected(): DisconnectedAction {
+ return {
+ type: 'DISCONNECTED',
+ };
+}
function connectionChange(newData: $Shape<ConnectionReduxState>): ConnectionChangeAction {
return {
@@ -44,6 +78,13 @@ function newPublicIp(ip: string): NewPublicIpAction {
};
}
+function newLocation(newLoc: Location): NewLocationAction {
+ return {
+ type: 'NEW_LOCATION',
+ newLocation: newLoc,
+ };
+}
+
+export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp, newLocation, connectingTo, disconnected };
-export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp };
diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js
index 2426f7eddd..d454e1bc4a 100644
--- a/app/redux/connection/reducers.js
+++ b/app/redux/connection/reducers.js
@@ -32,6 +32,15 @@ export default function(state: ConnectionReduxState = initialState, action: Redu
return { ...state, ...action.newData };
case 'NEW_PUBLIC_IP':
return { ...state, ...{ clientIp: action.ip }};
+ case 'NEW_LOCATION':
+ return { ...state, ...action.newLocation };
+ case 'CONNECTING':
+ return { ...state, ...{
+ status: 'connecting',
+ serverAddress: action.serverAddress,
+ }};
+ case 'DISCONNECTED':
+ return { ...state, ...{ status: 'disconnected' }};
default:
return state;
}