【问题标题】:How to send notifications in Windows 10 (Electron best practise)?如何在 Windows 10 中发送通知(电子最佳实践)?
【发布时间】:2018-06-08 11:31:32
【问题描述】:

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

【问题讨论】:

标签: javascript html electron


【解决方案1】:

Electron 原生支持气球通知。要显示气球通知,请先添加一个托盘并使用tray.displayBalloon(options) 创建气球通知。 参考API for tray in electron

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);
});

【讨论】:

  • 你用过吗?
  • 这是经过编辑的答案,我已经尝试过并且有效。
  • 如果您觉得这个答案有用,请点击答案旁边的勾号,这样它也可以帮助其他人。
  • 运行应用程序时,您将看到一个托盘图标。您必须右键单击托盘图标并单击通知。
  • 我知道,当我点击通知时没有任何反应。
猜你喜欢
  • 2014-08-29
  • 2019-06-26
  • 2011-06-18
  • 2011-02-16
  • 2011-08-20
  • 2010-12-10
  • 1970-01-01
  • 1970-01-01
  • 2011-07-08
相关资源
最近更新 更多