diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-11-20 11:14:46 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-11-20 11:14:46 +0100 |
| commit | eaca478fa8c47903c405f206f4a77cc57068afc1 (patch) | |
| tree | 39052bd0269c50ea237675e715e5f0b9c68f0b98 | |
| parent | 085213b037e6879816da29e0fd8134f6b31fecd2 (diff) | |
| parent | 2e62c4f2a7593fe03c9dade30d9d92d810c6211c (diff) | |
| download | mullvadvpn-eaca478fa8c47903c405f206f4a77cc57068afc1.tar.xz mullvadvpn-eaca478fa8c47903c405f206f4a77cc57068afc1.zip | |
Merge branch 'move-location-to-main'
| -rw-r--r-- | gui/packages/desktop/src/main/daemon-rpc.js | 2 | ||||
| -rw-r--r-- | gui/packages/desktop/src/main/index.js | 34 | ||||
| -rw-r--r-- | gui/packages/desktop/src/renderer/app.js | 131 |
3 files changed, 95 insertions, 72 deletions
diff --git a/gui/packages/desktop/src/main/daemon-rpc.js b/gui/packages/desktop/src/main/daemon-rpc.js index ef904560f0..e3096dfef1 100644 --- a/gui/packages/desktop/src/main/daemon-rpc.js +++ b/gui/packages/desktop/src/main/daemon-rpc.js @@ -31,7 +31,7 @@ export type Location = { city: ?string, latitude: number, longitude: number, - mullvad_exit_ip: boolean, + mullvadExitIp: boolean, hostname: ?string, }; const LocationSchema = partialObject({ diff --git a/gui/packages/desktop/src/main/index.js b/gui/packages/desktop/src/main/index.js index 3c1d76459e..4e432f2c31 100644 --- a/gui/packages/desktop/src/main/index.js +++ b/gui/packages/desktop/src/main/index.js @@ -23,6 +23,7 @@ import { } from './daemon-rpc'; import type { AppVersionInfo, + Location, RelayList, Settings, TunnelState, @@ -66,6 +67,7 @@ const ApplicationMain = { _tunnelState: defaultTunnelStateTransition(), _settings: defaultSettings(), + _location: (null: ?Location), _relays: ({ countries: [] }: RelayList), _relaysInterval: (null: ?IntervalID), @@ -436,17 +438,18 @@ const ApplicationMain = { }, _setTunnelState(newState: TunnelStateTransition) { - const windowController = this._windowController; + const oldState = this._tunnelState; this._tunnelState = newState; this._updateTrayIcon(newState.state); + this._updateLocation(oldState, newState); if (!this._shouldSuppressNotifications()) { this._notificationController.notifyTunnelState(newState); } - if (windowController) { - windowController.send('tunnel-state-changed', newState); + if (this._windowController) { + this._windowController.send('tunnel-state-changed', newState); } }, @@ -458,6 +461,14 @@ const ApplicationMain = { } }, + _setLocation(newLocation: Location) { + this._location = newLocation; + + if (this._windowController) { + this._windowController.send('location-changed', newLocation); + } + }, + _setRelays(newRelayList: RelayList) { this._relays = newRelayList; @@ -592,6 +603,22 @@ const ApplicationMain = { return this._windowController && this._windowController.isVisible(); }, + async _updateLocation(oldState: TunnelStateTransition, newState: TunnelStateTransition) { + if ( + newState.state === 'connected' || + newState.state === 'disconnected' || + // Guard from fetching the location during reconnection loop. + (newState.state === 'connecting' && + !(oldState.state === 'disconnecting' && oldState.details === 'reconnect')) + ) { + try { + this._setLocation(await this._daemonRpc.getLocation()); + } catch (error) { + log.error(`Failed to update the location: ${error.message}`); + } + } + }, + _updateTrayIcon(tunnelState: TunnelState) { const iconTypes: { [TunnelState]: TrayIconType } = { connected: 'secured', @@ -642,6 +669,7 @@ const ApplicationMain = { this._connectedToDaemon, this._tunnelState, this._settings, + this._location, this._relays, this._currentVersion, this._upgradeVersion, diff --git a/gui/packages/desktop/src/renderer/app.js b/gui/packages/desktop/src/renderer/app.js index 1c456fd7d5..93f70dc14c 100644 --- a/gui/packages/desktop/src/renderer/app.js +++ b/gui/packages/desktop/src/renderer/app.js @@ -27,13 +27,13 @@ import type { CurrentAppVersionInfo, AppUpgradeInfo } from '../main'; import type { AccountToken, - Settings, - TunnelStateTransition, + AccountData, + Location, RelayList, RelaySettingsUpdate, RelaySettings, - TunnelState, - AccountData, + Settings, + TunnelStateTransition, } from './lib/daemon-rpc-proxy'; import DaemonRpcProxy, { @@ -111,6 +111,10 @@ export default class AppRenderer { this._setSettings(newSettings); }); + ipcRenderer.on('location-changed', (_event: Event, location: Location) => { + this._setLocation(location); + }); + ipcRenderer.on('relays-changed', (_event: Event, newRelays: RelayList) => { this._setRelays(newRelays); }); @@ -134,12 +138,18 @@ export default class AppRenderer { isConnected: boolean, tunnelState: TunnelStateTransition, settings: Settings, + location: ?Location, relays: RelayList, currentVersion: CurrentAppVersionInfo, upgradeVersion: AppUpgradeInfo, ) => { this._setTunnelState(tunnelState); this._setSettings(settings); + + if (location) { + this._setLocation(location); + } + this._setRelays(relays); this._setCurrentVersion(currentVersion); this._setUpgradeVersion(upgradeVersion); @@ -323,28 +333,6 @@ export default class AppRenderer { actions.account.updateAccountHistory(accountHistory); } - _setRelays(relayList: RelayList) { - const locations = relayList.countries.map((country) => ({ - name: country.name, - code: country.code, - hasActiveRelays: country.cities.some((city) => city.relays.length > 0), - cities: country.cities.map((city) => ({ - name: city.name, - code: city.code, - latitude: city.latitude, - longitude: city.longitude, - hasActiveRelays: city.relays.length > 0, - relays: city.relays, - })), - })); - - this._reduxActions.settings.updateRelayLocations(locations); - } - - async _fetchLocation() { - this._reduxActions.connection.newLocation(await this._daemonRpc.getLocation()); - } - async setAllowLan(allowLan: boolean) { const actions = this._reduxActions; await this._daemonRpc.setAllowLan(allowLan); @@ -444,12 +432,37 @@ export default class AppRenderer { } _setTunnelState(tunnelState: TunnelStateTransition) { + const actions = this._reduxActions; + log.debug(`Tunnel state: ${tunnelState.state}`); this._tunnelState = tunnelState; - this._updateConnectionStatus(tunnelState); - this._updateUserLocation(tunnelState.state); + switch (tunnelState.state) { + case 'connecting': + actions.connection.connecting(tunnelState.details); + break; + + case 'connected': + actions.connection.connected(tunnelState.details); + break; + + case 'disconnecting': + actions.connection.disconnecting(tunnelState.details); + break; + + case 'disconnected': + actions.connection.disconnected(); + break; + + case 'blocked': + actions.connection.blocked(tunnelState.details); + break; + + default: + log.error(`Unexpected TunnelState: ${(tunnelState.state: empty)}`); + break; + } } _setSettings(newSettings: Settings) { @@ -465,52 +478,34 @@ export default class AppRenderer { this._setRelaySettings(newSettings.relaySettings); } - _setCurrentVersion(versionInfo: CurrentAppVersionInfo) { - this._reduxActions.version.updateVersion(versionInfo.gui, versionInfo.isConsistent); + _setLocation(location: Location) { + this._reduxActions.connection.newLocation(location); } - _setUpgradeVersion(upgradeVersion: AppUpgradeInfo) { - this._reduxActions.version.updateLatest(upgradeVersion); - } + _setRelays(relayList: RelayList) { + const locations = relayList.countries.map((country) => ({ + name: country.name, + code: country.code, + hasActiveRelays: country.cities.some((city) => city.relays.length > 0), + cities: country.cities.map((city) => ({ + name: city.name, + code: city.code, + latitude: city.latitude, + longitude: city.longitude, + hasActiveRelays: city.relays.length > 0, + relays: city.relays, + })), + })); - async _updateUserLocation(tunnelState: TunnelState) { - if (['connected', 'connecting', 'disconnected'].includes(tunnelState)) { - try { - await this._fetchLocation(); - } catch (error) { - log.error(`Failed to update the location: ${error.message}`); - } - } + this._reduxActions.settings.updateRelayLocations(locations); } - _updateConnectionStatus(stateTransition: TunnelStateTransition) { - const actions = this._reduxActions; - - switch (stateTransition.state) { - case 'connecting': - actions.connection.connecting(stateTransition.details); - break; - - case 'connected': - actions.connection.connected(stateTransition.details); - break; - - case 'disconnecting': - actions.connection.disconnecting(stateTransition.details); - break; - - case 'disconnected': - actions.connection.disconnected(); - break; - - case 'blocked': - actions.connection.blocked(stateTransition.details); - break; + _setCurrentVersion(versionInfo: CurrentAppVersionInfo) { + this._reduxActions.version.updateVersion(versionInfo.gui, versionInfo.isConsistent); + } - default: - log.error(`Unexpected TunnelStateTransition: ${(stateTransition.state: empty)}`); - break; - } + _setUpgradeVersion(upgradeVersion: AppUpgradeInfo) { + this._reduxActions.version.updateLatest(upgradeVersion); } } |
