node-notifier click event not accessible in gulp-notify
Closed this issue · 6 comments
Hey there,
i wanted to use the onclick event mentioned in the node-notifier module to get a callback when a notification is clicked.
node-notifier api says:
notifier.on('click', function (notifierObject, options) {
// Happens if wait: true and user clicks notification
});
i went through the gulp-notify source code and couldn't find a way to get a callback for the click event on a notification.
I am also not able to get a reference to the reporter.
Is there anything i am missing or is it just not possible?
Edit:
What i forgot to mention is, that i know about the open, activate and execute properties, but what i want to do is, depending on what happened, open the source file at a specific line/column, e.g. subl /path/to/file.ts:9:10
I tried adding the click event by myself. i did the following
notify.js:52
notifier.on('click', function(notifierObject, options) {
stream.emit('click', notifierObject, options)
});
i can then use the click event like this:
src('...')
.pipe(notify({
"title": "Open Github",
"subtitle": "Project web site",
"message": "Click to open project site",
"sound": "Frog", // case sensitive
"onLast": true,
"wait": true
}))
.on('click', function(notifierObject, options) {
console.log(notifierObject);
console.log('----')
console.log(options)
});
I'm not sure if this is the correct way to do this, and it would be nice to have access to this amazing feature in gulp-notify.
Thanks in advance
Dennis
Hi, thanks for the issue! Sorry for the late response. Your idea is great and definitely something that would be cool to have. I'm somewhat uncertain whether or not this is as simple as it looks, because you can easily get a lot of listeners and exhaust your maxListener
limit.
I'm looking into this right now, I'll be back with more answers soon.
There is an issue with Notification Center where if I have N notification commands active and activate the notification, N events will be emitted. I need to look more into this and how to just emit on the one that is actually clicked.
I've added this now in commit 387c506. Caveat: It can only be triggered on the last notification for notification center (and this makes sense, really). I'd love for you to test it out.
Hey mikael,
your solution works lika a charm for us. It would be nice if it could be published to npm as soon as possible :)
➜ gulp-notify git:(master) npm publish
+ gulp-notify@2.1.0
@dennism It'd be cool to see how you implemented it, and it would be wonderful if there was some kind of plugin/function-decorator that you could export for this! I think "click-to-open" would be very nice to have for a lot of people!