diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-06-05 10:37:46 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-06-05 10:42:17 +0200 |
| commit | 76a8fa5f60d02d1a7f825258c60ec36aad2fee2f (patch) | |
| tree | ee05d64d3d4c78b7bf85d491c8db19b9fe751ef7 /gui/src | |
| parent | 02198644f9262a5c5516c27026b3938691e5366b (diff) | |
| download | mullvadvpn-76a8fa5f60d02d1a7f825258c60ec36aad2fee2f.tar.xz mullvadvpn-76a8fa5f60d02d1a7f825258c60ec36aad2fee2f.zip | |
Move autoconnect to main process and check if account has expired
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/index.ts | 15 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 19 |
2 files changed, 19 insertions, 15 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index d64ff7cf93..ba9f8a9baa 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -1108,6 +1108,7 @@ class ApplicationMain { } await this.daemonRpc.setAccount(accountToken); + consumePromise(this.autoConnect()); } catch (error) { log.error(`Failed to login: ${error.message}`); @@ -1119,6 +1120,20 @@ class ApplicationMain { } } + private async autoConnect() { + if ( + !this.accountData || + !new AccountExpiry(this.accountData.expiry, this.locale).hasExpired() + ) { + try { + log.info('Auto-connecting the tunnel'); + await this.daemonRpc.connectTunnel(); + } catch (error) { + log.error(`Failed to auto-connect the tunnel: ${error.message}`); + } + } + } + private async logout(): Promise<void> { try { await this.daemonRpc.setAccount(); diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 5c1623b67e..b5afb608ec 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -242,7 +242,7 @@ export default class AppRenderer { await IpcRendererEventChannel.account.login(accountToken); actions.account.updateAccountToken(accountToken); actions.account.loggedIn(); - this.redirectToConnect(true); + this.redirectToConnect(); } catch (error) { actions.account.loginFailed(error); } @@ -267,7 +267,7 @@ export default class AppRenderer { const accountToken = await IpcRendererEventChannel.account.create(); const accountExpiry = new Date().toISOString(); actions.account.accountCreated(accountToken, accountExpiry); - this.redirectToConnect(false); + this.redirectToConnect(); } catch (error) { actions.account.createAccountFailed(error); } @@ -431,20 +431,9 @@ export default class AppRenderer { return preferredLocale ? preferredLocale.name : ''; } - private redirectToConnect(connect: boolean) { + private redirectToConnect() { // Redirect the user after some time to allow for the 'Logged in' screen to be visible - this.loginTimer = global.setTimeout(async () => { - this.memoryHistory.replace('/connect'); - - if (connect) { - try { - log.info('Auto-connecting the tunnel'); - await this.connectTunnel(); - } catch (error) { - log.error(`Failed to auto-connect the tunnel: ${error.message}`); - } - } - }, 1000); + this.loginTimer = global.setTimeout(() => this.memoryHistory.replace('/connect'), 1000); } private loadTranslations(locale: string) { |
