update notify interface (#45)

This commit is contained in:
Lynn 2017-03-28 17:04:21 -07:00 committed by GitHub
parent 1f149d62c2
commit 06e93cd9c3
5 changed files with 31 additions and 10 deletions

View File

@ -45,16 +45,22 @@
body: body,
image: imageUrl,
flash: shouldFlash,
color: color || 'white'
color: color || 'white',
data: {
hello: 'hello word'
}
});
notf.addEventListener('click', function() {
alert('notification clicked');
notf.addEventListener('click', function(event) {
event.target.data.then(function(value) {
alert('notification clicked: ' + value.hello);
})
});
notf.addEventListener('close', function() {
alert('notification closed');
});
});
var badgeCount = 0;

View File

@ -383,10 +383,9 @@ electron.ipcMain.on(apiProxyCmds.addEvent, function(event, args) {
/* eslint-enable no-console */
let obj = liveObjs[args.objId];
let callbackFunc = function(result) {
let callbackFunc = function() {
event.sender.send(apiProxyCmds.eventCallback, {
callbackId: args.callbackId,
result: result
callbackId: args.callbackId
});
}
obj._callbacks[args.callbackId] = callbackFunc;

View File

@ -14,7 +14,7 @@ class Notify {
this._id = notify({
title: title,
text: options.body,
image: options.image,
image: options.image || options.icon,
flash: options.flash,
color: options.color,
onShowFunc: onShow.bind(this),
@ -22,6 +22,8 @@ class Notify {
onCloseFunc: onClose.bind(this)
});
this._data = options.data || null;
function onShow(arg) {
if (arg.id === this._id) {
this.emitter.emit('show');
@ -54,6 +56,10 @@ class Notify {
return 'granted';
}
get data() {
return this._data;
}
addEventListener(event, cb) {
if (event && typeof cb === 'function') {
this.emitter.on(event, cb);

View File

@ -20,9 +20,11 @@ class Notify {
* @param {String} title Title of notification
* @param {Object} options {
* body {string} main text to display in notifications
* image {string} url of image to show in notifications
* image {string} url of image to show in notification
* icon {string} url of image to show in notification
* flash {bool} true if notification should flash (default false)
* color {string} background color for notification
* data {object} arbitrary object to be stored with notification
* }
*/
constructor(title, options) {}
@ -38,6 +40,11 @@ class Notify {
*/
static get permission() {}
/**
* returns data object passed in via constructor options
*/
get data() {}
/**
* add event listeners for 'click' and 'close' events
*

View File

@ -110,9 +110,12 @@ function addEventHandler(target) {
let callbackFunc = function(arg) {
if (arg.callbackId === callbackId) {
callback(args.result);
callback({
target: this,
type: eventName
});
}
}
}.bind(this);
ipcRenderer.on(proxyCmds.eventCallback, callbackFunc);