diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-07-22 15:49:24 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-07-22 15:49:24 +0200 |
| commit | a40f663811ab1f5962cfe4b82e3d21b59b338731 (patch) | |
| tree | d19ccf9f28f79b673999f454faa965cf5d6f085a /gui/src | |
| parent | bcd90f658557b7a01e03eb97d9d21ef817e4b07a (diff) | |
| parent | 02a1881ba3d6fec79e0ecf2095fc3fbafa9e2ce8 (diff) | |
| download | mullvadvpn-a40f663811ab1f5962cfe4b82e3d21b59b338731.tar.xz mullvadvpn-a40f663811ab1f5962cfe4b82e3d21b59b338731.zip | |
Merge branch 'improve-notification-timeout'
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/index.ts | 1 | ||||
| -rw-r--r-- | gui/src/main/notification-controller.ts | 31 | ||||
| -rw-r--r-- | gui/src/shared/notifications/account-expired.ts | 7 | ||||
| -rw-r--r-- | gui/src/shared/notifications/close-to-account-expiry.ts | 7 | ||||
| -rw-r--r-- | gui/src/shared/notifications/notification.ts | 7 | ||||
| -rw-r--r-- | gui/src/shared/notifications/unsupported-version.ts | 6 |
6 files changed, 49 insertions, 10 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index d6a01e6fd1..18dfc67d29 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -84,6 +84,7 @@ type AccountVerification = { status: 'verified' } | { status: 'deferred'; error: class ApplicationMain { private notificationController = new NotificationController({ + openApp: () => this.windowController?.show(), openLink: (url: string, withAuth?: boolean) => this.openLink(url, withAuth), isWindowVisible: () => this.windowController?.isVisible() ?? false, areSystemNotificationsEnabled: () => this.guiSettings.enableSystemNotifications, diff --git a/gui/src/main/notification-controller.ts b/gui/src/main/notification-controller.ts index 20c29d0a41..c5c30b42ef 100644 --- a/gui/src/main/notification-controller.ts +++ b/gui/src/main/notification-controller.ts @@ -9,6 +9,7 @@ import { ConnectingNotificationProvider, DisconnectedNotificationProvider, ErrorNotificationProvider, + NotificationAction, ReconnectingNotificationProvider, SystemNotification, SystemNotificationProvider, @@ -16,6 +17,7 @@ import { import consumePromise from '../shared/promise'; interface NotificationControllerDelegate { + openApp(): void; openLink(url: string, withAuth?: boolean): Promise<void>; isWindowVisible(): boolean; areSystemNotificationsEnabled(): boolean; @@ -97,7 +99,9 @@ export default class NotificationController { this.addPendingNotification(notification); notification.show(); - setTimeout(() => notification.close(), 4000); + if (!systemNotification.critical) { + setTimeout(() => notification.close(), 4000); + } return notification; } else { @@ -111,18 +115,33 @@ export default class NotificationController { body: systemNotification.message, silent: true, icon: this.notificationIcon, + timeoutType: systemNotification.critical ? 'never' : 'default', }); - if (systemNotification.action) { - const { withAuth, url } = systemNotification.action; - notification.on('click', () => { - consumePromise(this.notificationControllerDelegate.openLink(url, withAuth)); - }); + // Action buttons are only available on macOS. + if (process.platform === 'darwin') { + if (systemNotification.action) { + notification.actions = [{ type: 'button', text: systemNotification.action.text }]; + notification.on('action', () => this.performAction(systemNotification.action)); + } + notification.on('click', () => this.notificationControllerDelegate.openApp()); + } else { + if (systemNotification.action) { + notification.on('click', () => this.performAction(systemNotification.action)); + } else { + notification.on('click', () => this.notificationControllerDelegate.openApp()); + } } return notification; } + private performAction(action?: NotificationAction) { + if (action && action.type === 'open-url') { + consumePromise(this.notificationControllerDelegate.openLink(action.url, action.withAuth)); + } + } + private showTunnelStateNotification(systemNotification: SystemNotification) { const message = systemNotification.message; const lastAnnouncement = this.lastTunnelStateAnnouncement; diff --git a/gui/src/shared/notifications/account-expired.ts b/gui/src/shared/notifications/account-expired.ts index ea600aa577..c89845bc4b 100644 --- a/gui/src/shared/notifications/account-expired.ts +++ b/gui/src/shared/notifications/account-expired.ts @@ -28,7 +28,12 @@ export class AccountExpiredNotificationProvider implements SystemNotificationPro ), critical: true, presentOnce: { value: true, name: this.constructor.name }, - action: { type: 'open-url', url: links.purchase, withAuth: true }, + action: { + type: 'open-url', + url: links.purchase, + withAuth: true, + text: messages.pgettext('notifications', 'Buy more'), + }, }; } } diff --git a/gui/src/shared/notifications/close-to-account-expiry.ts b/gui/src/shared/notifications/close-to-account-expiry.ts index b30aff2542..ad1969929f 100644 --- a/gui/src/shared/notifications/close-to-account-expiry.ts +++ b/gui/src/shared/notifications/close-to-account-expiry.ts @@ -41,7 +41,12 @@ export class CloseToAccountExpiryNotificationProvider return { message, critical: true, - action: { type: 'open-url', url: links.purchase, withAuth: true }, + action: { + type: 'open-url', + url: links.purchase, + withAuth: true, + text: messages.pgettext('notifications', 'Buy more'), + }, }; } diff --git a/gui/src/shared/notifications/notification.ts b/gui/src/shared/notifications/notification.ts index 98b50d4d24..adbf3ae746 100644 --- a/gui/src/shared/notifications/notification.ts +++ b/gui/src/shared/notifications/notification.ts @@ -1,4 +1,9 @@ -export type NotificationAction = { type: 'open-url'; url: string; withAuth?: boolean }; +export type NotificationAction = { + type: 'open-url'; + url: string; + text?: string; + withAuth?: boolean; +}; export type InAppNotificationIndicatorType = 'success' | 'warning' | 'error'; diff --git a/gui/src/shared/notifications/unsupported-version.ts b/gui/src/shared/notifications/unsupported-version.ts index fd2e0b5c72..097a142815 100644 --- a/gui/src/shared/notifications/unsupported-version.ts +++ b/gui/src/shared/notifications/unsupported-version.ts @@ -27,7 +27,11 @@ export class UnsupportedVersionNotificationProvider return { message, critical: true, - action: { type: 'open-url', url: links.download }, + action: { + type: 'open-url', + url: links.download, + text: messages.pgettext('notifications', 'Upgrade'), + }, presentOnce: { value: true, name: this.constructor.name }, suppressInDevelopment: true, }; |
