summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorJonathan <jonathan@mullvad.net>2023-12-21 13:36:52 +0100
committerJonathan <jonathan@mullvad.net>2023-12-21 13:36:52 +0100
commit9d71eccc2f3507928b833f969c952347c7a76d4c (patch)
treec92a6f524fa9f659a0edb2bb702e466d051ddba2 /gui/src
parentce7f4f73f82295275631ef05dbe12ba17843ec2d (diff)
parent8ed53a012b6c510a0dfd92925b8b0e742fd79da3 (diff)
downloadmullvadvpn-9d71eccc2f3507928b833f969c952347c7a76d4c.tar.xz
mullvadvpn-9d71eccc2f3507928b833f969c952347c7a76d4c.zip
Merge branch 'out-ip-delay'
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/daemon-rpc.ts11
-rw-r--r--gui/src/main/index.ts2
-rw-r--r--gui/src/main/tunnel-state.ts19
-rw-r--r--gui/src/renderer/app.tsx51
-rw-r--r--gui/src/shared/daemon-rpc-types.ts4
-rw-r--r--gui/src/shared/ipc-schema.ts4
6 files changed, 32 insertions, 59 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts
index 174b2aea77..ad7b60dec2 100644
--- a/gui/src/main/daemon-rpc.ts
+++ b/gui/src/main/daemon-rpc.ts
@@ -33,7 +33,6 @@ import {
IDevice,
IDeviceRemoval,
IDnsOptions,
- ILocation,
IObfuscationEndpoint,
IOpenVpnConstraints,
IProxyEndpoint,
@@ -434,11 +433,6 @@ export class DaemonRpc {
await this.callEmpty(this.client.reconnectTunnel);
}
- public async getLocation(): Promise<ILocation> {
- const response = await this.callEmpty<grpcTypes.GeoIpLocation>(this.client.getCurrentLocation);
- return response.toObject();
- }
-
public async getState(): Promise<TunnelState> {
const response = await this.callEmpty<grpcTypes.TunnelState>(this.client.getTunnelState);
return convertFromTunnelState(response)!;
@@ -851,7 +845,10 @@ function convertFromTunnelState(tunnelState: grpcTypes.TunnelState): TunnelState
case grpcTypes.TunnelState.StateCase.STATE_NOT_SET:
return undefined;
case grpcTypes.TunnelState.StateCase.DISCONNECTED:
- return { state: 'disconnected' };
+ return {
+ state: 'disconnected',
+ location: tunnelStateObject.disconnected!.disconnectedLocation,
+ };
case grpcTypes.TunnelState.StateCase.DISCONNECTING: {
const detailsMap: Record<grpcTypes.AfterDisconnect, AfterDisconnect> = {
[grpcTypes.AfterDisconnect.NOTHING]: 'nothing',
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index da3d677cc0..6c3a6373fb 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -728,8 +728,6 @@ class ApplicationMain
navigationHistory: this.navigationHistory,
}));
- IpcMainEventChannel.location.handleGet(() => this.daemonRpc.getLocation());
-
IpcMainEventChannel.tunnel.handleConnect(this.connectTunnel);
IpcMainEventChannel.tunnel.handleReconnect(this.reconnectTunnel);
IpcMainEventChannel.tunnel.handleDisconnect(this.disconnectTunnel);
diff --git a/gui/src/main/tunnel-state.ts b/gui/src/main/tunnel-state.ts
index 029386f3b7..6829118818 100644
--- a/gui/src/main/tunnel-state.ts
+++ b/gui/src/main/tunnel-state.ts
@@ -1,5 +1,5 @@
import { connectEnabled, disconnectEnabled, reconnectEnabled } from '../shared/connect-helper';
-import { TunnelState } from '../shared/daemon-rpc-types';
+import { ILocation, TunnelState } from '../shared/daemon-rpc-types';
import { Scheduler } from '../shared/scheduler';
export interface TunnelStateProvider {
@@ -20,6 +20,8 @@ export default class TunnelStateHandler {
// Scheduler for discarding the assumed next state.
private tunnelStateFallbackScheduler = new Scheduler();
+ private lastKnownDisconnectedLocation: Partial<ILocation> | undefined;
+
public constructor(private delegate: TunnelStateHandlerDelegate) {}
public get tunnelState() {
@@ -37,7 +39,9 @@ export default class TunnelStateHandler {
this.tunnelStateFallback = this.tunnelState;
this.setTunnelState(
- state === 'disconnecting' ? { state, details: 'nothing' as const } : { state },
+ state === 'disconnecting'
+ ? { state, details: 'nothing' as const, location: this.lastKnownDisconnectedLocation }
+ : { state },
);
this.tunnelStateFallbackScheduler.schedule(() => {
@@ -67,6 +71,17 @@ export default class TunnelStateHandler {
this.expectNextTunnelState('connecting');
this.tunnelStateFallback = newState;
} else {
+ if (newState.state === 'disconnected' && newState.location !== undefined) {
+ this.lastKnownDisconnectedLocation = newState.location;
+ }
+
+ if (
+ newState.state === 'disconnecting' ||
+ (newState.state === 'disconnected' && newState.location === undefined)
+ ) {
+ newState.location = this.lastKnownDisconnectedLocation;
+ }
+
this.setTunnelState(newState);
}
}
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx
index 584e80ed4f..b5eacf17b3 100644
--- a/gui/src/renderer/app.tsx
+++ b/gui/src/renderer/app.tsx
@@ -94,7 +94,6 @@ export default class AppRenderer {
};
private location?: Partial<ILocation>;
- private lastDisconnectedLocation?: Partial<ILocation>;
private relayList?: IRelayListWithEndpointData;
private tunnelState!: TunnelState;
private settings!: ISettings;
@@ -103,7 +102,6 @@ export default class AppRenderer {
private previousLoginState: LoginState = 'none';
private loginScheduler = new Scheduler();
private connectedToDaemon = false;
- private getLocationPromise?: Promise<ILocation>;
constructor() {
log.addOutput(new ConsoleOutput(LogLevel.debug));
@@ -255,7 +253,7 @@ export default class AppRenderer {
);
}
- void this.updateLocation();
+ this.updateLocation();
if (initialState.navigationHistory) {
// Set last action to POP to trigger automatic scrolling to saved coordinates.
@@ -765,7 +763,7 @@ export default class AppRenderer {
}
// Update the location when entering a new tunnel state since it's likely changed.
- void this.updateLocation();
+ this.updateLocation();
});
}
@@ -944,22 +942,16 @@ export default class AppRenderer {
this.reduxActions.userInterface.setForceShowChanges(forceShowChanges);
}
- private async updateLocation() {
+ private updateLocation() {
switch (this.tunnelState.state) {
- case 'disconnected': {
- if (this.lastDisconnectedLocation) {
- this.setLocation(this.lastDisconnectedLocation);
- }
- const location = await this.fetchLocation();
- if (location) {
- this.setLocation(location);
- this.lastDisconnectedLocation = location;
+ case 'disconnected':
+ if (this.tunnelState.location) {
+ this.setLocation(this.tunnelState.location);
}
break;
- }
case 'disconnecting':
- if (this.lastDisconnectedLocation) {
- this.setLocation(this.lastDisconnectedLocation);
+ if (this.tunnelState.location) {
+ this.setLocation(this.tunnelState.location);
} else {
// If there's no previous location while disconnecting we remove the location. We keep the
// coordinates to prevent the map from jumping around.
@@ -968,38 +960,13 @@ export default class AppRenderer {
}
break;
case 'connecting':
- this.setLocation(this.tunnelState.details?.location ?? this.getLocationFromConstraints());
- break;
case 'connected': {
- if (this.tunnelState.details?.location) {
- this.setLocation(this.tunnelState.details.location);
- }
- const location = await this.fetchLocation();
- if (location) {
- this.setLocation(location);
- }
+ this.setLocation(this.tunnelState.details?.location ?? this.getLocationFromConstraints());
break;
}
}
}
- private async fetchLocation(): Promise<ILocation | void> {
- try {
- // Fetch the new user location
- const getLocationPromise = IpcRendererEventChannel.location.get();
- this.getLocationPromise = getLocationPromise;
- 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 && getLocationPromise === this.getLocationPromise) {
- return location;
- }
- } catch (e) {
- const error = e as Error;
- log.error(`Failed to update the location: ${error.message}`);
- }
- }
-
private getLocationFromConstraints(): Partial<ILocation> {
const state = this.reduxStore.getState();
const coordinates = {
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts
index 6977be4375..e83f9e5afc 100644
--- a/gui/src/shared/daemon-rpc-types.ts
+++ b/gui/src/shared/daemon-rpc-types.ts
@@ -181,10 +181,10 @@ export interface ITunnelStateRelayInfo {
}
export type TunnelState =
- | { state: 'disconnected' }
+ | { state: 'disconnected'; location?: Partial<ILocation> }
| { state: 'connecting'; details?: ITunnelStateRelayInfo }
| { state: 'connected'; details: ITunnelStateRelayInfo }
- | { state: 'disconnecting'; details: AfterDisconnect }
+ | { state: 'disconnecting'; details: AfterDisconnect; location?: Partial<ILocation> }
| { state: 'error'; details: ErrorState };
export interface RelayLocationCountry extends Partial<RelayLocationCustomList> {
diff --git a/gui/src/shared/ipc-schema.ts b/gui/src/shared/ipc-schema.ts
index 994bacdcd6..ecf34e93fb 100644
--- a/gui/src/shared/ipc-schema.ts
+++ b/gui/src/shared/ipc-schema.ts
@@ -15,7 +15,6 @@ import {
IDevice,
IDeviceRemoval,
IDnsOptions,
- ILocation,
IRelayListWithEndpointData,
ISettings,
ObfuscationSettings,
@@ -153,9 +152,6 @@ export const ipcSchema = {
showOpenDialog: invoke<Electron.OpenDialogOptions, Electron.OpenDialogReturnValue>(),
showLaunchDaemonSettings: invoke<void, void>(),
},
- location: {
- get: invoke<void, ILocation>(),
- },
tunnel: {
'': notifyRenderer<TunnelState>(),
connect: invoke<void, void>(),