incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [25/40] git commit: Fixed case issue with CordovaCommandResult, device is the same implemenation as Android
Date Fri, 06 Apr 2012 01:20:43 GMT
Fixed case issue with CordovaCommandResult, device is the same implemenation as Android


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

Branch: refs/heads/master
Commit: 558a632534591d25a48b23752b78a7ff58a93795
Parents: b1c58fa
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed Mar 28 01:06:11 2012 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed Mar 28 16:01:35 2012 -0700

----------------------------------------------------------------------
 lib/wp7/plugin/wp7/device.js |   78 +++++++++++++++++++++++++++++--------
 1 files changed, 62 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/558a6325/lib/wp7/plugin/wp7/device.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/device.js b/lib/wp7/plugin/wp7/device.js
index 62587f8..ad3c9e7 100644
--- a/lib/wp7/plugin/wp7/device.js
+++ b/lib/wp7/plugin/wp7/device.js
@@ -3,26 +3,72 @@
  * phone, etc.
  * @constructor
  */
-var Device = function() 
-{
+var exec = require('cordova/exec'),
+    channel = require('cordova/channel');
+var Cordova = require("cordova");
+
+var Device = function() {
     this.platform = null;
     this.version  = null;
     this.name     = null;
-    this.phonegap = null;
+    this.cordova  = 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;
-    } 
-    catch(e) {
-        // TODO: 
-		
-		console.log("error in device.js : " + e);
+	
+	var me = this;
+    this.getInfo(function (res) {
+			console.log("Device.getInfo::" + res);
+            var info = JSON.parse(res);
+            console.log("GotDeviceInfo :: " + info.version);
+            me.available = true;
+            me.platform = info.platform;
+            me.version = info.version;
+            me.name = info.name;
+            me.uuid = info.uuid;
+            me.cordova = info.cordova;
+
+            Cordova.onCordovaInfoReady.fire();
+        },
+        function(e) {
+            me.available = false;
+            console.log("Error initializing Cordova: " + e);
+        });
+};
+
+/**
+ * Get device info
+ *
+ * @param {Function} successCallback The function to call when the heading data is available
+ * @param {Function} errorCallback The function to call when there is an error getting the
heading data. (OPTIONAL)
+ */
+Device.prototype.getInfo = function(successCallback, errorCallback) {
+
+    // successCallback required
+    if (typeof successCallback !== "function") {
+        console.log("Device Error: successCallback is not a function");
+        return;
+    }
+
+    // errorCallback optional
+    if (errorCallback && (typeof errorCallback !== "function")) {
+        console.log("Device Error: errorCallback is not a function");
+        return;
+    }
+
+    // Get info
+    exec(successCallback, errorCallback, "Device", "Get");
+};
+
+Device.prototype.setInfo = function(info) {
+    try {
+        this.platform = info.platform;
+        this.version = info.version;
+        this.name = info.name;
+        this.cordova = info.gap;
+        this.uuid = info.uuid;
+        channel.onCordovaInfoReady.fire();
+    } catch(e) {
+        alert('Error during device info setting in cordova/plugin/ios/device!');
     }
-    this.available = Cordova.available = !!this.uuid;
 };
 
-module.exports = new Device();
+module.exports = new Device;


Mime
View raw message