Skip to content

Instantly share code, notes, and snippets.

@tzapu tzapu/index.html
Created Dec 8, 2016

Embed
What would you like to do?
meteore-desktop-system-notifications
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Background</title>
</head>
   <body>
<script>
require('./renderer.js')
</script>
   </body>
</html>
import moduleJson from './module.json';
const { app, BrowserWindow, ipcMain } = require('electron');
import path from 'path';
/**
* Example module.
*
* @param {Object} log - Winston logger instance
* @param {Object} skeletonApp - reference to the skeleton app instance
* @param {Object} appSettings - settings.json contents
* @param {Object} eventsBus - event emitter for listening or emitting events
* shared across skeleton app and every module/plugin
* @param {Object} modules - references to all loaded modules
* @param {Object} settings - module settings
* @param {Object} Module - reference to the Module class
* @constructor
*/
export default class DesktopNotifier {
constructor({ log, skeletonApp, appSettings, eventsBus, modules, settings, Module }) {
this.module = new Module('desktopNotifier');
this.log = log;
this.eventsBus = eventsBus;
this.win = null;
this.eventsBus.on('desktopLoaded', () => {
this.init();
});
this.eventsBus.on('windowCreated', (window) => {
if (this.win === null) {
console.log('win2 created');
this.win = new BrowserWindow({
parent: window,
width: 100,
height: 100,
frame: false,
show: false,
});
//this.win = new BrowserWindow({ width: 800, height: 600})
this.win.loadURL(`file://${__dirname}/index.html`);
}
});
}
init() {
// Do some initialization if necessary.
this.registerApi();
// Lets inform that the module has finished loading.
this.eventsBus.emit(`${moduleJson.name}.loaded`);
}
registerApi() {
ipcMain.on('notificationClicked', (event, data) => {
this.module.send('notificationClicked', data);
});
this.module.on('notify', (event, { title, text, silent = true, icon = '', data }) => {
if(this.win) {
this.win.webContents.send('notify', title, text, silent, icon, data);
}
});
}
}
{
"name": "meteor-desktop-node-notifier",
"dependencies": {
},
"extract": []
}
var electron = require('electron');
electron.ipcRenderer.on('notify', (event, title, text, silent, icon, data) => {
let notification = new Notification(title, {
body: text,
silent,
icon,
});
notification.onclick = () => {
electron.ipcRenderer.send('notificationClicked', data);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.