summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2023-02-09 19:25:56 +0100
committerOskar Nyberg <oskar@mullvad.net>2023-02-10 16:35:22 +0100
commitbaae4206897979557814160956f0782f619fbddf (patch)
tree1ef6d07874452c2b0f37f2c7d80e98e9936e9122
parenteae319abc221181b3a15b6ea487712b3ec44c140 (diff)
downloadmullvadvpn-baae4206897979557814160956f0782f619fbddf.tar.xz
mullvadvpn-baae4206897979557814160956f0782f619fbddf.zip
Add scheduler for first notification
-rw-r--r--CHANGELOG.md3
-rw-r--r--gui/src/main/account.ts23
2 files changed, 21 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03543913e9..07d53e86dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,9 @@ Line wrap the file at 100 chars. Th
deprecating it on Windows.
### Fixed
+- Fix close to expiry notification not showing unless app is opened once within the last three days
+ in the desktop app.
+
#### Android
- Fix adaptive app icon which previously had a displaced nose and some other oddities.
diff --git a/gui/src/main/account.ts b/gui/src/main/account.ts
index 564880fe61..0b992cee88 100644
--- a/gui/src/main/account.ts
+++ b/gui/src/main/account.ts
@@ -33,7 +33,9 @@ export interface AccountDelegate {
export default class Account {
private accountDataValue?: IAccountData = undefined;
private accountHistoryValue?: AccountToken = undefined;
- private accountExpiryNotificationScheduler = new Scheduler();
+ private expiryNotificationFrequencyScheduler = new Scheduler();
+ private firstExpiryNotificationScheduler = new Scheduler();
+
private accountDataCache = new AccountDataCache(
(accountToken) => {
return this.daemonRpc.getAccountData(accountToken);
@@ -179,7 +181,8 @@ export default class Account {
try {
await this.daemonRpc.logoutAccount();
- this.accountExpiryNotificationScheduler.cancel();
+ this.expiryNotificationFrequencyScheduler.cancel();
+ this.firstExpiryNotificationScheduler.cancel();
} catch (e) {
const error = e as Error;
log.info(`Failed to logout: ${error.message}`);
@@ -200,21 +203,31 @@ export default class Account {
});
if (expiredNotification.mayDisplay()) {
- this.accountExpiryNotificationScheduler.cancel();
+ this.expiryNotificationFrequencyScheduler.cancel();
+ this.firstExpiryNotificationScheduler.cancel();
this.delegate.notify(expiredNotification.getSystemNotification());
} else if (
- !this.accountExpiryNotificationScheduler.isRunning &&
+ !this.expiryNotificationFrequencyScheduler.isRunning &&
closeToExpiryNotification.mayDisplay()
) {
+ this.firstExpiryNotificationScheduler.cancel();
this.delegate.notify(closeToExpiryNotification.getSystemNotification());
const twelveHours = 12 * 60 * 60 * 1000;
const remainingMilliseconds = new Date(this.accountData.expiry).getTime() - Date.now();
const delay = Math.min(twelveHours, remainingMilliseconds);
- this.accountExpiryNotificationScheduler.schedule(() => this.handleAccountExpiry(), delay);
+ this.expiryNotificationFrequencyScheduler.schedule(() => this.handleAccountExpiry(), delay);
} else if (!closeToExpiry(this.accountData.expiry)) {
+ this.expiryNotificationFrequencyScheduler.cancel();
// If no longer close to expiry, all previous notifications should be closed
this.delegate.closeNotificationsInCategory(SystemNotificationCategory.expiry);
+
+ const expiry = new Date(this.accountData.expiry).getTime();
+ const now = new Date().getTime();
+ const threeDays = 3 * 24 * 60 * 60 * 1000;
+ // Add 10 seconds to be on the safe side
+ const timeout = expiry - now - threeDays + 10_000;
+ this.firstExpiryNotificationScheduler.schedule(() => this.handleAccountExpiry(), timeout);
}
}
}