cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [01/31] git commit: Added console polyfill from native IBrowserDecorator
Date Fri, 13 Sep 2013 01:19:36 GMT
Updated Branches:
  refs/heads/master d62ca3a12 -> 9976c0258


Added console polyfill from native IBrowserDecorator


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

Branch: refs/heads/master
Commit: c179f562a9d602d266346d86b52341aea5f98871
Parents: 8f98831
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed Jul 10 00:18:42 2013 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed Jul 10 00:18:42 2013 -0700

----------------------------------------------------------------------
 wp7/framework/WPCordovaClassLib.csproj      |  3 ++
 wp7/template/cordovalib/ConsoleHelper.cs    | 37 ++++++++++++++++++++++++
 wp7/template/cordovalib/CordovaView.xaml.cs | 12 ++++----
 3 files changed, 46 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c179f562/wp7/framework/WPCordovaClassLib.csproj
----------------------------------------------------------------------
diff --git a/wp7/framework/WPCordovaClassLib.csproj b/wp7/framework/WPCordovaClassLib.csproj
index 4c6ba8c..cd1e004 100644
--- a/wp7/framework/WPCordovaClassLib.csproj
+++ b/wp7/framework/WPCordovaClassLib.csproj
@@ -167,6 +167,9 @@
     <Compile Include="..\template\cordovalib\ConfigHandler.cs">
       <Link>CordovaLib\ConfigHandler.cs</Link>
     </Compile>
+    <Compile Include="..\template\cordovalib\ConsoleHelper.cs">
+      <Link>CordovaLib\ConsoleHelper.cs</Link>
+    </Compile>
     <Compile Include="..\template\cordovalib\CordovaCommandCall.cs">
       <Link>CordovaLib\CordovaCommandCall.cs</Link>
     </Compile>

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c179f562/wp7/template/cordovalib/ConsoleHelper.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/ConsoleHelper.cs b/wp7/template/cordovalib/ConsoleHelper.cs
new file mode 100644
index 0000000..c7bc8df
--- /dev/null
+++ b/wp7/template/cordovalib/ConsoleHelper.cs
@@ -0,0 +1,37 @@
+´╗┐using Microsoft.Phone.Controls;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+
+namespace WPCordovaClassLib.CordovaLib
+{
+    class ConsoleHelper : IBrowserDecorator
+    {
+
+        public WebBrowser Browser { get; set; }
+
+        public void InjectScript() 
+        {
+            string script = @"(function(win) {
+        function exec(msg) { window.external.Notify('ConsoleLog/' + msg); }
+        var cons = win.console = win.console || {};
+        cons.log = exec;
+        cons.debug = cons.debug || cons.log;
+        cons.info = cons.info   || function(msg) { exec('INFO:' + msg ); };     
+        cons.warn = cons.warn   || function(msg) { exec('WARN:' + msg ); };
+        cons.error = cons.error || function(msg) { exec('ERROR:' + msg ); };
+    })(window);";
+
+           Browser.InvokeScript("execScript", new string[] { script });
+        }
+
+        public bool HandleCommand(string commandStr)
+        {
+            Debug.WriteLine(commandStr.Substring("ConsoleLog/".Length));
+            return true;
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c179f562/wp7/template/cordovalib/CordovaView.xaml.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/CordovaView.xaml.cs b/wp7/template/cordovalib/CordovaView.xaml.cs
index 61f673b..3830634 100644
--- a/wp7/template/cordovalib/CordovaView.xaml.cs
+++ b/wp7/template/cordovalib/CordovaView.xaml.cs
@@ -192,6 +192,10 @@ namespace WPCordovaClassLib
             storageHelper.Browser = CordovaBrowser;
             browserDecorators.Add("DOMStorage", storageHelper);
 
+            ConsoleHelper console = new ConsoleHelper();
+            console.Browser = CordovaBrowser;
+            browserDecorators.Add("ConsoleLog", console);
+
         }
 
 
@@ -243,10 +247,6 @@ namespace WPCordovaClassLib
             // prevents refreshing web control to initial state during pages transitions
             if (this.IsBrowserInitialized) return;
 
-
-
-            
-
             try
             {
 
@@ -397,11 +397,11 @@ namespace WPCordovaClassLib
 
         void GapBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs
e)
         {
-            string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();";
+            string nativeReady = "(function(){ window.setTimeout(function(){cordova.require('cordova/channel').onNativeReady.fire()},0)
})();";
 
             try
             {
-                CordovaBrowser.InvokeScript("eval", new string[] { nativeReady });
+                CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady });
             }
             catch (Exception ex)
             {


Mime
View raw message