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/03/30 01:21:16 UTC

[3/3] git commit: changing plugins that rely on exec during initialization to attach first to CordovaReady, as the communication bridge may not be fully ready before this event fires.

changing plugins that rely on exec during initialization to attach first to CordovaReady, as the communication bridge may not be fully ready before this event fires.


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/d2fc7133
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/d2fc7133
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/d2fc7133

Branch: refs/heads/master
Commit: d2fc71333c12d1b13cdcae58b50eec26a82e3b30
Parents: cddb3b8
Author: Fil Maj <ma...@gmail.com>
Authored: Thu Mar 29 16:12:25 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Mar 29 16:12:25 2012 -0700

----------------------------------------------------------------------
 lib/android/plugin/android/device.js       |    9 ++-
 lib/blackberry/plugin/blackberry/device.js |   16 +++---
 lib/common/plugin/network.js               |   73 ++++++++++++-----------
 lib/playbook/plugin/playbook/device.js     |    7 +-
 4 files changed, 54 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/android/plugin/android/device.js
----------------------------------------------------------------------
diff --git a/lib/android/plugin/android/device.js b/lib/android/plugin/android/device.js
index 44a80c6..353d0ed 100644
--- a/lib/android/plugin/android/device.js
+++ b/lib/android/plugin/android/device.js
@@ -16,8 +16,9 @@ function Device() {
     this.cordova = null;
 
     var me = this;
-    this.getInfo(
-        function(info) {
+
+    channel.onCordovaReady.subscribeOnce(function() {
+        this.getInfo(function(info) {
             me.available = true;
             me.platform = info.platform;
             me.version = info.version;
@@ -25,11 +26,11 @@ function Device() {
             me.uuid = info.uuid;
             me.cordova = info.cordova;
             channel.onCordovaInfoReady.fire();
-        },
-        function(e) {
+        },function(e) {
             me.available = false;
             utils.alert("[ERROR] Error initializing Cordova: " + e);
         });
+    });
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/blackberry/plugin/blackberry/device.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/blackberry/device.js b/lib/blackberry/plugin/blackberry/device.js
index 42a0647..01b41e5 100644
--- a/lib/blackberry/plugin/blackberry/device.js
+++ b/lib/blackberry/plugin/blackberry/device.js
@@ -2,8 +2,8 @@ var me = {},
     channel = require('cordova/channel'),
     exec = require('cordova/exec');
 
-exec(
-    function (device) {
+channel.onCordovaReady.subscribeOnce(function() {
+    exec(function (device) {
         me.platform = device.platform;
         me.version  = device.version;
         me.name     = device.name;
@@ -11,13 +11,13 @@ exec(
         me.cordova  = device.cordova;
 
         channel.onCordovaInfoReady.fire();
-    },
-    function (e) {
+    },function (e) {
         console.log("error initializing cordova: " + e);
     },
-    "Device",
-    "getDeviceInfo",
-    []
-);
+        "Device",
+        "getDeviceInfo",
+        []
+    );
+});
 
 module.exports = me;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/common/plugin/network.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/network.js b/lib/common/plugin/network.js
index 899aab5..f5b4fd4 100644
--- a/lib/common/plugin/network.js
+++ b/lib/common/plugin/network.js
@@ -3,46 +3,47 @@ var exec = require('cordova/exec'),
     channel = require('cordova/channel');
 
 var NetworkConnection = function () {
-        this.type = null;
-        this._firstRun = true;
-        this._timer = null;
-        this.timeout = 500;
+    this.type = null;
+    this._firstRun = true;
+    this._timer = null;
+    this.timeout = 500;
 
-        var me = this;
+    var me = this;
 
-        this.getInfo(
-            function (info) {
-                me.type = info;
-                if (info === "none") {
-                    // set a timer if still offline at the end of timer send the offline event
-                    me._timer = setTimeout(function(){
-                        cordova.fireDocumentEvent("offline");
-                        me._timer = null;
-                        }, me.timeout);
-                } else {
-                    // If there is a current offline event pending clear it
-                    if (me._timer !== null) {
-                        clearTimeout(me._timer);
-                        me._timer = null;
-                    }
-                    cordova.fireDocumentEvent("online");
+    channel.onCordovaReady.subscribeOnce(function() {
+        me.getInfo(function (info) {
+            me.type = info;
+            if (info === "none") {
+                // set a timer if still offline at the end of timer send the offline event
+                me._timer = setTimeout(function(){
+                    cordova.fireDocumentEvent("offline");
+                    me._timer = null;
+                    }, me.timeout);
+            } else {
+                // If there is a current offline event pending clear it
+                if (me._timer !== null) {
+                    clearTimeout(me._timer);
+                    me._timer = null;
                 }
+                cordova.fireDocumentEvent("online");
+            }
 
-                // should only fire this once
-                if (me._firstRun) {
-                    me._firstRun = false;
-                    channel.onCordovaConnectionReady.fire();
-                }
-            },
-            function (e) {
-                // If we can't get the network info we should still tell Cordova
-                // to fire the deviceready event.
-                if (me._firstRun) {
-                    me._firstRun = false;
-                    channel.onCordovaConnectionReady.fire();
-                }
-                console.log("Error initializing Network Connection: " + e);
-            });
+            // should only fire this once
+            if (me._firstRun) {
+                me._firstRun = false;
+                channel.onCordovaConnectionReady.fire();
+            }
+        },
+        function (e) {
+            // If we can't get the network info we should still tell Cordova
+            // to fire the deviceready event.
+            if (me._firstRun) {
+                me._firstRun = false;
+                channel.onCordovaConnectionReady.fire();
+            }
+            console.log("Error initializing Network Connection: " + e);
+        });
+    });
 };
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d2fc7133/lib/playbook/plugin/playbook/device.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/device.js b/lib/playbook/plugin/playbook/device.js
index 90ec376..f3d86ec 100644
--- a/lib/playbook/plugin/playbook/device.js
+++ b/lib/playbook/plugin/playbook/device.js
@@ -2,8 +2,8 @@ var me = {},
     exec = require('cordova/exec'),
     channel = require('cordova/channel');
 
-exec(
-    function (device) {
+channel.onCordovaReady.subscribeOnce(function() {
+    exec(function (device) {
         me.platform = device.platform;
         me.version  = device.version;
         me.name     = device.name;
@@ -18,6 +18,7 @@ exec(
     "Device",
     "getDeviceInfo",
     []
-);
+    );
+});
 
 module.exports = me;