diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2024-02-06 16:57:06 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2024-02-09 17:45:22 +0100 |
| commit | c080d76fbd765d39e0522a43743064744e23529e (patch) | |
| tree | af8dd0501fe7c8d2f35cf91b51cd64096070d844 /gui/src | |
| parent | 9873a37ef0c2feab38bd0d34558916758a8a60dc (diff) | |
| download | mullvadvpn-c080d76fbd765d39e0522a43743064744e23529e.tar.xz mullvadvpn-c080d76fbd765d39e0522a43743064744e23529e.zip | |
Add scheduler that sets the expired state
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/app.tsx | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 78c11504f2..231bb980e4 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 }); + } } } } @@ -933,23 +939,39 @@ export default class AppRenderer { 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(); 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); } } |
