electron消息通知

electron消息通知有自带的模块,但是本文是使用node-notifier

1、安装node-notifier

npm install --save node-notifier

2、使用node-notifier

const notifier = window.require('node-notifier')
const openMessage = () => {
  //渲染进程想主进程发送消息
 notifier.notify({
    title: '我是标题',
    message: '我是提示语',
    icon: './static/log1.png',//项目的绝对地址
    sound: true,  // 提示是否有声音
    wait: true,   // 等待针对通知的用户操作或超时。与超时相同 = 5 秒
    open: 'https://www.jianshu.com/u/aabdb035b04c', // 点击消息框会跳转此地址
  }, function (err, response) {
    // Response is response from notification
  })
  notifier.on('click', function (notifierObject, options) {
    // 此方法是点击消息提示框的操作,例如打开窗口的操作,openWin就是主线程里打开窗口的方法
    ipcRenderer.send('openWin', true)
  })
  notifier.on('timeout', function (notifierObject, options) {
    console.log("Notification timed out!")
  })
}

具体配置参见:https://github.com/mikaelbr/node-notifier

提示.png

你可能感兴趣的:(electron消息通知)