summaryrefslogtreecommitdiffhomepage
path: root/app/notification-controller.js
diff options
context:
space:
mode:
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();
+ }
+ }
+}