我正在制作托盘应用程序,我尝试显示基本通知:
我的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但不显示通知。
你知道怎么做吗?
相关分类