diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-11-30 15:00:30 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2023-02-09 10:39:26 +0100 |
| commit | b00d0b5a176c4d8dcd403a60395c5a1087c42cdd (patch) | |
| tree | 188a7c4eeb204a1e81cb9504a8c59b10a85355ea /gui/src | |
| parent | 9bc388cd020d0e4fc675e02b20522f31c2464885 (diff) | |
| download | mullvadvpn-b00d0b5a176c4d8dcd403a60395c5a1087c42cdd.tar.xz mullvadvpn-b00d0b5a176c4d8dcd403a60395c5a1087c42cdd.zip | |
Add notification categories
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/notification-controller.ts | 26 | ||||
| -rw-r--r-- | gui/src/shared/notifications/block-when-disconnected.ts | 3 | ||||
| -rw-r--r-- | gui/src/shared/notifications/connected.ts | 3 | ||||
| -rw-r--r-- | gui/src/shared/notifications/connecting.ts | 3 | ||||
| -rw-r--r-- | gui/src/shared/notifications/disconnected.ts | 3 | ||||
| -rw-r--r-- | gui/src/shared/notifications/error.ts | 3 | ||||
| -rw-r--r-- | gui/src/shared/notifications/notification.ts | 6 | ||||
| -rw-r--r-- | gui/src/shared/notifications/reconnecting.ts | 3 |
8 files changed, 34 insertions, 16 deletions
diff --git a/gui/src/main/notification-controller.ts b/gui/src/main/notification-controller.ts index 33149bcae8..cf703e431c 100644 --- a/gui/src/main/notification-controller.ts +++ b/gui/src/main/notification-controller.ts @@ -28,8 +28,8 @@ export interface NotificationControllerDelegate { export default class NotificationController { private lastTunnelStateAnnouncement?: { body: string; notification: Notification }; private reconnecting = false; - private presentedNotifications: { [key: string]: boolean } = {}; - private pendingNotifications: Notification[] = []; + private previousNotifications: { [key: string]: boolean } = {}; + private activeNotifications: Notification[] = []; private notificationTitle = process.platform === 'linux' ? app.name : ''; private notificationIcon?: NativeImage; @@ -91,7 +91,7 @@ export default class NotificationController { } public cancelPendingNotifications() { - for (const notification of this.pendingNotifications) { + for (const notification of this.activeNotifications) { notification.close(); } } @@ -109,7 +109,7 @@ export default class NotificationController { this.evaluateNotification(systemNotification, isWindowVisible, areSystemNotificationsEnabled) ) { const notification = this.createNotification(systemNotification); - this.addPendingNotification(notification); + this.addActiveNotification(notification); notification.show(); return notification; @@ -188,19 +188,13 @@ export default class NotificationController { } } - private addPendingNotification(notification: Notification) { - notification.on('close', () => { - this.removePendingNotification(notification); - }); - - this.pendingNotifications.push(notification); + private addActiveNotification(notification: Notification) { + notification.on('close', () => this.removeActiveNotification(notification)); + this.activeNotifications.push(notification); } - private removePendingNotification(notification: Notification) { - const index = this.pendingNotifications.indexOf(notification); - if (index !== -1) { - this.pendingNotifications.splice(index, 1); - } + private removeActiveNotification(notification: Notification) { + this.activeNotifications = this.activeNotifications.filter((value) => value !== notification); } private evaluateNotification( @@ -223,7 +217,7 @@ export default class NotificationController { } private suppressDueToAlreadyPresented(notification: SystemNotification) { - const presented = this.presentedNotifications; + const presented = this.previousNotifications; if (notification.presentOnce?.value) { if (presented[notification.presentOnce.name]) { return true; diff --git a/gui/src/shared/notifications/block-when-disconnected.ts b/gui/src/shared/notifications/block-when-disconnected.ts index 0eada4036c..3d7ec1e509 100644 --- a/gui/src/shared/notifications/block-when-disconnected.ts +++ b/gui/src/shared/notifications/block-when-disconnected.ts @@ -7,6 +7,7 @@ import { InAppNotification, InAppNotificationProvider, SystemNotification, + SystemNotificationCategory, SystemNotificationProvider, SystemNotificationSeverityType, } from './notification'; @@ -35,6 +36,8 @@ export class BlockWhenDisconnectedNotificationProvider return { message, severity: SystemNotificationSeverityType.info, + category: SystemNotificationCategory.tunnelState, + replaceByCategory: true, }; } diff --git a/gui/src/shared/notifications/connected.ts b/gui/src/shared/notifications/connected.ts index bcce249a15..d695df1c95 100644 --- a/gui/src/shared/notifications/connected.ts +++ b/gui/src/shared/notifications/connected.ts @@ -4,6 +4,7 @@ import { messages } from '../../shared/gettext'; import { TunnelState } from '../daemon-rpc-types'; import { SystemNotification, + SystemNotificationCategory, SystemNotificationProvider, SystemNotificationSeverityType, } from './notification'; @@ -32,6 +33,8 @@ export class ConnectedNotificationProvider implements SystemNotificationProvider return { message, severity: SystemNotificationSeverityType.low, + category: SystemNotificationCategory.tunnelState, + replaceByCategory: true, }; } else { return undefined; diff --git a/gui/src/shared/notifications/connecting.ts b/gui/src/shared/notifications/connecting.ts index bf8d3b1248..e722e7fb95 100644 --- a/gui/src/shared/notifications/connecting.ts +++ b/gui/src/shared/notifications/connecting.ts @@ -6,6 +6,7 @@ import { InAppNotification, InAppNotificationProvider, SystemNotification, + SystemNotificationCategory, SystemNotificationProvider, SystemNotificationSeverityType, } from './notification'; @@ -42,6 +43,8 @@ export class ConnectingNotificationProvider return { message, severity: SystemNotificationSeverityType.low, + category: SystemNotificationCategory.tunnelState, + replaceByCategory: true, }; } else { return undefined; diff --git a/gui/src/shared/notifications/disconnected.ts b/gui/src/shared/notifications/disconnected.ts index 66a1e9d66e..531c95d015 100644 --- a/gui/src/shared/notifications/disconnected.ts +++ b/gui/src/shared/notifications/disconnected.ts @@ -2,6 +2,7 @@ import { messages } from '../../shared/gettext'; import { TunnelState } from '../daemon-rpc-types'; import { SystemNotification, + SystemNotificationCategory, SystemNotificationProvider, SystemNotificationSeverityType, } from './notification'; @@ -21,6 +22,8 @@ export class DisconnectedNotificationProvider implements SystemNotificationProvi return { message: messages.pgettext('notifications', 'Disconnected and unsecure'), severity: SystemNotificationSeverityType.info, + category: SystemNotificationCategory.tunnelState, + replaceByCategory: true, }; } } diff --git a/gui/src/shared/notifications/error.ts b/gui/src/shared/notifications/error.ts index f066bc1040..e878f5ef19 100644 --- a/gui/src/shared/notifications/error.ts +++ b/gui/src/shared/notifications/error.ts @@ -13,6 +13,7 @@ import { InAppNotification, InAppNotificationProvider, SystemNotification, + SystemNotificationCategory, SystemNotificationProvider, SystemNotificationSeverityType, } from './notification'; @@ -47,6 +48,8 @@ export class ErrorNotificationProvider this.context.tunnelState.details.blockingError === undefined ? SystemNotificationSeverityType.low : SystemNotificationSeverityType.high, + category: SystemNotificationCategory.tunnelState, + replaceByCategory: false, }; } else { return undefined; diff --git a/gui/src/shared/notifications/notification.ts b/gui/src/shared/notifications/notification.ts index af95baa558..873f7b2f4a 100644 --- a/gui/src/shared/notifications/notification.ts +++ b/gui/src/shared/notifications/notification.ts @@ -14,6 +14,10 @@ export enum SystemNotificationSeverityType { high, } +export enum SystemNotificationCategory { + tunnelState, +} + interface NotificationProvider { mayDisplay(): boolean; } @@ -21,6 +25,8 @@ interface NotificationProvider { export interface SystemNotification { message: string; severity: SystemNotificationSeverityType; + category?: SystemNotificationCategory; + replaceByCategory?: boolean; presentOnce?: { value: boolean; name: string }; suppressInDevelopment?: boolean; action?: NotificationAction; diff --git a/gui/src/shared/notifications/reconnecting.ts b/gui/src/shared/notifications/reconnecting.ts index caea454eff..08eb36b18d 100644 --- a/gui/src/shared/notifications/reconnecting.ts +++ b/gui/src/shared/notifications/reconnecting.ts @@ -4,6 +4,7 @@ import { InAppNotification, InAppNotificationProvider, SystemNotification, + SystemNotificationCategory, SystemNotificationProvider, SystemNotificationSeverityType, } from './notification'; @@ -20,6 +21,8 @@ export class ReconnectingNotificationProvider return { message: messages.pgettext('notifications', 'Reconnecting'), severity: SystemNotificationSeverityType.info, + category: SystemNotificationCategory.tunnelState, + replaceByCategory: true, }; } |
