Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s-a/electron-toaster
A simple desktop notification for electron apps
https://github.com/s-a/electron-toaster
Last synced: about 5 hours ago
JSON representation
A simple desktop notification for electron apps
- Host: GitHub
- URL: https://github.com/s-a/electron-toaster
- Owner: s-a
- License: other
- Created: 2015-08-05T18:32:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-29T21:20:52.000Z (over 4 years ago)
- Last Synced: 2024-11-14T09:20:57.107Z (3 days ago)
- Language: JavaScript
- Size: 174 KB
- Stars: 55
- Watchers: 9
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Installation
```bash
$ npm install electron-toaster;
```# Usage
```javascript
// In main process.
var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.var Toaster = require('electron-toaster');
var toaster = new Toaster();// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;app.on('window-all-closed', function() {
if (process.platform !== 'darwin'){
app.quit();
}
});app.on('ready', function() {
mainWindow = new BrowserWindow({});
toaster.init(mainWindow);mainWindow.on('devtools-opened', function() {
mainWindow.loadUrl('file://' + __dirname + '/index.html');
});mainWindow.on('closed', function() {
mainWindow = null;
});
});
``````javascript
// In renderer process (web page).var ipc = require("electron").ipcRenderer;
var msg = {
title : "Awesome!",
message : "Check this out!
Check this out!
Check this out!
Check this out!
Check this out!
Check this out!
",
detail : "PI is equal to 3! - 0.0
PI is equal to 3! - 0.0
PI is equal to 3! - 0.0
PI is equal to 3! - 0.0
",
width : 440,
// height : 160, window will be autosized
timeout : 6000,
focus: true // set focus back to main window
};
ipc.send('electron-toaster-message', msg);
```## User interaction
If you need to do some stuffs at the main process on toaster click or when toaster was closed by timeout.
```javascript
//in your main process. listen to the event 'electron-toaster-reply'. i.e
ipc.on('electron-toaster-reply', (event, isAuto) => {
console.log('Toaster just spoke to me', isAuto);
})
````isAuto` **parameter**:
`true` - if timeout was reached.
`false` - if user interacted with toaster onclick.![screenshot](/screenshot.png)