Explorar o código

WP8 support for the new callback interface as good as possible

Sebastián Katzer %!s(int64=12) %!d(string=hai) anos
pai
achega
906f256f8d
Modificáronse 1 ficheiros con 23 adicións e 7 borrados
  1. 23 7
      src/wp8/LocalNotification.cs

+ 23 - 7
src/wp8/LocalNotification.cs

@@ -54,15 +54,10 @@ namespace Cordova.Extension.Commands
                 // Empty strings for the text values and URIs will result in the property being cleared.
                 FlipTileData TileData = CreateTileData(options);
 
-                // Update the Application Tile
                 AppTile.Update(TileData);
 
-                if (!string.IsNullOrEmpty(options.Foreground))
-                {
-                    string arguments = String.Format("{0}({1})", options.Foreground, options.ID);
-
-                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, arguments));
-                }
+                FireEvent("trigger", options.ID, options.JSON);
+                FireEvent("add", options.ID, options.JSON);
             }
 
             DispatchCommandResult();
@@ -73,7 +68,12 @@ namespace Cordova.Extension.Commands
         /// </summary>
         public void cancel(string jsonArgs)
         {
+            string[] args         = JsonHelper.Deserialize<string[]>(jsonArgs);
+            string notificationID = args[0];
+
             cancelAll(jsonArgs);
+
+            FireEvent("cancel", notificationID, "");
         }
 
         /// <summary>
@@ -139,5 +139,21 @@ namespace Cordova.Extension.Commands
 
             return tile;
         }
+
+        /// <summary>
+        /// Fires the given event.
+        /// </summary>
+        private void FireEvent (string Event, string Id, string JSON = "")
+        {
+            string state = "foreground";
+            string args  = String.Format("\'{0}\',\'{1}\',\'{2}\'", Id, state, JSON);
+            string js    = String.Format("window.plugin.notification.local.on{0}({1})", Event, args);
+
+            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, js);
+
+            pluginResult.KeepCallback = true;
+
+            DispatchCommandResult(pluginResult);
+        }
     }
 }