electron-native-notification

Notification API polyfill in electron main process.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
electron-native-notification
601.2.16 years ago7 years agoMinified + gzip package size for electron-native-notification in KB

Readme

electron-native-notification
GitHub release JavaScript Style Guide Easily display native desktop applications from your Electron main process. Because Notifications use the HTML 5 Notification API, this usually only works from renderer processes. However, it's a polyfill from https://developer.mozilla.org/en-US/docs/Web/API/notification.

Usage

Reference https://developer.mozilla.org/en-US/docs/Web/API/notification.

main.js:

```javascript const { app } = require('electron'), Notification = require('electron-native-notification'); app.on('ready', () => { const opt = { body: 'See? Really easy to use!' }; const notification = new Notification('I am a notification!', opt); notification.on('show', () => {
console.log('I\'m coming~');
}); notification.onclick = () => {
console.log('On no! You touch me. It\'s hurt!!');
}; notification.addEventListener('close', () => {
console.log('I\'ll be back!!');
}); notification.addListener('error', (err) => {
console.error(err);
}); console.log('What does the notification say? ' + notification.body); setTimeout(() => notification.close(), 2000); }); ```

Polyfill what?

Constructor

- Notification(title, options)

Properties

- body (Read-only) - data (Read-only) - dir (Read-only) - icon (Read-only) - lang (Read-only) - onclick - onerror - tag (Read-only) - timestamp (Read-only) - title (Read-only)

Methods

- close() - on() (Event register for node) - addListener() (Event register for node) - addEventListener() (Event register for javascript)

Events

- error - click - close - show

License

MIT