Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2FF2E9B5A for ; Thu, 23 Feb 2012 17:53:43 +0000 (UTC) Received: (qmail 2874 invoked by uid 500); 23 Feb 2012 17:53:43 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 2845 invoked by uid 500); 23 Feb 2012 17:53:43 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 2838 invoked by uid 99); 23 Feb 2012 17:53:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Feb 2012 17:53:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.114] (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Feb 2012 17:53:40 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BB3028127B7; Thu, 23 Feb 2012 17:53:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: filmaj@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/35] git commit: most of the way there for ios JS working Message-Id: <20120223175318.BB3028127B7@tyr.zones.apache.org> Date: Thu, 23 Feb 2012 17:53:18 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Wed Feb 15 12:00:57 2012 -0800 Committer: Fil Maj 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