gpt4 book ai didi

javascript - Electron : display basic notification in a Tray application

转载 作者:行者123 更新时间:2023-12-03 12:28:29 25 4
gpt4 key购买 nike

我正在制作纸盘应用程序,并且尝试显示一个基本通知:

我的main.js文件和package.json在下面:

我的app/main.js文件

 const path = require('path');
const {
app,
globalShortcut,
Tray,
Notification
} = require('electron');

app.on('ready', () => {
tray = new Tray(path.join(__dirname, 'icon-light.png'));

globalShortcut.register('CommandOrControl+Shift+N', () => {
console.log("Roger");
let myNotification = new Notification('Title', {
body: 'Rabbit'
})

myNotification.onclick = () => {
console.log('Notification clicked')
}
});
})

我的package.json文件
{
"name": "test_notification",
"version": "1.0.0",
"description": "",
"main": "app/main.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^5.0.1"
}
}

当我触发击键CommandOrControl + Shift + N时,它将显示console.log而不是通知。

你知道怎么做吗?

最佳答案

您错过了以下代码中的new

let myNotification = new Notification('Title', {
body: 'Rabbit'
})

引用: https://electronjs.org/docs/tutorial/notifications

关于javascript - Electron : display basic notification in a Tray application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56168608/

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