You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/02/23 18:53:18 UTC
[1/35] git commit: most of the way there for ios JS working
Updated Branches:
refs/heads/ios b43cbc054 -> cadf9dfac (forced update)
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/86a3e3ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/86a3e3ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/86a3e3ca
Branch: refs/heads/ios
Commit: 86a3e3ca3f7370d9b63fc7e982dadaa930560929
Parents: 6c7aeeb
Author: Fil Maj <fi...@nitobi.com>
Authored: Wed Feb 15 12:00:57 2012 -0800
Committer: Fil Maj <fi...@nitobi.com>
Committed: Thu Feb 23 09:52:59 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/86a3e3ca/lib/cordova.js
----------------------------------------------------------------------
diff --git a/lib/cordova.js b/lib/cordova.js
index 2586d5a..524f8f3 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/86a3e3ca/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/86a3e3ca/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/86a3e3ca/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/86a3e3ca/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