diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-09-01 15:56:02 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-09-06 14:38:26 +0200 |
| commit | 993c7e039041d238256b663b80d20297a6ffca7e (patch) | |
| tree | 7a2dab0fcaa9cd0a00870206f883630f7e8674d2 /gui/src | |
| parent | 4ba1552c25a84dcf4a7abb4ee109804b2722e3ec (diff) | |
| download | mullvadvpn-993c7e039041d238256b663b80d20297a6ffca7e.tar.xz mullvadvpn-993c7e039041d238256b663b80d20297a6ffca7e.zip | |
Use cached location when disconnecting
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/index.ts | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 8845422e6b..03121170e7 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -990,12 +990,6 @@ class ApplicationMain { if (tunnelState.details && tunnelState.details.location) { this.setLocation(tunnelState.details.location); } - } else if (tunnelState.state === 'disconnected') { - // It may take some time to fetch the new user location. - // So take the user to the last known location when disconnected. - if (this.lastDisconnectedLocation) { - this.setLocation(this.lastDisconnectedLocation); - } } if (tunnelState.state === 'connected' || tunnelState.state === 'disconnected') { @@ -1003,21 +997,16 @@ class ApplicationMain { // Fetch the new user location const getLocationPromise = (this.getLocationPromise = this.daemonRpc.getLocation()); const location = await getLocationPromise; - // If the location is currently unavailable, do nothing! This only ever - // happens when a custom relay is set or we are in a blocked state. - if (!location) { - return; - } - - // Cache the user location - // Note: hostname is only set for relay servers. - if (location.hostname === null) { - this.lastDisconnectedLocation = location; - } - - // Broadcast the new location if it is the result of the most recent call to getLocation. - if (getLocationPromise === this.getLocationPromise) { + // If the location is currently unavailable, do nothing! This only ever happens when a + // custom relay is set or we are in a blocked state. Save and broadcast the new location if + // it is the result of the most recent call to getLocation. + if (location && getLocationPromise === this.getLocationPromise) { this.setLocation(location); + + // Cache the user location + if (tunnelState.state === 'disconnected') { + this.lastDisconnectedLocation = location; + } } } catch (error) { log.error(`Failed to update the location: ${error.message}`); @@ -1159,7 +1148,17 @@ class ApplicationMain { }); IpcMainEventChannel.tunnel.handleConnect(() => this.daemonRpc.connectTunnel()); - IpcMainEventChannel.tunnel.handleDisconnect(() => this.daemonRpc.disconnectTunnel()); + IpcMainEventChannel.tunnel.handleDisconnect(async () => { + // It may take some time to fetch the new user location. + // So take the user to the last known location when disconnected. + if (this.windowController && this.lastDisconnectedLocation) { + IpcMainEventChannel.location.notify( + this.windowController.webContents, + this.lastDisconnectedLocation, + ); + } + return this.daemonRpc.disconnectTunnel(); + }); IpcMainEventChannel.tunnel.handleReconnect(() => this.daemonRpc.reconnectTunnel()); IpcMainEventChannel.guiSettings.handleSetEnableSystemNotifications((flag: boolean) => { |
