diff options
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/account-data-cache.ts | 15 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 4 |
2 files changed, 17 insertions, 2 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts index 97a94eb7c3..7db2c05ca8 100644 --- a/gui/src/main/account-data-cache.ts +++ b/gui/src/main/account-data-cache.ts @@ -1,7 +1,10 @@ import log from 'electron-log'; +import moment from 'moment'; import { AccountToken, IAccountData } from '../shared/daemon-rpc-types'; import consumePromise from '../shared/promise'; +const EXPIRED_ACCOUNT_REFRESH_PERIOD = 60_000; + export enum AccountFetchRetryAction { stop, retry, @@ -77,6 +80,7 @@ export default class AccountDataCache { if (this.currentAccount === accountToken) { this.setValue(accountData); + this.scheduleRefetchIfExpired(accountToken, accountData); } } catch (error) { if (this.currentAccount === accountToken) { @@ -85,6 +89,13 @@ export default class AccountDataCache { } } + private scheduleRefetchIfExpired(accountToken: AccountToken, accountData: IAccountData) { + const hasExpired = moment(accountData.expiry).isSameOrBefore(new Date()); + if (hasExpired) { + this.scheduleFetch(accountToken, EXPIRED_ACCOUNT_REFRESH_PERIOD); + } + } + private handleFetchError(accountToken: AccountToken, error: Error) { let shouldRetry = true; @@ -107,6 +118,10 @@ export default class AccountDataCache { log.warn(`Failed to fetch account data. Retrying in ${delay} ms`); + this.scheduleFetch(accountToken, delay); + } + + private scheduleFetch(accountToken: AccountToken, delay: number) { this.fetchRetryTimeout = global.setTimeout(() => { this.fetchRetryTimeout = undefined; consumePromise(this.performFetch(accountToken)); diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 01aec17d62..28956d8c88 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -901,7 +901,7 @@ class ApplicationMain { // cancel notifications when window appears this.notificationController.cancelPendingNotifications(); - this.updateAccountExpiryIfNeeded(); + this.updateAccountData(); }); windowController.window.on('hide', () => { @@ -1159,7 +1159,7 @@ class ApplicationMain { } } - private updateAccountExpiryIfNeeded() { + private updateAccountData() { if (this.connectedToDaemon && this.settings.accountToken) { this.accountDataCache.fetch(this.settings.accountToken); } |
