我有 Windows 10 和 Electron 中的应用程序:28.2.3。这是我的显示系统通知的代码:
export const showSystemNotification = (
notificationData: NotificationCustomOptions,
) => {
const icon = nativeImage.createFromPath(join(PUBLIC, 'icon.ico'))
const notification = new Notification({
...notificationData,
icon,
})
notification.on('click', async () => {
console.log('click!')
if (notificationData.url) await openURL(notificationData.url)
})
notification.show()
}
当通知第一次出现时,点击它有预期的效果,但是当通知转到“操作中心”时(我不知道通知消失的地方的名称是什么),然后点击通知有没有效果。
我该如何修复它?
我找到了决心。这个答案帮助了我。 这行解决了我的问题:
<toast launch="my_app_name://" activationType="protocol">
这是我在Windows系统中显示通知的代码:
const iconPath = join(PUBLIC, "icon.ico");
const notification = new Notification({
toastXml: `<toast launch="my_app_name://" activationType="protocol">
<visual>
<binding template="ToastGeneric">
<text id="1">${notificationData.title}</text>
<text id="2">${notificationData.body}</text>
<image src="${iconPath}" alt="Logo" placement="appLogoOverride" />
</binding>
</visual>
</toast>`,
});
notification.on("click", () => {
console.log('Click!')
});
notification.show();
这里是有关 Toast schema 的更多信息。