summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-08-30 10:46:25 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-08-30 10:46:25 +0200
commit3fec3efd11bc8a73b6e9f9ea4b3bb28fdf9fd1e1 (patch)
tree7ab4e7ee146a57a2bd75b3d125fe7f753bfffca1 /gui
parent7b742357fa0200bf31b778ddb00971322aeb8a29 (diff)
parent741bda934eb622a6ecc1b1101c7e59d69b1015bf (diff)
downloadmullvadvpn-3fec3efd11bc8a73b6e9f9ea4b3bb28fdf9fd1e1.tar.xz
mullvadvpn-3fec3efd11bc8a73b6e9f9ea4b3bb28fdf9fd1e1.zip
Merge branch 'fix-change-window-type-autoconnect'
Diffstat (limited to 'gui')
-rw-r--r--gui/src/main/index.ts31
-rw-r--r--gui/src/renderer/app.tsx28
2 files changed, 26 insertions, 33 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 769863fd72..94702ce979 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -116,6 +116,7 @@ class ApplicationMain {
private daemonRpc = new DaemonRpc(DAEMON_RPC_PATH);
private daemonEventListener?: SubscriptionListener<DaemonEvent>;
private reconnectBackoff = new ReconnectionBackoff();
+ private beforeFirstDaemonConnection = true;
private connectedToDaemon = false;
private quitStage = AppQuitStage.unready;
@@ -518,6 +519,8 @@ class ApplicationMain {
}
private onDaemonConnected = async () => {
+ const firstDaemonConnection = this.beforeFirstDaemonConnection;
+ this.beforeFirstDaemonConnection = false;
this.connectedToDaemon = true;
log.info('Connected to the daemon');
@@ -596,6 +599,10 @@ class ApplicationMain {
IpcMainEventChannel.daemon.notifyConnected(this.windowController.webContents);
}
+ if (firstDaemonConnection) {
+ void this.autoConnect();
+ }
+
// show window when account is not set
if (!this.settings.accountToken) {
this.windowController?.show();
@@ -1389,13 +1396,25 @@ class ApplicationMain {
}
private async autoConnect() {
- if (!this.accountData || !hasExpired(this.accountData.expiry)) {
- try {
- log.info('Auto-connecting the tunnel');
- await this.daemonRpc.connectTunnel();
- } catch (error) {
- log.error(`Failed to auto-connect the tunnel: ${error.message}`);
+ if (process.env.NODE_ENV === 'development') {
+ log.info('Skip autoconnect in development');
+ } else if (
+ this.settings.accountToken &&
+ (!this.accountData || !hasExpired(this.accountData.expiry))
+ ) {
+ if (this.guiSettings.autoConnect) {
+ try {
+ log.info('Autoconnect the tunnel');
+
+ await this.daemonRpc.connectTunnel();
+ } catch (error) {
+ log.error(`Failed to autoconnect the tunnel: ${error.message}`);
+ }
+ } else {
+ log.info('Skip autoconnect because GUI setting is disabled');
}
+ } else {
+ log.info('Skip autoconnect because account token is not set');
}
}
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx
index 54f843a6e0..5cb32d3517 100644
--- a/gui/src/renderer/app.tsx
+++ b/gui/src/renderer/app.tsx
@@ -121,7 +121,6 @@ export default class AppRenderer {
private tunnelState!: TunnelState;
private settings!: ISettings;
private guiSettings!: IGuiSettingsState;
- private autoConnected = false;
private doingLogin = false;
private loginScheduler = new Scheduler();
private connectedToDaemon = false;
@@ -646,9 +645,8 @@ export default class AppRenderer {
}
}
- private async onDaemonConnected() {
+ private onDaemonConnected() {
this.connectedToDaemon = true;
- await this.autoConnect();
this.resetNavigation();
}
@@ -698,30 +696,6 @@ export default class AppRenderer {
}
}
- private async autoConnect() {
- if (window.env.development) {
- log.info('Skip autoconnect in development');
- } else if (this.autoConnected) {
- log.info('Skip autoconnect because it was done before');
- } else if (this.settings.accountToken) {
- if (this.guiSettings.autoConnect) {
- try {
- log.info('Autoconnect the tunnel');
-
- await this.connectTunnel();
-
- this.autoConnected = true;
- } catch (error) {
- log.error(`Failed to autoconnect the tunnel: ${error.message}`);
- }
- } else {
- log.info('Skip autoconnect because GUI setting is disabled');
- }
- } else {
- log.info('Skip autoconnect because account token is not set');
- }
- }
-
private setAccountHistory(accountHistory?: AccountToken) {
this.reduxActions.account.updateAccountHistory(accountHistory);
}