incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [10/10] git commit: most of the way there for ios JS working
Date Sat, 03 Mar 2012 19:33:08 GMT
most of the way there for ios JS working


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

Branch: refs/heads/master
Commit: a26bd93ef43b2551db22f48319e03e8b5148d16f
Parents: 616d375
Author: Fil Maj <filip.maj@nitobi.com>
Authored: Wed Feb 15 12:00:57 2012 -0800
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Fri Mar 2 16:03:20 2012 -0800

----------------------------------------------------------------------
 lib/cordova.js               |    9 +++++++++
 lib/exec/ios.js              |   31 ++++++-------------------------
 lib/platform/ios.js          |    4 +++-
 lib/plugin/ios/device.js     |   15 +++++++++++++++
 lib/plugin/ios/nativecomm.js |   15 +++++++++++++++
 5 files changed, 48 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a26bd93e/lib/cordova.js
----------------------------------------------------------------------
diff --git a/lib/cordova.js b/lib/cordova.js
index 1059cbb..4b003e0 100644
--- a/lib/cordova.js
+++ b/lib/cordova.js
@@ -114,6 +114,15 @@ var cordova = {
     shuttingDown:false,
     UsePolling:false,
     // END TODO
+
+    // TODO: iOS only
+    // This queue holds the currently executing command and all pending
+    // commands executed with cordova.exec().
+    commandQueue:[],
+    // Indicates if we're currently in the middle of flushing the command
+    // queue on the native side.
+    commandQueueFlushing:false,
+    // END TODO
     /**
      * Plugin callback mechanism.
      */

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a26bd93e/lib/exec/ios.js
----------------------------------------------------------------------
diff --git a/lib/exec/ios.js b/lib/exec/ios.js
index 66ef5c5..5c972ca 100644
--- a/lib/exec/ios.js
+++ b/lib/exec/ios.js
@@ -1,17 +1,11 @@
-// This queue holds the currently executing command and all pending
-// commands executed with cordova.exec().
-var commandQueue = [],
-    // Indicates if we're currently in the middle of flushing the command
-    // queue on the native side.
-    commandQueueFlushing = false,
     /**
      * Creates a gap bridge iframe used to notify the native code about queued
      * commands.
      *
      * @private
      */
+var cordova = require('cordova'),
     gapBridge,
-    // TODO: why do we have to recreate the iframe sometimes?
     createGapBridge = function() {
         gapBridge = document.createElement("iframe");
         gapBridge.setAttribute("style", "display:none;");
@@ -19,13 +13,11 @@ var commandQueue = [],
         gapBridge.setAttribute("width","0px");
         gapBridge.setAttribute("frameborder","0");
         document.documentElement.appendChild(gapBridge);
-    };
-
+    },
+    channel = require('cordova/channel');
 
 module.exports = function() { 
-    // TODO: DeviceInfo, where does this come from? what is execution
-    // order during app load, and how does this fit in.
-    if (!DeviceInfo.uuid) {
+    if (!channel.onCordovaInfoReady.fired) {
         alert("ERROR: Attempting to call cordova.exec()" +
               " before 'deviceready'. Ignoring.");
         return;
@@ -86,13 +78,13 @@ module.exports = function() {
     // Stringify and queue the command. We stringify to command now to
     // effectively clone the command arguments in case they are mutated before
     // the command is executed.
-    commandQueue.push(JSON.stringify(command));
+    cordova.commandQueue.push(JSON.stringify(command));
 
     // If the queue length is 1, then that means it was empty before we queued
     // the given command, so let the native side know that we have some
     // commands to execute, unless the queue is currently being flushed, in
     // which case the command will be picked up without notification.
-    if (commandQueue.length == 1 && !commandQueueFlushing) {
+    if (cordova.commandQueue.length == 1 && !cordova.commandQueueFlushing) {
         if (!gapBridge) {
             createGapBridge();
         }
@@ -100,14 +92,3 @@ module.exports = function() {
         gapBridge.src = "gap://ready";
     }
 };
-
-// TODO: how does this get called from native? 
-/**
- * Called by native code to retrieve all queued commands and clear the queue.
- */
-cordova.getAndClearQueuedCommands = function() {
-  json = JSON.stringify(commandQueue);
-  commandQueue = [];
-  return json;
-};
-

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a26bd93e/lib/platform/ios.js
----------------------------------------------------------------------
diff --git a/lib/platform/ios.js b/lib/platform/ios.js
index 261a5ad..9f310e0 100644
--- a/lib/platform/ios.js
+++ b/lib/platform/ios.js
@@ -1,6 +1,8 @@
 module.exports = {
     id: "ios",
-    initialize:function() {},
+    initialize:function() {
+
+    },
     objects: {
         navigator: {
             children: {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a26bd93e/lib/plugin/ios/device.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/device.js b/lib/plugin/ios/device.js
index 2951345..44d6921 100644
--- a/lib/plugin/ios/device.js
+++ b/lib/plugin/ios/device.js
@@ -3,6 +3,10 @@
  * phone, etc.
  * @constructor
  */
+var exec = require('cordova/exec'),
+    channel = require('cordova/channel');
+
+ // TODO: pluginize native ios device info so we can call with exec
 var Device = function() {
     this.platform = null;
     this.version  = null;
@@ -10,11 +14,22 @@ var Device = function() {
     this.phonegap = null;
     this.uuid     = null;
     try {
+      /*
         this.platform = DeviceInfo.platform;
         this.version  = DeviceInfo.version;
         this.name     = DeviceInfo.name;
         this.phonegap = DeviceInfo.gap;
         this.uuid     = DeviceInfo.uuid;
+        */
+        var me = this;
+        exec(function(deviceinfo) {
+          me.platform = deviceinfo.platform;
+          /* etc. etc. */
+
+          channel.onCordovaInfoReady.fire();
+        }, function() {
+        },
+        'DeviceInfo', 'getInfo', []);
     } catch(e) {
         // TODO: 
     }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a26bd93e/lib/plugin/ios/nativecomm.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/nativecomm.js b/lib/plugin/ios/nativecomm.js
new file mode 100644
index 0000000..dec76ea
--- /dev/null
+++ b/lib/plugin/ios/nativecomm.js
@@ -0,0 +1,15 @@
+var cordova = require('cordova');
+
+/**
+ * Called by native code to retrieve all queued commands and clear the queue.
+ */
+module.exports = function() {
+  var json = JSON.stringify(cordova.commandQueue);
+  cordova.commandQueue = [];
+  return json;
+};
+
+// TODO: make sure native uses:
+// require('cordova/plugin/ios/nativecomm')();
+// instead of:
+// getAndClearCommandQueue


Mime
View raw message