Created
December 8, 2016 12:24
-
-
Save tzapu/14f92eb419c212768aa525112448261d to your computer and use it in GitHub Desktop.
meteore-desktop-system-notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Background</title> | |
</head> | |
<body> | |
<script> | |
require('./renderer.js') | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "meteor-desktop-node-notifier", | |
"dependencies": { | |
}, | |
"extract": [] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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