summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
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/src/main
parentf694c41fc4bd5b16b63c2ec6edb83d0dcce75d37 (diff)
downloadmullvadvpn-7f5f6a3d0e4a61784ca75b53e4850c4dec108d95.tar.xz
mullvadvpn-7f5f6a3d0e4a61784ca75b53e4850c4dec108d95.zip
Add notification action buttons in macOS
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/notification-controller.ts31
1 files changed, 19 insertions, 12 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;