summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-07-28 07:28:10 +0200
committerErik Larkö <erik@mullvad.net>2017-08-08 11:47:05 +0200
commitc6f83d7793bc5f50cef7f708ccb7da7601291a23 (patch)
tree20ba7483b2db7cf5947af66c5efabfa0d21b23fd /app
parent63edffdd0def243f5087039ddaaf3aba3572d8f6 (diff)
downloadmullvadvpn-c6f83d7793bc5f50cef7f708ccb7da7601291a23.tar.xz
mullvadvpn-c6f83d7793bc5f50cef7f708ccb7da7601291a23.zip
RPC notification actions
Diffstat (limited to 'app')
-rw-r--r--app/lib/backend.js14
-rw-r--r--app/redux/connection/actions.js26
-rw-r--r--app/redux/connection/reducers.js24
3 files changed, 54 insertions, 10 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index 02ab2717f0..e8c8cbd464 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -276,9 +276,17 @@ export class Backend {
log.info('Got new state from backend', newState);
const newStatus = this._securityStateToConnectionState(newState);
- this._store.dispatch(connectionActions.connectionChange({
- status: newStatus,
- }));
+ switch(newStatus) {
+ case 'connecting':
+ this._store.dispatch(connectionActions.connecting());
+ break;
+ case 'connected':
+ this._store.dispatch(connectionActions.connected());
+ break;
+ case 'disconnected':
+ this._store.dispatch(connectionActions.disconnected());
+ break;
+ }
this.sync();
});
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index e334cfd63b..e7fd03bc77 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -22,7 +22,10 @@ const copyIPAddress = () => {
type ConnectingAction = {
type: 'CONNECTING',
- serverAddress: string,
+ serverAddress?: string,
+};
+type ConnectedAction = {
+ type: 'CONNECTED',
};
type DisconnectedAction = {
type: 'DISCONNECTED',
@@ -49,7 +52,12 @@ type NewLocationAction = {
newLocation: Location,
};
-export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction | NewLocationAction | ConnectingAction | DisconnectedAction;
+export type ConnectionAction = ConnectionChangeAction
+ | NewPublicIpAction
+ | NewLocationAction
+ | ConnectingAction
+ | ConnectedAction
+ | DisconnectedAction;
function connectingTo(serverAddress: string): ConnectingAction {
return {
@@ -58,6 +66,18 @@ function connectingTo(serverAddress: string): ConnectingAction {
};
}
+function connecting(): ConnectingAction {
+ return {
+ type: 'CONNECTING',
+ };
+}
+
+function connected(): ConnectedAction {
+ return {
+ type: 'CONNECTED',
+ };
+}
+
function disconnected(): DisconnectedAction {
return {
type: 'DISCONNECTED',
@@ -86,5 +106,5 @@ function newLocation(newLoc: Location): NewLocationAction {
}
-export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp, newLocation, connectingTo, disconnected };
+export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp, newLocation, connectingTo, connecting, connected, disconnected };
diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js
index d454e1bc4a..457a6c1bd6 100644
--- a/app/redux/connection/reducers.js
+++ b/app/redux/connection/reducers.js
@@ -30,18 +30,34 @@ export default function(state: ConnectionReduxState = initialState, action: Redu
switch (action.type) {
case 'CONNECTION_CHANGE':
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,
- }};
+ return onConnecting(state, action);
+
+ case 'CONNECTED':
+ return { ...state, ...{ status: 'connected' }};
+
case 'DISCONNECTED':
return { ...state, ...{ status: 'disconnected' }};
+
default:
return state;
}
}
+
+function onConnecting(state, action) {
+ const newState: $Shape<ConnectionReduxState> = {
+ status: 'connecting',
+ };
+
+ if (action.serverAddress) {
+ newState.serverAddress = action.serverAddress;
+ }
+ return { ...state, ...newState};
+}