From fc7016fbaa4d7562c01df6903c0b1c5e50763f15 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 8 Nov 2016 11:06:20 -0800 Subject: [PATCH] fix(notifs): Re-display notifs with the same tag on macOS --- src/native-notifications.es6 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/native-notifications.es6 b/src/native-notifications.es6 index b0c2b5e99..82c7afefc 100644 --- a/src/native-notifications.es6 +++ b/src/native-notifications.es6 @@ -9,10 +9,24 @@ if (process.platform === 'darwin') { } class NativeNotifications { + constructor() { + if (MacNotifierNotification) { + this._macNotificationsByTag = {}; + NylasEnv.onBeforeUnload(() => { + Object.keys(this._macNotificationsByTag).forEach((key) => { + this._macNotificationsByTag[key].close(); + }); + return true; + }); + } + } displayNotification({title, subtitle, body, tag, canReply, onActivate} = {}) { let notif = null; if (MacNotifierNotification) { + if (tag && this._macNotificationsByTag[tag]) { + this._macNotificationsByTag[tag].close(); + } notif = new MacNotifierNotification(title, { bundleId: 'com.nylas.nylas-mail', canReply: canReply, @@ -26,6 +40,9 @@ class NativeNotifications { notif.addEventListener('click', () => { onActivate({response: null, activationType: 'clicked'}); }); + if (tag) { + this._macNotificationsByTag[tag] = notif; + } } else { notif = new Notification(title, { silent: true,