0

在节点/电子应用程序中,使用节点通知器来显示通知,效果很好。然后,添加了“确定”和“取消”按钮,以及它们各自的回调函数。回调函数也按预期工作,直到用户错过任何通知和通知超时。通知超时后,它会移动到(如果是Windows 10)通知侧边栏,并显示通知的标题和消息,按钮也可见,但按钮不起作用,甚至console.log。

第二个问题是我无法找到将参数/值传递给回调函数的方法。下面是代码:

const notifier = require('node-notifier')

 notifier.notify({
    title: title,
    message: message,
    icon: path.join(__dirname, 'logo.jpg'),
    actions: ['Ok','Cancel'],
    wait: true,
     },function(err, response, metadata){
        // Response is response from notification
        // Metadata contains activationType, activationAt, deliveredAt
        console.log(err, response, metadata);
     });

// Notifier Default events
 notifier.on('click', function(notifierObject, options, event){
    // Triggers if `wait: true` and user clicks notification
    console.log('"Clicked" on notification' , notifierObject, options, event);
 });

// Notifier Button actions
notifier.on('ok', function(notifierObject, options, event){     
    console.log('"OK" pressed', notifierObject, options, event);
});

notifier.on('cancel', function(notifierObject, options, event){
    console.log('"Cancel" pressed', notifierObject, options, event);
});
4

0 回答 0