summaryrefslogtreecommitdiffhomepage
path: root/app/notification-controller.js
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-08-01 17:32:52 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-08-08 08:12:47 -0300
commitb7fccae454943a113022fe4403ca9a6920ffec13 (patch)
tree8bcc6709f88652f47bfc9434acc1f6d1291c2af6 /app/notification-controller.js
parent2c4d95cea476a0f038b731e13088d547465971c3 (diff)
downloadmullvadvpn-b7fccae454943a113022fe4403ca9a6920ffec13.tar.xz
mullvadvpn-b7fccae454943a113022fe4403ca9a6920ffec13.zip
Implement system notifications of connection state
Diffstat (limited to 'app/notification-controller.js')
-rw-r--r--app/notification-controller.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/notification-controller.js b/app/notification-controller.js
new file mode 100644
index 0000000000..62d6381e72
--- /dev/null
+++ b/app/notification-controller.js
@@ -0,0 +1,25 @@
+// @flow
+import { remote } from 'electron';
+
+export default class NotificationController {
+ _activeNotification: ?Notification;
+
+ show(message: string) {
+ const lastNotification = this._activeNotification;
+ const newNotification = new Notification(remote.app.getName(), { body: message, silent: true });
+
+ this._activeNotification = newNotification;
+
+ newNotification.addEventListener('show', () => {
+ // If the notification is closed too soon, it might still get shown. If that happens, close()
+ // should be called again so that it is closed immediately.
+ if (this._activeNotification !== newNotification) {
+ newNotification.close();
+ }
+ });
+
+ if (lastNotification) {
+ lastNotification.close();
+ }
+ }
+}