summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2018-01-08 13:35:27 +0100
committerErik Larkö <erik@mullvad.net>2018-01-09 14:21:16 +0100
commit2707a2919eb4cc087695dbca12d5d6c74975c30a (patch)
tree2c996a62dc0c6fbd39204bd4c5b8b899d3d39a14
parente7defa271e70fe7a145daedb17597115d2ca52d4 (diff)
downloadmullvadvpn-2707a2919eb4cc087695dbca12d5d6c74975c30a.tar.xz
mullvadvpn-2707a2919eb4cc087695dbca12d5d6c74975c30a.zip
Read the backend security state when starting to talk to the backend
-rw-r--r--app/app.js1
-rw-r--r--app/lib/backend.js34
2 files changed, 24 insertions, 11 deletions
diff --git a/app/app.js b/app/app.js
index e84a577223..3a9d6c0294 100644
--- a/app/app.js
+++ b/app/app.js
@@ -28,6 +28,7 @@ ipcRenderer.on('backend-info', async (_event, args) => {
try {
await backend.autologin();
await backend.fetchRelaySettings();
+ await backend.fetchSecurityState();
await backend.connect();
} catch (e) {
if(e instanceof BackendError) {
diff --git a/app/lib/backend.js b/app/lib/backend.js
index da87deced4..62babdf4b6 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -421,6 +421,14 @@ export class Backend {
);
}
+ async fetchSecurityState() {
+ await this._ensureAuthenticated();
+
+ const securityState = await this._ipc.getState();
+ const connectionState = this._securityStateToConnectionState(securityState);
+ this._dispatchConnectionState(connectionState);
+ }
+
/**
* Start reachability monitoring for online/offline detection
* This is currently done via HTML5 APIs but will be replaced later
@@ -452,17 +460,7 @@ export class Backend {
log.debug('Got new state from backend', newState);
const newStatus = this._securityStateToConnectionState(newState);
- 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._dispatchConnectionState(newStatus);
this.sync();
});
}
@@ -478,6 +476,20 @@ export class Backend {
throw new Error('Unsupported state/target state combination: ' + JSON.stringify(backendState));
}
+ _dispatchConnectionState(connectionState: ConnectionState) {
+ switch(connectionState) {
+ case 'connecting':
+ this._store.dispatch(connectionActions.connecting());
+ break;
+ case 'connected':
+ this._store.dispatch(connectionActions.connected());
+ break;
+ case 'disconnected':
+ this._store.dispatch(connectionActions.disconnected());
+ break;
+ }
+ }
+
_ensureAuthenticated() {
const credentials = this._credentials;
if(credentials) {