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 @@ ...@@ -26,9 +26,9 @@
@interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate> @interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate>
// Set launchDetails object // Set launchDetails object
- (void) launchDetails:(CDVInvokedUrlCommand*)command; - (void) launch:(CDVInvokedUrlCommand*)command;
// Execute all queued events // Execute all queued events
- (void) deviceready:(CDVInvokedUrlCommand*)command; - (void) ready:(CDVInvokedUrlCommand*)command;
// Check permission to show notifications // Check permission to show notifications
- (void) check:(CDVInvokedUrlCommand*)command; - (void) check:(CDVInvokedUrlCommand*)command;
......
...@@ -47,13 +47,12 @@ ...@@ -47,13 +47,12 @@
* *
* @return [ Void ] * @return [ Void ]
*/ */
- (void) launchDetails:(CDVInvokedUrlCommand*)command - (void) launch:(CDVInvokedUrlCommand*)command
{ {
if (!_launchDetails) if (!_launchDetails)
return; return;
NSString* js; NSString* js;
js = [NSString stringWithFormat: js = [NSString stringWithFormat:
@"cordova.plugins.notification.local.launchDetails = {id:%@, action:'%@'}", @"cordova.plugins.notification.local.launchDetails = {id:%@, action:'%@'}",
_launchDetails[0], _launchDetails[1]]; _launchDetails[0], _launchDetails[1]];
...@@ -68,7 +67,7 @@ ...@@ -68,7 +67,7 @@
* *
* @return [ Void ] * @return [ Void ]
*/ */
- (void) deviceready:(CDVInvokedUrlCommand*)command - (void) ready:(CDVInvokedUrlCommand*)command
{ {
deviceready = YES; deviceready = YES;
...@@ -119,18 +118,18 @@ ...@@ -119,18 +118,18 @@
for (NSDictionary* options in notifications) { for (NSDictionary* options in notifications) {
NSNumber* id = [options objectForKey:@"id"]; NSNumber* id = [options objectForKey:@"id"];
UNNotificationRequest* notification; UNNotificationRequest* notification;
notification = [_center getNotificationWithId:id]; notification = [_center getNotificationWithId:id];
if (!notification) if (!notification)
continue; continue;
[self updateNotification:[notification copy] [self updateNotification:[notification copy]
withOptions:options]; withOptions:options];
[self fireEvent:@"update" notification:notification]; [self fireEvent:@"update" notification:notification];
} }
[self execCallback:command]; [self execCallback:command];
}]; }];
} }
...@@ -240,7 +239,7 @@ ...@@ -240,7 +239,7 @@
default: default:
type = @"unknown"; type = @"unknown";
} }
CDVPluginResult* result; CDVPluginResult* result;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:type]; messageAsString:type];
...@@ -316,11 +315,11 @@ ...@@ -316,11 +315,11 @@
NSArray* notifications; NSArray* notifications;
notifications = [_center getNotificationOptionsById:ids]; notifications = [_center getNotificationOptionsById:ids];
CDVPluginResult* result; CDVPluginResult* result;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:[notifications firstObject]]; messageAsDictionary:[notifications firstObject]];
[self.commandDelegate sendPluginResult:result [self.commandDelegate sendPluginResult:result
callbackId:command.callbackId]; callbackId:command.callbackId];
}]; }];
...@@ -489,7 +488,7 @@ ...@@ -489,7 +488,7 @@
APPNotificationContent* APPNotificationContent*
newNotification = [[APPNotificationContent alloc] initWithOptions:options]; newNotification = [[APPNotificationContent alloc] initWithOptions:options];
[self scheduleNotification:newNotification]; [self scheduleNotification:newNotification];
} }
......
...@@ -22,7 +22,41 @@ ...@@ -22,7 +22,41 @@
var LocalNotification = LocalNotificationProxy.LocalNotification, var LocalNotification = LocalNotificationProxy.LocalNotification,
ActivationKind = Windows.ApplicationModel.Activation.ActivationKind; 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. * Check permission to show notifications.
...@@ -301,6 +335,10 @@ exports.clicked = function (xml, input) { ...@@ -301,6 +335,10 @@ exports.clicked = function (xml, input) {
meta.text = input.first().current.value; meta.text = input.first().current.value;
} }
if (!ready) {
exports.launch(null, null, [toast.id, event]);
}
exports.fireEvent(event, toast, meta); exports.fireEvent(event, toast, meta);
}; };
...@@ -317,6 +355,11 @@ exports.fireEvent = function (event, toast, data) { ...@@ -317,6 +355,11 @@ exports.fireEvent = function (event, toast, data) {
var meta = Object.assign({ event: event }, data), var meta = Object.assign({ event: event }, data),
plugin = cordova.plugins.notification.local.core; plugin = cordova.plugins.notification.local.core;
if (!ready) {
queue.push(arguments);
return;
}
if (toast) { if (toast) {
plugin.fireEvent(event, exports.clone(toast), meta); plugin.fireEvent(event, exports.clone(toast), meta);
} else { } else {
......
...@@ -362,13 +362,13 @@ exports.exec = function (action, args, callback, scope) { ...@@ -362,13 +362,13 @@ exports.exec = function (action, args, callback, scope) {
channel.deviceready.subscribe(function () { channel.deviceready.subscribe(function () {
// Device is ready now, the listeners are registered // Device is ready now, the listeners are registered
// and all queued events can be executed. // and all queued events can be executed.
exports.exec('deviceready'); exports.exec('ready');
}); });
// Called before 'deviceready' event // Called before 'deviceready' event
channel.onCordovaReady.subscribe(function () { channel.onCordovaReady.subscribe(function () {
// Set launchDetails object // Set launchDetails object
exports.exec('launchDetails'); exports.exec('launch');
// Device plugin is ready now // Device plugin is ready now
channel.onCordovaInfoReady.subscribe(function () { channel.onCordovaInfoReady.subscribe(function () {
// Merge platform specifics into defaults // 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