You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/03/14 23:40:38 UTC

[1/4] git commit: Removed dependency on CordovaCommandResult, removed obsolete 'cast' param from callbacks

Removed dependency on CordovaCommandResult, removed obsolete 'cast' param from callbacks


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/57bc645b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/57bc645b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/57bc645b

Branch: refs/heads/master
Commit: 57bc645ba7457c3c68a5b31663bb9f63e2d95721
Parents: fa0465a
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Mar 11 17:40:10 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon Mar 11 17:40:10 2013 -0700

----------------------------------------------------------------------
 .../standalone/cordovalib/CordovaView.xaml.cs      |    7 ++-
 templates/standalone/cordovalib/NativeExecution.cs |   23 +++++++----
 templates/standalone/cordovalib/PluginResult.cs    |   30 +--------------
 3 files changed, 19 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/57bc645b/templates/standalone/cordovalib/CordovaView.xaml.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/CordovaView.xaml.cs b/templates/standalone/cordovalib/CordovaView.xaml.cs
index ec88576..7b92f65 100644
--- a/templates/standalone/cordovalib/CordovaView.xaml.cs
+++ b/templates/standalone/cordovalib/CordovaView.xaml.cs
@@ -179,7 +179,7 @@ namespace WPCordovaClassLib
 
             try
             {
-                CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "pause" });
+                CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" });
             }
             catch (Exception)
             {
@@ -197,7 +197,7 @@ namespace WPCordovaClassLib
             Debug.WriteLine("INFO: AppActivated");
             try
             {
-                CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "resume" });
+                CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('resume');" });
             }
             catch (Exception)
             {
@@ -257,6 +257,7 @@ namespace WPCordovaClassLib
                  * 11/08/12 Ruslan Kokorev
                  * Copying files to isolated storage is no more required in WP8. WebBrowser control now works with files located in XAP.
                 */
+
                 //StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("CordovaSourceDictionary.xml", UriKind.Relative));
 
                 //if (streamInfo != null)
@@ -347,7 +348,7 @@ namespace WPCordovaClassLib
             {
                 try
                 {
-                    CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" });
+                    CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('backbutton');" });
                     e.Cancel = true;
                 }
                 catch (Exception ex)

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/57bc645b/templates/standalone/cordovalib/NativeExecution.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/NativeExecution.cs b/templates/standalone/cordovalib/NativeExecution.cs
index a0865ab..28dc528 100644
--- a/templates/standalone/cordovalib/NativeExecution.cs
+++ b/templates/standalone/cordovalib/NativeExecution.cs
@@ -129,7 +129,7 @@ namespace WPCordovaClassLib.Cordova
                     }
                 };
 
-                if ((bc is File) || (bc is Accelerometer))
+                if (true || (bc is File) || (bc is Accelerometer))
                 {
                     // Due to some issues with the IsolatedStorage in current version of WP8 SDK we have to run all File Api commands synchronously.
                     // TODO: test this in WP8 RTM
@@ -176,21 +176,27 @@ namespace WPCordovaClassLib.Cordova
 
             #endregion
 
-            string status = ((int)result.Result).ToString();
             string jsonResult = result.ToJSONString();
 
-            ScriptCallback scriptCallback = null;
+            string callback;
+            string args = string.Format("('{0}',{1});", callbackId, jsonResult);
 
-            if (String.IsNullOrEmpty(result.Cast))
+            if (result.Result == PluginResult.Status.NO_RESULT ||
+               result.Result == PluginResult.Status.OK)
             {
-                scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult });
+                callback = @"(function(callbackId,args) {
+                try { args.message = JSON.parse(args.message); } catch (ex) { }
+                cordova.callbackSuccess(callbackId,args);
+                })" + args;
             }
             else
             {
-                scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult, result.Cast });
+                callback = @"(function(callbackId,args) {
+                try { args.message = JSON.parse(args.message); } catch (ex) { }
+                cordova.callbackError(callbackId,args);
+                })" + args;
             }
-
-            this.InvokeScriptCallback(scriptCallback);
+            this.InvokeScriptCallback(new ScriptCallback("eval", new string[] { callback }));
 
         }
 
@@ -213,7 +219,6 @@ namespace WPCordovaClassLib.Cordova
             //Debug.WriteLine("INFO:: About to invoke ::" + script.ScriptName + " with args ::" + script.Args[0]);
             this.webBrowser.Dispatcher.BeginInvoke((ThreadStart)delegate()
             {
-
                 try
                 {
                     //Debug.WriteLine("INFO:: InvokingScript::" + script.ScriptName + " with args ::" + script.Args[0]);

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/57bc645b/templates/standalone/cordovalib/PluginResult.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/PluginResult.cs b/templates/standalone/cordovalib/PluginResult.cs
index b887bb8..e6d0c56 100644
--- a/templates/standalone/cordovalib/PluginResult.cs
+++ b/templates/standalone/cordovalib/PluginResult.cs
@@ -68,8 +68,6 @@ namespace WPCordovaClassLib.Cordova
 
         public Status Result { get; private set; }
         public string Message { get; set; }
-        public String Cast { get; private set; }
-
         public bool KeepCallback { get; set; }
 
         /// <summary>
@@ -103,21 +101,6 @@ namespace WPCordovaClassLib.Cordova
             this.Message = JSON.JsonHelper.Serialize(message);
         }
 
-        /// <summary>
-        /// Creates new instance of the PluginResult class.
-        /// </summary>
-        /// <param name="status">Execution result</param>
-        /// <param name="message">The message</param>
-        /// <param name="cast">The cast parameter</param>
-        /// 
-        [Obsolete("Don't use Cast!!", false)]
-        public PluginResult(Status status, object message, string cast)
-        {
-            this.Result = status;
-            this.Message = JSON.JsonHelper.Serialize(message);
-            this.Cast = cast;
-        }
-
         public string ToJSONString()
         {
             string res = String.Format("\"status\":{0},\"message\":{1},\"keepCallback\":{2}",
@@ -132,21 +115,10 @@ namespace WPCordovaClassLib.Cordova
 
         public string ToCallbackString(string callbackId, string successCallback, string errorCallback)
         {
-            //return String.Format("{0}('{1}',{2});", successCallback, callbackId, this.ToJSONString());
-
             if (this.IsSuccess)
             {
                 StringBuilder buf = new StringBuilder("");
-                if (this.Cast != null)
-                {
-                    Debug.WriteLine(callbackId + "this.Cast = " + this.Cast);
-                    buf.Append("var temp = " + this.Cast + "(" + this.ToJSONString() + ");\n");
-                    buf.Append(String.Format("{0}('{1}',temp);", successCallback, callbackId));
-                }
-                else
-                {
-                    buf.Append(String.Format("{0}('{1}',{2});", successCallback, callbackId, this.ToJSONString()));
-                }
+                buf.Append(String.Format("{0}('{1}',{2});", successCallback, callbackId, this.ToJSONString()));
                 return buf.ToString();
             }
             else