diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2023-04-13 08:57:54 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2023-04-17 14:14:07 +0200 |
| commit | 124e7774c82d8b6ec80be2af5d973b350698bb9c (patch) | |
| tree | 5c088bbe618cb5c3a876c26bd3275183e2cb985f /gui/src | |
| parent | 025a88ecd26d85a1ab8fcedf421ce774de361a0a (diff) | |
| download | mullvadvpn-124e7774c82d8b6ec80be2af5d973b350698bb9c.tar.xz mullvadvpn-124e7774c82d8b6ec80be2af5d973b350698bb9c.zip | |
Add tests for notification evaluation
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/notification-controller.ts | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/gui/src/main/notification-controller.ts b/gui/src/main/notification-controller.ts index 04cb8afcb9..f5b7b631ad 100644 --- a/gui/src/main/notification-controller.ts +++ b/gui/src/main/notification-controller.ts @@ -85,7 +85,7 @@ export default class NotificationController { hasExcludedApps: boolean, isWindowVisible: boolean, areSystemNotificationsEnabled: boolean, - ) { + ): boolean { const notificationProviders: SystemNotificationProvider[] = [ new ConnectingNotificationProvider({ tunnelState, reconnecting: this.reconnecting }), new ConnectedNotificationProvider(tunnelState), @@ -98,11 +98,14 @@ export default class NotificationController { notification.mayDisplay(), ); + this.reconnecting = + tunnelState.state === 'disconnecting' && tunnelState.details === 'reconnect'; + if (notificationProvider) { const notification = notificationProvider.getSystemNotification(); if (notification) { - this.notify(notification, isWindowVisible, areSystemNotificationsEnabled); + return this.notify(notification, isWindowVisible, areSystemNotificationsEnabled); } else { log.error( `Notification providers mayDisplay() returned true but getSystemNotification() returned undefined for ${notificationProvider.constructor.name}`, @@ -112,8 +115,7 @@ export default class NotificationController { this.closeNotificationsInCategory(SystemNotificationCategory.tunnelState); } - this.reconnecting = - tunnelState.state === 'disconnecting' && tunnelState.details === 'reconnect'; + return false; } // Closes still relevant notifications but still lets them affect notification dot in tray icon. @@ -150,7 +152,7 @@ export default class NotificationController { systemNotification: SystemNotification, windowVisible: boolean, infoNotificationsEnabled: boolean, - ) { + ): boolean { const notificationSuppressReason = this.evaluateNotification( systemNotification, windowVisible, @@ -165,7 +167,7 @@ export default class NotificationController { this.updateNotificationIcon(); } - return; + return false; } // Cancel throttled notifications within the same category @@ -186,8 +188,10 @@ export default class NotificationController { }, THROTTLE_DELAY); this.throttledNotifications.set(systemNotification, scheduler); + return true; } else { this.notifyImpl(systemNotification); + return true; } } @@ -210,14 +214,7 @@ export default class NotificationController { } private createNotification(systemNotification: SystemNotification): Notification { - const notification = new ElectronNotification({ - title: this.notificationTitle, - body: systemNotification.message, - silent: true, - icon: this.notificationIcon, - timeoutType: - systemNotification.severity == SystemNotificationSeverityType.high ? 'never' : 'default', - }); + const notification = this.createElectronNotification(systemNotification); // Action buttons are only available on macOS. if (process.platform === 'darwin') { @@ -242,6 +239,17 @@ export default class NotificationController { return { specification: systemNotification, notification }; } + private createElectronNotification(systemNotification: SystemNotification): ElectronNotification { + return new ElectronNotification({ + title: this.notificationTitle, + body: systemNotification.message, + silent: true, + icon: this.notificationIcon, + timeoutType: + systemNotification.severity == SystemNotificationSeverityType.high ? 'never' : 'default', + }); + } + private performAction(action?: NotificationAction) { if (action && action.type === 'open-url') { void this.notificationControllerDelegate.openLink(action.url, action.withAuth); |
