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.
This commit is contained in:
Andrew Dupont 2024-01-12 18:14:36 -08:00
parent be068ea38c
commit 839d4b37bd

View File

@ -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) {