summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2017-11-30 16:28:48 +0100
committerAndrej Mihajlov <and@mullvad.net>2017-12-06 13:36:25 +0100
commit9ce419928e84d11a2fc487f0b0565427aa79b1a8 (patch)
tree30af2bb8cf6a44c340d28953fd6bb5afb6e12b8f
parent7a915b67b14fb436431fdcad4e515264fbef7505 (diff)
downloadmullvadvpn-9ce419928e84d11a2fc487f0b0565427aa79b1a8.tar.xz
mullvadvpn-9ce419928e84d11a2fc487f0b0565427aa79b1a8.zip
Convert Backend.sync() to async
-rw-r--r--app/lib/backend.js61
1 files changed, 32 insertions, 29 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index c4492fc77b..0621a24338 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -129,39 +129,42 @@ export class Backend {
this._registerIpcListeners();
}
- sync() {
+ async sync() {
log.info('Syncing with the backend...');
- this._ensureAuthenticated()
- .then( () => {
- this._ipc.getPublicIp()
- .then( ip => {
- log.info('Got ip', ip);
- this._store.dispatch(connectionActions.newPublicIp(ip));
- })
- .catch(e => {
- log.info('Failed syncing with the backend,', e.message);
- });
- });
+ await this._ensureAuthenticated();
- this._ensureAuthenticated()
- .then( () => {
- this._ipc.getLocation()
- .then( location => {
- log.info('Got location', location);
- const newLocation = {
- country: location.country,
- city: location.city,
- location: location.position
- };
- this._store.dispatch(connectionActions.newLocation(newLocation));
- })
- .catch(e => {
- log.info('Failed getting new location,', e.message);
- });
- });
+ try {
+ const publicIp = await this._ipc.getPublicIp();
+
+ log.info('Got public IP: ', publicIp);
+
+ this._store.dispatch(
+ connectionActions.newPublicIp(publicIp)
+ );
+ } catch (e) {
+ log.info('Cannot fetch public IP: ', e.message);
+ }
+
+ try {
+ const location = await this._ipc.getLocation();
+
+ log.info('Got location: ', location);
+
+ const locationUpdate = {
+ country: location.country,
+ city: location.city,
+ location: location.position
+ };
+
+ this._store.dispatch(
+ connectionActions.newLocation(locationUpdate)
+ );
+ } catch (e) {
+ log.info('Cannot fetch new location: ', e.message);
+ }
- this._updateAccountHistory();
+ await this._updateAccountHistory();
}
serverInfo(relay: RelayLocation): ?ServerInfo {