Home

Awesome

Electron Notifications

A node module for sending notifications in electron applications.

screenshot

Quick Usage

const notifier = require('electron-notifications')

// Just title
notifier.notify('Calendar')

// Full Options
notifier.notify('Calendar', {
  message: 'Event begins in 10 minutes',
  icon: 'http://cl.ly/J49B/3951818241085781941.png',
  buttons: ['Dismiss', 'Snooze'],
})

Installation

npm install --save electron-notifications

Playbook

If you'd like to see this in action you can run the playbook and try out live examples and edit the code in place.

git clone git@github.com:blainesch/electron-notifications.git
npm run playbook

Introduction

When you create a new notification, your notification is queued, since we only display one at a time. Each notification is a BrowserWindow instance, so it's completely cross platform.

Options

All options are optional.

Events

In addition to the events provided by electron you also have access to the following 3 additional events.

Clicked

When the notification was clicked, but not dragged. This usually does the default action, or closes the notification.

const notification = notifier.notify('Calendar')

notification.on('clicked', () => {
  notification.close()
})

Swiped Right

When the notification has been swiped to the right. This usually indicates that the user wants to dismiss the notification.

const notification = notifier.notify('Calendar')

notification.on('swipedRight', () => {
  notification.close()
})

Button Clicked

When any one of the buttons are clicked, it'll trigger a buttonClicked event, and pass the text, button index and options to the handler.

const notification = notifier.notify('Calendar', {
  buttons: ['Dismiss', 'Snooze'],
  url: "http://google.com"
})

notification.on('buttonClicked', (text, buttonIndex, options) => {
  if (text === 'Snooze') {
    // Snooze!
  } else if(buttonIndex === 1) {
    //open options.url
  }
  notification.close()
})