diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-08-03 15:35:02 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-08-08 16:25:34 +0200 |
| commit | 7cb837912df646992f63ad5ff61c26871f5c24b8 (patch) | |
| tree | f31bcc566d378cbb7ede9172c57e45a7322e67bf | |
| parent | 96e45e1243ea48661987a0724ce10f9a2da7f106 (diff) | |
| download | mullvadvpn-7cb837912df646992f63ad5ff61c26871f5c24b8.tar.xz mullvadvpn-7cb837912df646992f63ad5ff61c26871f5c24b8.zip | |
Save daemon connectivity status to redux
| -rw-r--r-- | app/app.js | 11 | ||||
| -rw-r--r-- | app/redux/daemon/actions.js | 24 | ||||
| -rw-r--r-- | app/redux/daemon/reducers.js | 33 | ||||
| -rw-r--r-- | app/redux/store.js | 14 |
4 files changed, 81 insertions, 1 deletions
diff --git a/app/app.js b/app/app.js index de60873dae..6a465e0867 100644 --- a/app/app.js +++ b/app/app.js @@ -23,6 +23,7 @@ import configureStore from './redux/store'; import accountActions from './redux/account/actions'; import connectionActions from './redux/connection/actions'; import settingsActions from './redux/settings/actions'; +import daemonActions from './redux/daemon/actions'; import type { RpcCredentials } from './lib/rpc-address-file'; import type { @@ -54,6 +55,7 @@ export default class AppRenderer { account: bindActionCreators(accountActions, dispatch), connection: bindActionCreators(connectionActions, dispatch), settings: bindActionCreators(settingsActions, dispatch), + daemon: bindActionCreators(daemonActions, dispatch), history: bindActionCreators( { push: pushHistory, @@ -380,6 +382,9 @@ export default class AppRenderer { } async _onOpenConnection() { + // save to redux that the app connected to daemon + this._reduxActions.daemon.connected(); + this._reconnectBackoff.reset(); // authenticate once connected @@ -427,6 +432,12 @@ export default class AppRenderer { } async _onCloseConnection(error: ?Error) { + const actions = this._reduxActions; + + // save to redux that the app disconnected from daemon + actions.daemon.disconnected(); + + // recover connection on error if (error) { log.debug(`Lost connection to daemon: ${error.message}`); diff --git a/app/redux/daemon/actions.js b/app/redux/daemon/actions.js new file mode 100644 index 0000000000..904cb3bd61 --- /dev/null +++ b/app/redux/daemon/actions.js @@ -0,0 +1,24 @@ +// @flow + +export type DaemonConnectedAction = { + type: 'DAEMON_CONNECTED', +}; +export type DaemonDisconnectedAction = { + type: 'DAEMON_DISCONNECTED', +}; + +export type DaemonAction = DaemonConnectedAction | DaemonDisconnectedAction; + +function connected(): DaemonConnectedAction { + return { + type: 'DAEMON_CONNECTED', + }; +} + +function disconnected(): DaemonDisconnectedAction { + return { + type: 'DAEMON_DISCONNECTED', + }; +} + +export default { connected, disconnected }; diff --git a/app/redux/daemon/reducers.js b/app/redux/daemon/reducers.js new file mode 100644 index 0000000000..5e9e707ff6 --- /dev/null +++ b/app/redux/daemon/reducers.js @@ -0,0 +1,33 @@ +// @flow + +import type { ReduxAction } from '../store'; + +export type DaemonReduxState = { + isConnected: boolean, +}; + +const initialState: DaemonReduxState = { + isConnected: false, +}; + +export default function( + state: DaemonReduxState = initialState, + action: ReduxAction, +): DaemonReduxState { + switch (action.type) { + case 'DAEMON_CONNECTED': + return { + ...state, + isConnected: true, + }; + + case 'DAEMON_DISCONNECTED': + return { + ...state, + isConnected: false, + }; + + default: + return state; + } +} diff --git a/app/redux/store.js b/app/redux/store.js index 8afe22d716..e269d9902b 100644 --- a/app/redux/store.js +++ b/app/redux/store.js @@ -11,6 +11,8 @@ import settings from './settings/reducers'; import settingsActions from './settings/actions'; import support from './support/reducers'; import supportActions from './support/actions'; +import daemon from './daemon/reducers'; +import daemonActions from './daemon/actions'; import type { Store, StoreEnhancer } from 'redux'; import type { History } from 'history'; @@ -18,20 +20,28 @@ import type { AccountReduxState } from './account/reducers'; import type { ConnectionReduxState } from './connection/reducers'; import type { SettingsReduxState } from './settings/reducers'; import type { SupportReduxState } from './support/reducers'; +import type { DaemonReduxState } from './daemon/reducers'; import type { AccountAction } from './account/actions'; import type { ConnectionAction } from './connection/actions'; import type { SettingsAction } from './settings/actions'; import type { SupportAction } from './support/actions'; +import type { DaemonAction } from './daemon/actions'; export type ReduxState = { account: AccountReduxState, connection: ConnectionReduxState, settings: SettingsReduxState, support: SupportReduxState, + daemon: DaemonReduxState, }; -export type ReduxAction = AccountAction | ConnectionAction | SettingsAction | SupportAction; +export type ReduxAction = + | AccountAction + | ConnectionAction + | SettingsAction + | SupportAction + | DaemonAction; export type ReduxStore = Store<ReduxState, ReduxAction, ReduxDispatch>; export type ReduxGetState = () => ReduxState; export type ReduxDispatch = (action: ReduxAction | ReduxThunk) => any; @@ -48,6 +58,7 @@ export default function configureStore( ...connectionActions, ...settingsActions, ...supportActions, + ...daemonActions, pushRoute: (route) => push(route), replaceRoute: (route) => replace(route), }; @@ -57,6 +68,7 @@ export default function configureStore( connection, settings, support, + daemon, }; const middlewares = [thunk, router]; |
