Commit 049680a9 by Sebastián Katzer

Register trigger handler for each scheduled notification on launch

parent 54e8202b
...@@ -32,14 +32,12 @@ exports.core = { ...@@ -32,14 +32,12 @@ exports.core = {
*/ */
deviceready: function () { deviceready: function () {
var plugin = cordova.plugins.notification.local, var plugin = cordova.plugins.notification.local,
args; events = this.eventQueue;
this.isReady = true; this.isReady = true;
for (var i = 0; i < this.eventQueue.length; i++) { for (var i = 0; i < events.length; i++) {
args = this.eventQueue[i]; plugin.fireEvent.apply(plugin, events[i]);
plugin.fireEvent.apply(plugin, args);
} }
this.eventQueue = []; this.eventQueue = [];
...@@ -370,7 +368,7 @@ exports.core = { ...@@ -370,7 +368,7 @@ exports.core = {
var toasts = this.getScheduledToasts(), var toasts = this.getScheduledToasts(),
notifications = []; notifications = [];
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
...@@ -397,7 +395,7 @@ exports.core = { ...@@ -397,7 +395,7 @@ exports.core = {
* List of local notification IDs * List of local notification IDs
*/ */
getScheduled: function (ids) { getScheduled: function (ids) {
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
...@@ -412,7 +410,7 @@ exports.core = { ...@@ -412,7 +410,7 @@ exports.core = {
* List of local notification IDs * List of local notification IDs
*/ */
getTriggered: function (ids) { getTriggered: function (ids) {
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
under the License. under the License.
*/ */
var channel = require('cordova/channel');
exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core; exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core;
...@@ -289,6 +292,20 @@ exports.callOnTrigger = function (notification, callback) { ...@@ -289,6 +292,20 @@ exports.callOnTrigger = function (notification, callback) {
}; };
/** /**
* Sets trigger event for all scheduled local notification.
*
* @param {Function} callback
* Callback function
*/
exports.callOnTriggerForScheduled = function (callback) {
var notifications = this.getScheduled();
for (var i = 0; i < notifications.length; i++) {
this.callOnTrigger(notifications[i], callback);
}
};
/**
* The application state - background or foreground. * The application state - background or foreground.
* *
* @return String * @return String
...@@ -328,6 +345,27 @@ exports.fireEvent = function (event, notification) { ...@@ -328,6 +345,27 @@ exports.fireEvent = function (event, notification) {
* LIFE CYCLE * * LIFE CYCLE *
**************/ **************/
// Called before 'deviceready' event
channel.onCordovaReady.subscribe(function () {
// Register trigger handler for each scheduled notification
exports.callOnTriggerForScheduled(function (notification) {
this.updateBadge(notification.badge);
this.fireEvent('trigger', notification);
});
});
// Handle onclick event
WinJS.Application.addEventListener('activated', function (args) {
var id = args.detail.arguments,
notification = exports.getAll([id])[0];
if (!notification)
return;
exports.clearLocalNotification(id);
exports.fireEvent('click', notification);
}, false);
// App is running in background // App is running in background
document.addEventListener('pause', function () { document.addEventListener('pause', function () {
exports.isInBackground = true; exports.isInBackground = true;
...@@ -342,15 +380,3 @@ document.addEventListener('resume', function () { ...@@ -342,15 +380,3 @@ document.addEventListener('resume', function () {
document.addEventListener('deviceready', function () { document.addEventListener('deviceready', function () {
exports.isInBackground = false; exports.isInBackground = false;
}, false); }, false);
// Handle onclick event
WinJS.Application.addEventListener('activated', function (args) {
var id = args.detail.arguments,
notification = exports.getAll([id])[0];
if (!notification)
return;
exports.clearLocalNotification(id);
exports.fireEvent('click', notification);
}, false);
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