Commit 831c96d3 by Sebastián Katzer

Copy sealed windows objects to JS objects

parent 04e5ef63
...@@ -166,7 +166,7 @@ exports.triggeredIds = function (success, error) { ...@@ -166,7 +166,7 @@ exports.triggeredIds = function (success, error) {
exports.notification = function (success, error, args) { exports.notification = function (success, error, args) {
var obj = impl.notification(args[0]); var obj = impl.notification(args[0]);
success(obj); success(exports.clone(obj));
}; };
/** /**
...@@ -181,7 +181,7 @@ exports.notification = function (success, error, args) { ...@@ -181,7 +181,7 @@ exports.notification = function (success, error, args) {
exports.notifications = function (success, error, args) { exports.notifications = function (success, error, args) {
var objs = impl.notifications(args) || []; var objs = impl.notifications(args) || [];
success(Array.from(objs)); success(exports.cloneAll(objs));
}; };
/** /**
...@@ -195,7 +195,7 @@ exports.notifications = function (success, error, args) { ...@@ -195,7 +195,7 @@ exports.notifications = function (success, error, args) {
exports.scheduledNotifications = function (success, error) { exports.scheduledNotifications = function (success, error) {
var objs = impl.scheduledNotifications() || []; var objs = impl.scheduledNotifications() || [];
success(Array.from(objs)); success(exports.cloneAll(objs));
}; };
/** /**
...@@ -209,7 +209,7 @@ exports.scheduledNotifications = function (success, error) { ...@@ -209,7 +209,7 @@ exports.scheduledNotifications = function (success, error) {
exports.triggeredNotifications = function (success, error) { exports.triggeredNotifications = function (success, error) {
var objs = impl.triggeredNotifications() || []; var objs = impl.triggeredNotifications() || [];
success(Array.from(objs)); success(exports.cloneAll(objs));
}; };
/** /**
...@@ -222,20 +222,75 @@ exports.triggeredNotifications = function (success, error) { ...@@ -222,20 +222,75 @@ exports.triggeredNotifications = function (success, error) {
exports.clicked = function (xml, input) { exports.clicked = function (xml, input) {
var toast = LocalNotification.Options.parse(xml), var toast = LocalNotification.Options.parse(xml),
event = toast.action || 'click', event = toast.action || 'click',
e = { event: event }; meta = Object.assign({}, input);
if (input && input.size > 0) { if (input && input.size > 0) {
var it = input.first(); meta.text = input.first().current.value;
}
exports.fireEvent(event, toast, meta);
};
e.text = it.current.value; /**
* Invoke listeners for the given event.
*
* @param [ String ] event The name of the event.
* @param [ Object ] toast Optional notification object.
* @param [ Object ] data Optional meta data about the event.
*
* @return [ Void ]
*/
exports.fireEvent = function (event, toast, data) {
var meta = Object.assign({ event: event }, data),
plugin = cordova.plugins.notification.local.core;
if (toast) {
plugin.fireEvent(event, exports.clone(toast), meta);
} else {
plugin.fireEvent(event, meta);
}
};
while (it.hasCurrent) { /**
e[it.current.key] = it.current.value; * Clone the objects and delete internal properties.
it.moveNext(); *
* @param [ Array<Object> ] objs The objects to clone for.
*
* @return [ Array<Object> ]
*/
exports.cloneAll = function (objs) {
var clones = [];
for (var i = 0; i < objs.length; i++) {
clones.push(exports.clone(objs[i]));
}
return clones;
};
/**
* Clone the object and delete internal properties.
*
* @param [ Object ] obj The object to clone for.
*
* @return [ Object ]
*/
exports.clone = function (obj) {
var ignore = ['action'],
clone = {};
for (var prop in obj) {
if (ignore.includes(prop) || typeof obj[prop] === 'function')
continue;
try {
clone[prop] = obj[prop];
} catch (e) {
clone[prop] = null;
} }
} }
cordova.plugins.notification.local.core.fireEvent(event, toast, e); return clone;
}; };
// Handle onclick event // Handle onclick event
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment