diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2024-02-09 17:45:33 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2024-02-09 17:45:33 +0100 |
| commit | 3bea8ae918ba35755b166a44ac90ef1388e25a86 (patch) | |
| tree | 6542fa3e5d07942c9ac536f6056e124b694e1b91 /gui/src | |
| parent | 433547101d2c4e26c5224381a72330bce1ce51fb (diff) | |
| parent | 683fbbced61ce9379b1af0be6da8be5da3a11f25 (diff) | |
| download | mullvadvpn-3bea8ae918ba35755b166a44ac90ef1388e25a86.tar.xz mullvadvpn-3bea8ae918ba35755b166a44ac90ef1388e25a86.zip | |
Merge branch 'add-out-of-time-state-update'
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/app.tsx | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 78c11504f2..1a735e1ec5 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -3,7 +3,7 @@ import { Router } from 'react-router'; import { bindActionCreators } from 'redux'; import { StyleSheetManager } from 'styled-components'; -import { hasExpired } from '../shared/account-expiry'; +import { closeToExpiry, hasExpired } from '../shared/account-expiry'; import { ILinuxSplitTunnelingApplication, IWindowsApplication } from '../shared/application-types'; import { AccessMethodSetting, @@ -103,9 +103,11 @@ export default class AppRenderer { private deviceState?: DeviceState; private loginState: LoginState = 'none'; private previousLoginState: LoginState = 'none'; - private loginScheduler = new Scheduler(); private connectedToDaemon = false; + private loginScheduler = new Scheduler(); + private expiryScheduler = new Scheduler(); + constructor() { log.addOutput(new ConsoleOutput(LogLevel.debug)); log.addOutput(new IpcOutput(LogLevel.debug)); @@ -669,14 +671,18 @@ export default class AppRenderer { this.resetNavigation(); } - private resetNavigation() { + private resetNavigation(replaceRoot?: boolean) { if (this.history) { const pathname = this.history.location.pathname as RoutePath; const nextPath = this.getNavigationBase() as RoutePath; if (pathname !== nextPath) { const transition = this.getNavigationTransition(pathname, nextPath); - this.history.reset(nextPath, { transition }); + if (replaceRoot) { + this.history.replaceRoot(nextPath, { transition }); + } else { + this.history.reset(nextPath, { transition }); + } } } } @@ -927,29 +933,41 @@ export default class AppRenderer { } private setAccountExpiry(expiry?: string) { - if (window.env.e2e && expiry) { - log.verbose('Expiry of account:', expiry); + const state = this.reduxStore.getState(); + const previousExpiry = state.account.expiry; + + this.expiryScheduler.cancel(); + + if (expiry !== undefined) { + const expired = hasExpired(expiry); + + // Set state to expired when expiry date passes. + if (!expired && closeToExpiry(expiry)) { + const delay = new Date(expiry).getTime() - Date.now() + 1; + this.expiryScheduler.schedule(() => this.handleExpiry(expiry, true), delay); + } + + if (expiry !== previousExpiry) { + this.handleExpiry(expiry, expired); + } + } else { + this.handleExpiry(expiry); } + } + private handleExpiry(expiry?: string, expired?: boolean) { const state = this.reduxStore.getState(); - const previousExpiry = state.account.expiry; this.reduxActions.account.updateAccountExpiry(expiry); - const expired = expiry !== undefined && hasExpired(expiry); if ( - this.history && - state.account.status.type === 'ok' && expiry !== undefined && - expiry !== previousExpiry && + state.account.status.type === 'ok' && ((state.account.status.expiredState === undefined && expired) || (state.account.status.expiredState === 'expired' && !expired)) && // If the login navigation is already scheduled no navigation is needed !this.loginScheduler.isRunning ) { - const prevPath = this.history.location.pathname as RoutePath; - const nextPath = expired ? RoutePath.expired : RoutePath.timeAdded; - const transition = this.getNavigationTransition(prevPath, nextPath); - this.history.replaceRoot(nextPath, { transition }); + this.resetNavigation(true); } } |
