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: "/",
});
notifier.on("click", function (notifierObject, options, event) {
open("");
});
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.
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./",
});
notifier.on("click", function (notifierObject, options, event) {
open("https://sindresorhus.");
});
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.
Share Improve this question edited Jun 10, 2020 at 15:34 doğukan asked Jun 4, 2020 at 11:28 doğukandoğukan 27.7k13 gold badges63 silver badges75 bronze badges 2-
It doesn't even enter the
click
event callback? – Danyal Commented Jun 6, 2020 at 19:05 - @Danyal no..... – doğukan Commented Jun 6, 2020 at 20:45
1 Answer
Reset to default 7 +50Action 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."
}).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./mikaelbr/node-notifier/issues/291#issuement-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.') })
Another possibility if you're confident and would rather fix the library itself:
https://github./mikaelbr/node-notifier/blob/v5.4.3/notifiers/toaster.js#L63
https://github./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).