From 839d4b37bddb7579b96e1554f3c5854fc8890aa8 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 12 Jan 2024 18:14:36 -0800 Subject: [PATCH] Add signal usage example in `pulsar-updater` Whenever `pulsar-updater` shows a notification in any window, it will send a signal to all other windows when that notification is dismissed. The other windows can dismiss any of their `pulsar-updater` notifications. This allows the user to dismiss _one_ notification instead of one per window. --- packages/pulsar-updater/src/main.js | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/pulsar-updater/src/main.js b/packages/pulsar-updater/src/main.js index ef2875c1d..301dd9d61 100644 --- a/packages/pulsar-updater/src/main.js +++ b/packages/pulsar-updater/src/main.js @@ -73,16 +73,43 @@ class PulsarUpdater { } else { // This can be a no-op or something that generates an actual notification // based on how the update check was invoked. - await this.notifyAboutCurrent(latestVersion, manual); + this.notifyAboutCurrent(latestVersion, manual); } } + dismissIfDismissedInAnotherWindow(notification) { + if (!atom.signal) return; + let disposables = new CompositeDisposable(); + let dismissedInAnotherWindow = false; + disposables.add( + // If we get this signal from another window, it means this notification + // has already been dismissed in that window, so we should dismiss ours + // as well. + atom.signal.onMessage('pulsar-notifier', message => { + if (message.type === 'dismiss') { + dismissedInAnotherWindow = true; + notification.dismiss(); + } + }), + + notification.onDidDismiss(() => { + disposables.dispose(); + if (!dismissedInAnotherWindow) { + // If we haven't gotten a signal from another window, we're the first + // one to dismiss, so we should send a signal to all the others. + atom.signal.send('pulsar-notifier', { type: 'dismiss' }); + } + }) + ); + } + notifyAboutCurrent(latestVersion, manual) { if (!manual) return; - atom.notifications.addInfo( + let notification = atom.notifications.addInfo( "Pulsar is already up to date.", { dismissable: true } ); + this.dismissIfDismissedInAnotherWindow(notification); } async notifyAboutUpdate(latestVersion) { @@ -138,6 +165,7 @@ class PulsarUpdater { ], } ); + this.dismissIfDismissedInAnotherWindow(notification); } ignoreForThisVersion(version) {