diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-07-06 19:19:33 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-07-08 13:23:30 +0200 |
| commit | 8452dc8559837253b253df7f47a075f156845e66 (patch) | |
| tree | ee319953943eba896f10d0078ba6686ccb646bd6 /gui/src | |
| parent | 01b8b634786777369c22940f2790477bdece36b8 (diff) | |
| download | mullvadvpn-8452dc8559837253b253df7f47a075f156845e66.tar.xz mullvadvpn-8452dc8559837253b253df7f47a075f156845e66.zip | |
Prevent account data fetch on show unless within 4 days of expiry
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/index.ts | 12 | ||||
| -rw-r--r-- | gui/src/shared/account-expiry.ts | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index a139434020..d7036a508c 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -15,7 +15,7 @@ import * as path from 'path'; import { sprintf } from 'sprintf-js'; import * as uuid from 'uuid'; import config from '../config.json'; -import { hasExpired } from '../shared/account-expiry'; +import { closeToExpiry, hasExpired } from '../shared/account-expiry'; import { IApplication } from '../shared/application-types'; import BridgeSettingsBuilder from '../shared/bridge-settings-builder'; import { @@ -1052,8 +1052,16 @@ class ApplicationMain { windowController.window?.on('show', () => { // cancel notifications when window appears this.notificationController.cancelPendingNotifications(); + }); - this.updateAccountData(); + windowController.window?.on('focus', () => { + if ( + !this.accountData || + closeToExpiry(this.accountData.expiry, 4) || + hasExpired(this.accountData.expiry) + ) { + this.updateAccountData(); + } }); windowController.window?.on('hide', () => { diff --git a/gui/src/shared/account-expiry.ts b/gui/src/shared/account-expiry.ts index 7ca382efb2..81c45fec07 100644 --- a/gui/src/shared/account-expiry.ts +++ b/gui/src/shared/account-expiry.ts @@ -5,10 +5,10 @@ export function hasExpired(expiry: DateType): boolean { return new Date(expiry).getTime() < Date.now(); } -export function closeToExpiry(expiry: DateType): boolean { +export function closeToExpiry(expiry: DateType, days = 3): boolean { return ( !hasExpired(expiry) && - new Date(expiry) <= dateByAddingComponent(new Date(), DateComponent.day, 3) + new Date(expiry) <= dateByAddingComponent(new Date(), DateComponent.day, days) ); } |
