diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-07-03 17:18:35 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-07-07 09:47:39 +0200 |
| commit | 3bb382007158db2c11c390bdde4efceffe861575 (patch) | |
| tree | 45cfbec02378e55c7bb9e5a0ebbb98da1a5150d7 /app/lib/backend.js | |
| parent | db78c15f3445899bc0760bfea5194ae1d7896f47 (diff) | |
| download | mullvadvpn-3bb382007158db2c11c390bdde4efceffe861575.tar.xz mullvadvpn-3bb382007158db2c11c390bdde4efceffe861575.zip | |
Add tests for the notifcation states AND add the getState endpoint. No tests for it though
Diffstat (limited to 'app/lib/backend.js')
| -rw-r--r-- | app/lib/backend.js | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index 377e27e702..a253595926 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -9,6 +9,9 @@ import connectionActions from '../redux/connection/actions'; import type { ReduxStore } from '../redux/store'; import { push } from 'react-router-redux'; +import type { BackendState } from './ipc-facade'; +import type { ConnectionState } from '../redux/connection/reducers'; + export type EventType = 'connect' | 'connecting' | 'disconnect' | 'login' | 'logging' | 'logout' | 'updatedIp' | 'updatedLocation' | 'updatedReachability'; export type ErrorType = 'NO_CREDIT' | 'NO_INTERNET' | 'INVALID_ACCOUNT'; @@ -280,9 +283,26 @@ export class Backend { } _registerIpcListeners() { - /*this._ipc.on('connection-info', (newConnectionInfo) => { - log.info('Got new connection info from backend', newConnectionInfo); - });*/ + this._ipc.registerStateListener(newState => { + log.info('Got new state from backend', newState); + + const newStatus = this._backendStateToConnectionState(newState); + this._store.dispatch(connectionActions.connectionChange({ + status: newStatus, + })); + }); + } + + _backendStateToConnectionState(backendState: BackendState): ConnectionState { + switch(backendState) { + case 'unsecured': + return 'disconnected'; + case 'secured': + return 'connected'; + + default: + throw new Error('Unknown backend state: ' + backendState); + } } on(event: EventType, listener: Function) { |
