summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-07-15 14:58:27 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-07-22 15:49:04 +0200
commit7f5f6a3d0e4a61784ca75b53e4850c4dec108d95 (patch)
tree4f55aae0c81e3e2f034ca61df4301abde6ec6963 /gui
parentf694c41fc4bd5b16b63c2ec6edb83d0dcce75d37 (diff)
downloadmullvadvpn-7f5f6a3d0e4a61784ca75b53e4850c4dec108d95.tar.xz
mullvadvpn-7f5f6a3d0e4a61784ca75b53e4850c4dec108d95.zip
Add notification action buttons in macOS
Diffstat (limited to 'gui')
-rw-r--r--gui/src/main/notification-controller.ts31
-rw-r--r--gui/src/shared/notifications/account-expired.ts7
-rw-r--r--gui/src/shared/notifications/close-to-account-expiry.ts7
-rw-r--r--gui/src/shared/notifications/notification.ts7
-rw-r--r--gui/src/shared/notifications/unsupported-version.ts6
5 files changed, 42 insertions, 16 deletions
diff --git a/gui/src/main/notification-controller.ts b/gui/src/main/notification-controller.ts
index c011ce7665..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,
@@ -117,24 +118,30 @@ export default class NotificationController {
timeoutType: systemNotification.critical ? 'never' : 'default',
});
- if (systemNotification.action) {
- notification.on('click', () => {
- consumePromise(
- this.notificationControllerDelegate.openLink(
- systemNotification.action!.url,
- systemNotification.action!.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 {
- notification.on('click', () => {
- this.notificationControllerDelegate.openApp();
- });
+ 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,
};