summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-02-28 16:58:06 +0000
committerAndrej Mihajlov <and@codeispoetry.ru>2017-02-28 16:58:06 +0000
commitca00a523ad65a0d4269b74675f8d2ffa0aec2de0 (patch)
treef71751148613e7b3036d321c243fb8a55171c429 /app
parent04b50f53e5d2e5941e934e6a76764f835e8afdd3 (diff)
downloadmullvadvpn-ca00a523ad65a0d4269b74675f8d2ffa0aec2de0.tar.xz
mullvadvpn-ca00a523ad65a0d4269b74675f8d2ffa0aec2de0.zip
Move backend patch for redux into Backend object
Diffstat (limited to 'app')
-rw-r--r--app/app.js27
-rw-r--r--app/lib/backend.js27
2 files changed, 28 insertions, 26 deletions
diff --git a/app/app.js b/app/app.js
index 821ceb42c2..369cd6cebb 100644
--- a/app/app.js
+++ b/app/app.js
@@ -53,31 +53,8 @@ const updateTrayIcon = () => {
ipcRenderer.send('changeTrayIcon', getName(connect.status));
};
-/**
- * Patch backend state.
- *
- * Currently backend does not have external state
- * such as VPN connection status or IP address.
- *
- * So far we store everything in redux and have to
- * sync redux state with backend.
- *
- * In future this will be the other way around.
- */
-const syncBackendWithReduxStore = (backend, store) => {
- const mapConnStatus = (s) => {
- const S = ConnectionState;
- const BS = Backend.ConnectionState;
- switch(s) {
- case S.connected: return BS.connected;
- case S.connecting: return BS.connecting;
- default: return BS.disconnected;
- }
- };
- const { connect } = store.getState();
- backend._connStatus = mapConnStatus(connect.status);
-};
-syncBackendWithReduxStore(backend, store);
+// patch backend
+backend.syncWithReduxStore(backend, store);
// Setup primary event handlers to translate backend events into redux dispatch
mapBackendEventsToReduxActions(backend, store);
diff --git a/app/lib/backend.js b/app/lib/backend.js
index d028f4f8fe..adec32fdd4 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -1,6 +1,6 @@
import Enum from './enum';
import { EventEmitter } from 'events';
-import { servers } from '../constants';
+import { ConnectionState as ReduxConnectionState, servers } from '../constants';
const EventType = Enum('connect', 'connecting', 'disconnect', 'login', 'logging', 'logout', 'updatedIp');
const ConnectionState = Enum('disconnected', 'connecting', 'connected');
@@ -33,6 +33,31 @@ export default class Backend extends EventEmitter {
// Public methods
+ /**
+ * Patch backend state.
+ *
+ * Currently backend does not have external state
+ * such as VPN connection status or IP address.
+ *
+ * So far we store everything in redux and have to
+ * sync redux state with backend.
+ *
+ * In future this will be the other way around.
+ */
+ syncWithReduxStore(store) {
+ const mapConnStatus = (s) => {
+ const S = ReduxConnectionState;
+ const BS = ConnectionState;
+ switch(s) {
+ case S.connected: return BS.connected;
+ case S.connecting: return BS.connecting;
+ default: return BS.disconnected;
+ }
+ };
+ const { connect } = store.getState();
+ this._connStatus = mapConnStatus(connect.status);
+ }
+
serverInfo(key) {
switch(key) {
case 'fastest': return this.fastestServer();