I'm simply send notifications using the node-notifier package. Also, when I click on the notification, it has to go to a link. But I can't listen the click event. The events provided by the package do nothing. This is my code:
const notifier = require("node-notifier");
const open = require("open");
notifier.notify({
title: "Stackoverflow",
message: "A message",
wait: true,
open: "https://stackoverflow.com/",
});
notifier.on("click", function (notifierObject, options, event) {
open("https://sindresorhus.com");
});
And this is my notification:
I can use any other package. I just want to listen click event.
@user120242's answer works but does not works clicking after the notification disappears. Is there any way? I added a gif.
Windows 10 puts notifications and quick actions in Action Center—right on the taskbar—where you can get to them instantly. Select Action Center on the taskbar to open it. (You can also swipe in from the right edge of your screen, or press Windows logo key + A.)
android.service.notification.NotificationListenerService. A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.
Manage notifications Windows 10: Select Start > Settings > System > Notifications & actions. Manage notifications MacOS: Select Apple menu > System Preferences > Notifications. Manage notifications Android: Select your phone's Settings app > Apps & Notifications>
A toast notification is a message that your app can construct and deliver to your user while they are not currently inside your app. This quickstart walks you through the steps to create, deliver, and display a Windows 10 or Windows 11 toast notification using rich content and interactive actions.
Action Center requires separate implementation in native code, which node-notifier doesn't have. You can try node-powertoast instead:
npm i node-powertoast
const toast = require('powertoast');
toast({
message: "Google It",
onClick: "https://www.google.com"
}).catch(err => console.error(err));
Callback functions onActivate are also supported. Check documentation in the link for more details.
How to fix node-notifier click event:
https://github.com/mikaelbr/node-notifier/issues/291#issuecomment-555741924
click not firing is affecting many people starting from after version 5
Due to changes in the use of the name of the action not being consistent.
You can rollback to 5.4.3, or use the suggestion of using the callback instead in the thread.
npm uninstall node-notifier
npm i node-notifier@5
Or:
notifier.notify({
... options
}, (err, action, metadata) => { if(action==='activate') { open('https://stackoverflow.com') })
Another possibility if you're confident and would rather fix the library itself:
https://github.com/mikaelbr/node-notifier/blob/v5.4.3/notifiers/toaster.js#L63
https://github.com/mikaelbr/node-notifier/blob/v5.4.3/lib/utils.js#L245
Patch those to account for 'activate' and emit 'click' (in master branch the "mapper" function no longer exists).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With