我只是使用节点通知器包发送通知。另外,当我单击通知时,它必须转到一个链接。但我听不到点击事件。包提供的事件不起任何作用。这是我的密码:
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");
});这是我的通知:

我可以用任何其他的包裹。我只想听一下点击事件。
@ answer 120242的答案有效,但在通知消失后单击不起作用。有办法吗?我添加了一个gif。
发布于 2020-06-06 19:03:35
操作中心需要在本机代码中单独实现,而节点通知程序没有这些实现。您可以尝试节点-力量:npm i node-powertoast
const toast = require('powertoast');
toast({
message: "Google It",
onClick: "https://www.google.com"
}).catch(err => console.error(err));还支持回调函数onActivate。有关详细信息,请查看链接中的文档。
如何修复节点通知程序单击事件:
https://github.com/mikaelbr/node-notifier/issues/291#issuecomment-555741924
单击“不开火”会影响许多人,从第5版开始。
由于使用名称的更改,操作不一致。
您可以回滚到5.4.3,或者在线程中使用回调的建议。
npm uninstall node-notifier
npm i node-notifier@5或者:
notifier.notify({
... options
}, (err, action, metadata) => { if(action==='activate') { open('https://stackoverflow.com') })如果您自信并且更愿意修复库本身,另一种可能是: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
修补那些帐户‘激活’和发出‘点击’(在主分支的“映射器”功能不再存在)。
https://stackoverflow.com/questions/62193525
复制相似问题