Commit 396829d8 by Sebastián Katzer

Queue events if device not yet ready and save launch details on windows

parent 55875628
......@@ -26,9 +26,9 @@
@interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate>
// Set launchDetails object
- (void) launchDetails:(CDVInvokedUrlCommand*)command;
- (void) launch:(CDVInvokedUrlCommand*)command;
// Execute all queued events
- (void) deviceready:(CDVInvokedUrlCommand*)command;
- (void) ready:(CDVInvokedUrlCommand*)command;
// Check permission to show notifications
- (void) check:(CDVInvokedUrlCommand*)command;
......
......@@ -47,13 +47,12 @@
*
* @return [ Void ]
*/
- (void) launchDetails:(CDVInvokedUrlCommand*)command
- (void) launch:(CDVInvokedUrlCommand*)command
{
if (!_launchDetails)
return;
NSString* js;
js = [NSString stringWithFormat:
@"cordova.plugins.notification.local.launchDetails = {id:%@, action:'%@'}",
_launchDetails[0], _launchDetails[1]];
......@@ -68,7 +67,7 @@
*
* @return [ Void ]
*/
- (void) deviceready:(CDVInvokedUrlCommand*)command
- (void) ready:(CDVInvokedUrlCommand*)command
{
deviceready = YES;
......
......@@ -22,7 +22,41 @@
var LocalNotification = LocalNotificationProxy.LocalNotification,
ActivationKind = Windows.ApplicationModel.Activation.ActivationKind;
var impl = new LocalNotificationProxy.LocalNotificationProxy();
var impl = new LocalNotificationProxy.LocalNotificationProxy(),
queue = [],
ready = false;
/**
* Set launchDetails object.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
* @param [ Array ] args Interface arguments
*
* @return [ Void ]
*/
exports.launch = function (success, error, args) {
var plugin = cordova.plugins.notification.local;
if (args.length === 0 || plugin.launchDetails) return;
plugin.launchDetails = { id: args[0], action: args[1] };
};
/**
* To execute all queued events.
*
* @return [ Void ]
*/
exports.ready = function () {
ready = true;
for (var i = 0; i < queue.length; i++) {
exports.fireEvent.apply(exports, queue[i]);
}
queue = [];
};
/**
* Check permission to show notifications.
......@@ -301,6 +335,10 @@ exports.clicked = function (xml, input) {
meta.text = input.first().current.value;
}
if (!ready) {
exports.launch(null, null, [toast.id, event]);
}
exports.fireEvent(event, toast, meta);
};
......@@ -317,6 +355,11 @@ exports.fireEvent = function (event, toast, data) {
var meta = Object.assign({ event: event }, data),
plugin = cordova.plugins.notification.local.core;
if (!ready) {
queue.push(arguments);
return;
}
if (toast) {
plugin.fireEvent(event, exports.clone(toast), meta);
} else {
......
......@@ -362,13 +362,13 @@ exports.exec = function (action, args, callback, scope) {
channel.deviceready.subscribe(function () {
// Device is ready now, the listeners are registered
// and all queued events can be executed.
exports.exec('deviceready');
exports.exec('ready');
});
// Called before 'deviceready' event
channel.onCordovaReady.subscribe(function () {
// Set launchDetails object
exports.exec('launchDetails');
exports.exec('launch');
// Device plugin is ready now
channel.onCordovaInfoReady.subscribe(function () {
// Merge platform specifics into defaults
......
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