我有一个问题,experimental electron notification API不提交“点击”事件,或者我只是错误地使用了它,但是我想澄清这是在主进程而不是渲染器进程中运行的新通知系统:
我的代码:
notification = new Notification({title: "Message Received",body: "message body"}).show()
// The above works and a notification gets made
notification.on('click', (event, arg)=>{
console.log("clicked")
})
// The above gives an error about 'on' not being defined
尝试过的事情:
notification.once('click', (event, arg)=>{
console.log("clicked")
})
notification.onclick = () =>{
console.log("clicked")
}
最佳答案
您的代码中有一个小缺陷:现在,变量 notification
没有收到调用 new Notification()
的结果,而是收到了结果对 show()
的调用是未定义
(不返回任何内容)。
通过将代码行分成两个语句,可以很容易地解决这个问题:
notification = new Notification({title: "Message Received",body: "message body"})
notification.show()
notification.on('click', (event, arg)=>{
console.log("clicked")
})
关于javascript - Electron 通知 API 'click' 事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61189074/