summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-07-22 15:49:24 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-07-22 15:49:24 +0200
commita40f663811ab1f5962cfe4b82e3d21b59b338731 (patch)
treed19ccf9f28f79b673999f454faa965cf5d6f085a /gui/src/main
parentbcd90f658557b7a01e03eb97d9d21ef817e4b07a (diff)
parent02a1881ba3d6fec79e0ecf2095fc3fbafa9e2ce8 (diff)
downloadmullvadvpn-a40f663811ab1f5962cfe4b82e3d21b59b338731.tar.xz
mullvadvpn-a40f663811ab1f5962cfe4b82e3d21b59b338731.zip
Merge branch 'improve-notification-timeout'
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/index.ts1
-rw-r--r--gui/src/main/notification-controller.ts31
2 files changed, 26 insertions, 6 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;