summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-03-09 12:00:47 +0100
committerOskar Nyberg <oskar@mullvad.net>2021-03-09 12:00:47 +0100
commit2c75829950240da8e75a87c980f98135ab6fb429 (patch)
treee69d2d82184da91bac326f3522e970830ce3a7f8
parent8a56534922588ffcb85c52eb5dad497029908839 (diff)
parent8ec56a752034458b0676cb04adda7bdb2a23a817 (diff)
downloadmullvadvpn-2c75829950240da8e75a87c980f98135ab6fb429.tar.xz
mullvadvpn-2c75829950240da8e75a87c980f98135ab6fb429.zip
Merge branch 'better-handle-non-responding-daemon'
-rw-r--r--gui/src/main/daemon-rpc.ts12
-rw-r--r--gui/src/main/index.ts61
-rw-r--r--gui/src/renderer/app.tsx25
-rw-r--r--gui/src/shared/ipc-schema.ts8
-rw-r--r--gui/src/shared/ipc-types.ts2
5 files changed, 40 insertions, 68 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts
index 9be0fc6870..8eef8848e2 100644
--- a/gui/src/main/daemon-rpc.ts
+++ b/gui/src/main/daemon-rpc.ts
@@ -165,16 +165,8 @@ export class DaemonRpc {
public addConnectionObserver(observer: ConnectionObserver) {
this.connectionObservers.push(observer);
- const currentState = this.client.getChannel()?.getConnectivityState(true);
- if (
- currentState === grpc.connectivityState.SHUTDOWN ||
- currentState === grpc.connectivityState.TRANSIENT_FAILURE ||
- currentState === grpc.connectivityState.IDLE
- ) {
- observer.onClose();
- } else {
- observer.onOpen();
- }
+ // Call getConnectivityState(true) to start connecting if idle
+ this.client.getChannel()?.getConnectivityState(true);
}
public removeConnectionObserver(observer: ConnectionObserver) {
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 190f575e94..45a21bf8f6 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -82,6 +82,7 @@ const DAEMON_RPC_PATH =
const AUTO_CONNECT_FALLBACK_DELAY = 6000;
+const GUI_VERSION = app.getVersion().replace('.0', '');
/// Mirrors the beta check regex in the daemon. Matches only well formed beta versions
const IS_BETA = /^(\d{4})\.(\d+)-beta(\d+)$/;
@@ -165,10 +166,10 @@ class ApplicationMain {
private relays: IRelayList = { countries: [] };
private currentVersion: ICurrentAppVersionInfo = {
- daemon: '',
- gui: '',
+ daemon: undefined,
+ gui: GUI_VERSION,
isConsistent: true,
- isBeta: false,
+ isBeta: IS_BETA.test(GUI_VERSION),
};
private upgradeVersion: IAppVersionInfo = {
@@ -224,7 +225,7 @@ class ApplicationMain {
app.enableSandbox();
}
- log.info(`Running version ${app.getVersion()}`);
+ log.info(`Running version ${this.currentVersion.gui}`);
if (process.platform === 'win32') {
app.setAppUserModelId('net.mullvad.vpn');
@@ -483,6 +484,8 @@ class ApplicationMain {
private onDaemonConnected = async () => {
this.connectedToDaemon = true;
+ log.info('Connected to the daemon');
+
// subscribe to events
try {
this.daemonEventListener = this.subscribeEvents();
@@ -548,20 +551,13 @@ class ApplicationMain {
// fetch the latest version info in background
consumePromise(this.fetchLatestVersion());
- // notify user about inconsistent version
- const notificationProvider = new InconsistentVersionNotificationProvider({
- consistent: this.currentVersion.isConsistent,
- });
- if (notificationProvider.mayDisplay()) {
- this.notificationController.notify(notificationProvider.getSystemNotification());
- }
-
// reset the reconnect backoff when connection established.
this.reconnectBackoff.reset();
- // notify renderer
- if (this.windowController) {
- IpcMainEventChannel.daemonConnected.notify(this.windowController.webContents);
+ // notify renderer, this.connectedToDaemon could have changed if the daemon disconnected again
+ // before this if-statement is reached.
+ if (this.windowController && this.connectedToDaemon) {
+ IpcMainEventChannel.daemon.notifyConnected(this.windowController.webContents);
}
// show window when account is not set
@@ -581,9 +577,6 @@ class ApplicationMain {
// Reset the daemon event listener since it's going to be invalidated on disconnect
this.daemonEventListener = undefined;
- // TODO: GRPC doesn't set an error, but without an error, the UI won't be updated
- error = error === undefined && wasConnected ? new Error('Connection to daemon lost') : error;
-
if (wasConnected) {
this.connectedToDaemon = false;
@@ -592,10 +585,7 @@ class ApplicationMain {
// notify renderer process
if (this.windowController) {
- IpcMainEventChannel.daemonDisconnected.notify(
- this.windowController.webContents,
- error ? error.message : undefined,
- );
+ IpcMainEventChannel.daemon.notifyDisconnected(this.windowController.webContents);
}
}
@@ -609,12 +599,6 @@ class ApplicationMain {
} else {
log.info('Disconnected from the daemon');
}
-
- // Set GUI version info if it hasn't already been done. Only happens if the app starts without a
- // connection to the daemon.
- if (this.currentVersion.gui === '') {
- this.setDaemonVersion('');
- }
};
private connectToDaemon() {
@@ -853,16 +837,29 @@ class ApplicationMain {
}
private setDaemonVersion(daemonVersion: string) {
- const guiVersion = app.getVersion().replace('.0', '');
const versionInfo = {
+ ...this.currentVersion,
daemon: daemonVersion,
- gui: guiVersion,
- isConsistent: daemonVersion === guiVersion,
- isBeta: IS_BETA.test(guiVersion),
+ isConsistent: daemonVersion === this.currentVersion.gui,
};
this.currentVersion = versionInfo;
+ if (!versionInfo.isConsistent) {
+ log.info('Inconsistent version', {
+ guiVersion: versionInfo.gui,
+ daemonVersion: versionInfo.daemon,
+ });
+ }
+
+ // notify user about inconsistent version
+ const notificationProvider = new InconsistentVersionNotificationProvider({
+ consistent: versionInfo.isConsistent,
+ });
+ if (notificationProvider.mayDisplay()) {
+ this.notificationController.notify(notificationProvider.getSystemNotification());
+ }
+
// notify renderer
if (this.windowController) {
IpcMainEventChannel.currentVersion.notify(this.windowController.webContents, versionInfo);
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx
index 4c79cc2192..9f7c6b5d2b 100644
--- a/gui/src/renderer/app.tsx
+++ b/gui/src/renderer/app.tsx
@@ -93,7 +93,6 @@ export default class AppRenderer {
private tunnelState!: TunnelState;
private settings!: ISettings;
private guiSettings!: IGuiSettingsState;
- private connectedToDaemon = false;
private autoConnected = false;
private doingLogin = false;
private loginTimer?: NodeJS.Timeout;
@@ -108,12 +107,12 @@ export default class AppRenderer {
}
});
- IpcRendererEventChannel.daemonConnected.listen(() => {
+ IpcRendererEventChannel.daemon.listenConnected(() => {
consumePromise(this.onDaemonConnected());
});
- IpcRendererEventChannel.daemonDisconnected.listen((errorMessage?: string) => {
- this.onDaemonDisconnected(errorMessage ? new Error(errorMessage) : undefined);
+ IpcRendererEventChannel.daemon.listenDisconnected(() => {
+ this.onDaemonDisconnected();
});
IpcRendererEventChannel.account.listen((newAccountData?: IAccountData) => {
@@ -559,14 +558,6 @@ export default class AppRenderer {
}
private async onDaemonConnected() {
- // Filter out the calls coming from IPC events arriving right after the constructor finished
- // execution.
- if (this.connectedToDaemon) {
- return;
- }
-
- this.connectedToDaemon = true;
-
if (this.settings.accountToken) {
this.history.resetWith('/connect');
@@ -577,14 +568,8 @@ export default class AppRenderer {
}
}
- private onDaemonDisconnected(error?: Error) {
- const wasConnected = this.connectedToDaemon;
-
- this.connectedToDaemon = false;
-
- if (error && wasConnected) {
- this.history.resetWith('/');
- }
+ private onDaemonDisconnected() {
+ this.history.resetWith('/');
}
private async autoConnect() {
diff --git a/gui/src/shared/ipc-schema.ts b/gui/src/shared/ipc-schema.ts
index 62a3afc948..3f0d86d995 100644
--- a/gui/src/shared/ipc-schema.ts
+++ b/gui/src/shared/ipc-schema.ts
@@ -107,11 +107,9 @@ export const ipcSchema = {
windowFocus: {
'': notifyRenderer<boolean>(),
},
- daemonConnected: {
- '': notifyRenderer<void>(),
- },
- daemonDisconnected: {
- '': notifyRenderer<string | undefined>(),
+ daemon: {
+ connected: notifyRenderer<void>(),
+ disconnected: notifyRenderer<void>(),
},
location: {
'': notifyRenderer<ILocation>(),
diff --git a/gui/src/shared/ipc-types.ts b/gui/src/shared/ipc-types.ts
index 7781551ed5..691d54b61b 100644
--- a/gui/src/shared/ipc-types.ts
+++ b/gui/src/shared/ipc-types.ts
@@ -1,6 +1,6 @@
export interface ICurrentAppVersionInfo {
gui: string;
- daemon: string;
+ daemon?: string;
isConsistent: boolean;
isBeta: boolean;
}