diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-12-01 15:53:52 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2023-02-09 10:39:26 +0100 |
| commit | ed97852d98976ced51bcd46650e7a465d6b3101f (patch) | |
| tree | e86212b533121a2f291f3dffc1162a6e4e115f18 /gui/src | |
| parent | 98b6bd1d3c879fd3be6e84ded04888758299dca5 (diff) | |
| download | mullvadvpn-ed97852d98976ced51bcd46650e7a465d6b3101f.tar.xz mullvadvpn-ed97852d98976ced51bcd46650e7a465d6b3101f.zip | |
Close notifications when they are no longer relevant
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/account.ts | 5 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 24 | ||||
| -rw-r--r-- | gui/src/main/notification-controller.ts | 18 | ||||
| -rw-r--r-- | gui/src/main/version.ts | 5 | ||||
| -rw-r--r-- | gui/src/shared/notifications/inconsistent-version.ts | 2 | ||||
| -rw-r--r-- | gui/src/shared/notifications/notification.ts | 3 | ||||
| -rw-r--r-- | gui/src/shared/notifications/unsupported-version.ts | 2 | ||||
| -rw-r--r-- | gui/src/shared/notifications/update-available.ts | 2 |
8 files changed, 43 insertions, 18 deletions
diff --git a/gui/src/main/account.ts b/gui/src/main/account.ts index 00a3bf0dfd..564880fe61 100644 --- a/gui/src/main/account.ts +++ b/gui/src/main/account.ts @@ -1,3 +1,4 @@ +import { closeToExpiry } from '../shared/account-expiry'; import { AccountToken, DeviceEvent, @@ -11,6 +12,7 @@ import log from '../shared/logging'; import { AccountExpiredNotificationProvider, CloseToAccountExpiryNotificationProvider, + SystemNotificationCategory, } from '../shared/notifications/notification'; import { Scheduler } from '../shared/scheduler'; import AccountDataCache from './account-data-cache'; @@ -210,6 +212,9 @@ export default class Account { const remainingMilliseconds = new Date(this.accountData.expiry).getTime() - Date.now(); const delay = Math.min(twelveHours, remainingMilliseconds); this.accountExpiryNotificationScheduler.schedule(() => this.handleAccountExpiry(), delay); + } else if (!closeToExpiry(this.accountData.expiry)) { + // If no longer close to expiry, all previous notifications should be closed + this.delegate.closeNotificationsInCategory(SystemNotificationCategory.expiry); } } } diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 824e354333..51ce0667ac 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -20,7 +20,10 @@ import { ITranslations, MacOsScrollbarVisibility } from '../shared/ipc-schema'; import { IChangelog, IHistoryObject } from '../shared/ipc-types'; import log, { ConsoleOutput, Logger } from '../shared/logging'; import { LogLevel } from '../shared/logging-types'; -import { SystemNotification } from '../shared/notifications/notification'; +import { + SystemNotification, + SystemNotificationCategory, +} from '../shared/notifications/notification'; import Account, { AccountDelegate, LocaleProvider } from './account'; import { getOpenAtLogin } from './autostart'; import { readChangelog } from './changelog'; @@ -211,14 +214,6 @@ class ApplicationMain public isLoggedIn = () => this.account.isLoggedIn(); - public notify = (notification: SystemNotification) => { - this.notificationController.notify( - notification, - this.userInterface?.isWindowVisible() ?? false, - this.settings.gui.enableSystemNotifications, - ); - }; - public disconnectAndQuit = async () => { if (this.daemonRpc.isConnected) { try { @@ -947,6 +942,17 @@ class ApplicationMain } }; + // NotificationSender + public notify = (notification: SystemNotification) => { + this.notificationController.notify( + notification, + this.userInterface?.isWindowVisible() ?? false, + this.settings.gui.enableSystemNotifications, + ); + }; + public closeNotificationsInCategory = (category: SystemNotificationCategory) => + this.notificationController.closeNotificationsInCategory(category); + // UserInterfaceDelegate public closeActiveNotifications = () => this.notificationController.closeActiveNotifications(); public isUnpinnedWindow = () => this.settings.gui.unpinnedWindow; diff --git a/gui/src/main/notification-controller.ts b/gui/src/main/notification-controller.ts index 67f54d7e06..9c75b68629 100644 --- a/gui/src/main/notification-controller.ts +++ b/gui/src/main/notification-controller.ts @@ -12,6 +12,7 @@ import { NotificationAction, ReconnectingNotificationProvider, SystemNotification, + SystemNotificationCategory, SystemNotificationProvider, SystemNotificationSeverityType, } from '../shared/notifications/notification'; @@ -26,6 +27,7 @@ export interface Notification { export interface NotificationSender { notify(notification: SystemNotification): void; + closeNotificationsInCategory(category: SystemNotificationCategory): void; } export interface NotificationControllerDelegate { @@ -96,6 +98,8 @@ export default class NotificationController { `Notification providers mayDisplay() returned true but getSystemNotification() returned undefined for ${notificationProvider.constructor.name}`, ); } + } else { + this.closeNotificationsInCategory(SystemNotificationCategory.tunnelState); } this.reconnecting = @@ -106,6 +110,14 @@ export default class NotificationController { this.activeNotifications.forEach((notification) => notification.notification.close()); } + public closeNotificationsInCategory(category: SystemNotificationCategory) { + this.activeNotifications.forEach((notification) => { + if (notification.specification.category === category) { + notification.notification.close(); + } + }); + } + public notify( systemNotification: SystemNotification, windowVisible: boolean, @@ -141,11 +153,7 @@ export default class NotificationController { private notifyImpl(systemNotification: SystemNotification): Notification { // Remove notifications in the same category if specified if (systemNotification.category !== undefined) { - this.activeNotifications.forEach((notification) => { - if (notification.specification.category === systemNotification.category) { - notification.notification.close(); - } - }); + this.closeNotificationsInCategory(systemNotification.category); } const notification = this.createNotification(systemNotification); diff --git a/gui/src/main/version.ts b/gui/src/main/version.ts index 5e45203c6c..fbe5b64574 100644 --- a/gui/src/main/version.ts +++ b/gui/src/main/version.ts @@ -5,6 +5,7 @@ import { ICurrentAppVersionInfo } from '../shared/ipc-types'; import log from '../shared/logging'; import { InconsistentVersionNotificationProvider, + SystemNotificationCategory, UnsupportedVersionNotificationProvider, UpdateAvailableNotificationProvider, } from '../shared/notifications/notification'; @@ -65,6 +66,8 @@ export default class Version { }); if (notificationProvider.mayDisplay()) { this.delegate.notify(notificationProvider.getSystemNotification()); + } else { + this.delegate.closeNotificationsInCategory(SystemNotificationCategory.inconsistentVersion); } // notify renderer @@ -105,6 +108,8 @@ export default class Version { ); if (notificationProvider) { this.delegate.notify(notificationProvider.getSystemNotification()); + } else { + this.delegate.closeNotificationsInCategory(SystemNotificationCategory.newVersion); } IpcMainEventChannel.upgradeVersion.notify?.(upgradeVersion); diff --git a/gui/src/shared/notifications/inconsistent-version.ts b/gui/src/shared/notifications/inconsistent-version.ts index f6f3cf4166..f4a5616c43 100644 --- a/gui/src/shared/notifications/inconsistent-version.ts +++ b/gui/src/shared/notifications/inconsistent-version.ts @@ -21,7 +21,7 @@ export class InconsistentVersionNotificationProvider public getSystemNotification(): SystemNotification { return { message: messages.pgettext('notifications', 'App is out of sync. Please quit and restart.'), - category: SystemNotificationCategory.version, + category: SystemNotificationCategory.inconsistentVersion, severity: SystemNotificationSeverityType.high, presentOnce: { value: true, name: this.constructor.name }, suppressInDevelopment: true, diff --git a/gui/src/shared/notifications/notification.ts b/gui/src/shared/notifications/notification.ts index 2fd0a47a37..10b5b21fc8 100644 --- a/gui/src/shared/notifications/notification.ts +++ b/gui/src/shared/notifications/notification.ts @@ -17,7 +17,8 @@ export enum SystemNotificationSeverityType { export enum SystemNotificationCategory { tunnelState, expiry, - version, + newVersion, + inconsistentVersion, } interface NotificationProvider { diff --git a/gui/src/shared/notifications/unsupported-version.ts b/gui/src/shared/notifications/unsupported-version.ts index 6c9c380595..8c2f87460b 100644 --- a/gui/src/shared/notifications/unsupported-version.ts +++ b/gui/src/shared/notifications/unsupported-version.ts @@ -27,7 +27,7 @@ export class UnsupportedVersionNotificationProvider public getSystemNotification(): SystemNotification { return { message: this.getMessage(), - category: SystemNotificationCategory.version, + category: SystemNotificationCategory.newVersion, severity: SystemNotificationSeverityType.high, action: { type: 'open-url', diff --git a/gui/src/shared/notifications/update-available.ts b/gui/src/shared/notifications/update-available.ts index 8e6bd7e76e..0394ef15a5 100644 --- a/gui/src/shared/notifications/update-available.ts +++ b/gui/src/shared/notifications/update-available.ts @@ -41,7 +41,7 @@ export class UpdateAvailableNotificationProvider public getSystemNotification(): SystemNotification { return { message: this.systemMessage(), - category: SystemNotificationCategory.version, + category: SystemNotificationCategory.newVersion, severity: SystemNotificationSeverityType.medium, action: { type: 'open-url', |
