簡體   English   中英

如何在 Windows 10 中發送通知(Electron 最佳實踐)?

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

我曾嘗試使用 HTML5 Notificaiton API,但它在 Windows 10 上不起作用。還有其他選擇嗎?

Electron 本身支持氣球通知。 要顯示氣球通知,請先添加托盤並使用托盤tray.displayBalloon(options)創建氣球通知。 請參閱電子托盤的 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