diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-09-09 10:12:20 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-09-09 15:35:31 +0200 |
| commit | 5ff4be3ffb71ea3c3f593c4bf679547c338077a9 (patch) | |
| tree | bc3d70da1cf66f069b8d14cf997cf9994d0aa7cf /gui/src/renderer | |
| parent | 0aef41f6e2937581749c837f660c436785daf131 (diff) | |
| download | mullvadvpn-5ff4be3ffb71ea3c3f593c4bf679547c338077a9.tar.xz mullvadvpn-5ff4be3ffb71ea3c3f593c4bf679547c338077a9.zip | |
Make sure fetchLocation is always called
Diffstat (limited to 'gui/src/renderer')
| -rw-r--r-- | gui/src/renderer/app.tsx | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 5b75330c8b..3f65002340 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -917,35 +917,40 @@ export default class AppRenderer { } private async updateLocation(tunnelState = this.tunnelState) { - if ( - (tunnelState.state === 'disconnected' || tunnelState.state === 'disconnecting') && - this.lastDisconnectedLocation - ) { - // If we have a previous location for the disconnected state we use that when disconnecting and - // during the location fetch while disconnected. - this.setLocation(this.lastDisconnectedLocation); - } else if (tunnelState.state === 'disconnecting') { - // If there's no previous location while disconnecting we remove the location. We keep the - // coordinates to prevent the map from jumping around. - const { longitude, latitude } = this.reduxStore.getState().connection; - this.setLocation({ longitude, latitude }); - } - - if ( - (tunnelState.state === 'connected' || tunnelState.state === 'connecting') && - tunnelState.details?.location - ) { - this.setLocation(tunnelState.details.location); - } else if (tunnelState.state === 'connecting') { - this.setLocation(this.getLocationFromConstraints()); - } else if (tunnelState.state === 'connected' || tunnelState.state === 'disconnected') { - const location = await this.fetchLocation(); - if (location) { - this.setLocation(location); - // Cache the user location - if (tunnelState.state === 'disconnected') { + switch (tunnelState.state) { + case 'disconnected': { + if (this.lastDisconnectedLocation) { + this.setLocation(this.lastDisconnectedLocation); + } + const location = await this.fetchLocation(); + if (location) { + this.setLocation(location); this.lastDisconnectedLocation = location; } + break; + } + case 'disconnecting': + if (this.lastDisconnectedLocation) { + this.setLocation(this.lastDisconnectedLocation); + } else { + // If there's no previous location while disconnecting we remove the location. We keep the + // coordinates to prevent the map from jumping around. + const { longitude, latitude } = this.reduxStore.getState().connection; + this.setLocation({ longitude, latitude }); + } + break; + case 'connecting': + this.setLocation(tunnelState.details?.location ?? this.getLocationFromConstraints()); + break; + case 'connected': { + if (tunnelState.details?.location) { + this.setLocation(tunnelState.details.location); + } + const location = await this.fetchLocation(); + if (location) { + this.setLocation(location); + } + break; } } } |
