gpt4 book ai didi

node.js - Windows Action Center中未触发notifier.on click事件

转载 作者:行者123 更新时间:2023-12-03 12:22:48 27 4
gpt4 key购买 nike

我正在使用node-notifier包进行通知,但是有一个问题。 Windows Action Center中未触发notifier.on click事件

notifier.notify(
{
appId: "com.electron.demo", // Absolute path (doesn't work on balloons),
title: "Alert Message",
message: "Click to view",
icon: path.join(__dirname, 'msicon.png'),
wait: true,
timeout: false,
id: "demo app"
},
function(err, response) {
// Response is response from notification
if (err) {
reject(err);
} else {
resolve(response);
}
}
);

notifier.on("click", function(notifierObject, options, event) {

// Triggers if `wait: true` and user clicks notification
var request = new sql.Request();
let username = userName;
request.query("update alerts.dbo.groupmessages set isRead = 1\
where pk = '"+ recordset.recordset[i].pk + "'\
and userFK = (select pk from alerts.dbo.users where username = '"+ username + "')\
and groupFK = (select groupFK from alerts.dbo.users where username = '"+ username + "')", function (err, recordset) {
if (err) throw err
console.log(err, recordset, 'User shit');
});

function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 400,
height: 400,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
// and load the index.html of the app.
ejse.data('message', recordset.recordset[i].message);
win.loadFile('index.ejs')
}
createWindow();

});
});
});

仅Windows Action Center中不会触发notifier.on click事件。请让我知道原因和解决方案。谢谢。

最佳答案

Action Center需要使用 native 代码进行单独的实现,而 Node 通知程序则没有。
您可以改为尝试node-powertoast并使用onActivated回调:npm i node-powertoast

const toast = require('powertoast');

toast({
title: "Hello",
message: "world",
callback: {
timeout: 5000, //keep-a-live in ms
onActivated: ()=>{ console.log("activated") },
onDismissed: (reason)=>{ console.log(reason) }
})
.then(()=> console.log("Notified")
.catch(err => console.error(err));

至于原因:
您可以看到,对于其他项目来说,这是一项艰巨的任务,例如,以下项目似乎在Action Center的支持中陷入了困境两年了: https://github.com/mohabouje/WinToast/issues/35尝试实现该计划的人自己似乎已陷入困境,并且很难获得它实现正确。
这很难做到。

关于node.js - Windows Action Center中未触发notifier.on click事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61207372/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com