简体   繁体   English

如何在 Windows 10 中发送通知(Electron 最佳实践)?

[英]How to send notifications in Windows 10 (Electron best practise)?

我曾尝试使用 HTML5 Notificaiton API,但它在 Windows 10 上不起作用。还有其他选择吗?

Electron natively supports balloon notification. Electron 本身支持气球通知。 To show balloon notification, add a tray first and use tray.displayBalloon(options) to create a balloon notification.要显示气球通知,请先添加托盘并使用托盘tray.displayBalloon(options)创建气球通知。 Refer API for tray in electron请参阅电子托盘的 API

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

const iconPath = path.join(__dirname, 'icon.png');
let tray;
app.on('ready', function(){
  tray = new Tray(iconPath);
  var contextMenu = Menu.buildFromTemplate([    
    {
      label: 'Notify',
      click: function() {
        tray.displayBalloon({
          title:'round',
          content:'world'
        })
      }
    }
  ]);
  tray.setToolTip('This is my application.');
  tray.setContextMenu(contextMenu);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM