You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/04/06 03:20:42 UTC
[13/40] git commit: bootstrapping exec + device ready initialization
bootstrapping exec + device ready initialization
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/af5a9266
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/af5a9266
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/af5a9266
Branch: refs/heads/master
Commit: af5a9266ed0f5ff1c83974f003d0a79e83b69b0c
Parents: 19c7fee
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Mar 30 12:20:13 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Mar 30 12:20:13 2012 -0700
----------------------------------------------------------------------
lib/wp7/exec.js | 18 +++++--
lib/wp7/platform.js | 18 ++-----
lib/wp7/plugin/wp7/CordovaCommandResult.js | 67 ++++++++++++-----------
lib/wp7/plugin/wp7/device.js | 65 +++++++---------------
4 files changed, 74 insertions(+), 94 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/af5a9266/lib/wp7/exec.js
----------------------------------------------------------------------
diff --git a/lib/wp7/exec.js b/lib/wp7/exec.js
index 9ea4831..227a489 100644
--- a/lib/wp7/exec.js
+++ b/lib/wp7/exec.js
@@ -15,7 +15,8 @@ var cordova = require('cordova');
* @param {String[]} [args] Zero or more arguments to pass to the method
*/
-module.exports = function(success, fail, service, action, args) {
+module.exports = function(success, fail, service, action, args)
+{
var callbackId = service + cordova.callbackId++;
if (typeof success == "function" || typeof fail == "function")
{
@@ -24,13 +25,20 @@ module.exports = function(success, fail, service, action, args) {
// generate a new command string, ex. DebugConsole/log/DebugConsole23/{"message":"wtf dude?"}
var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args);
// pass it on to Notify
- if(window.external && window.external.Notify)
+ try
{
- window.external.Notify(command);
+ if(window.external)
+ {
+ window.external.Notify(command);
+ }
+ else
+ {
+ console.log("window.external not available :: command=" + command);
+ }
}
- else
+ catch(e)
{
- console.log("Notify: " + command);
+ console.log("Exception calling native with command :: " + command + " :: exception=" + e);
}
};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/af5a9266/lib/wp7/platform.js
----------------------------------------------------------------------
diff --git a/lib/wp7/platform.js b/lib/wp7/platform.js
index 660b6a3..13ba1e5 100644
--- a/lib/wp7/platform.js
+++ b/lib/wp7/platform.js
@@ -2,18 +2,13 @@ module.exports = {
id: "wp7",
initialize:function() {
- //window.Cordova = window.cordova;
-
-
+ console.log("wp7 initialize");
+ console.log("window.CordovaCommandResult = " + window.CordovaCommandResult);
+ //cordova.require("cordova/channel").onNativeReady.fire();
},
objects: {
- cordova: {
- children: {
-
- CordovaCommandResult: {
- path:"cordova/plugin/wp7/CordovaCommandResult"
- }
- }
+ CordovaCommandResult: {
+ path:"cordova/plugin/wp7/CordovaCommandResult"
},
navigator: {
children: {
@@ -21,9 +16,6 @@ module.exports = {
path: "cordova/plugin/wp7/device"
}
}
- },
- device: {
- path: 'cordova/plugin/wp7/device'
}
}
};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/af5a9266/lib/wp7/plugin/wp7/CordovaCommandResult.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/CordovaCommandResult.js b/lib/wp7/plugin/wp7/CordovaCommandResult.js
index 92b71be..6798457 100644
--- a/lib/wp7/plugin/wp7/CordovaCommandResult.js
+++ b/lib/wp7/plugin/wp7/CordovaCommandResult.js
@@ -1,37 +1,42 @@
-console.log("CordovaComandResult is being added");
var cordova = require('cordova');
var channel = require('cordova/channel');
-//module.exports = {
- // singular WP7 callback function attached to window, status is used to determin if it is a success or error
-var CordovaCommandResult = function(status,callbackId,args,cast) {
- if(status === "backbutton") {
- cordova.fireEvent(document,"backbutton");
- return "true";
- }
- else if(status === "resume") {
- channel.onResume.fire();
- return "true";
- }
- else if(status === "pause") {
-
- channel.onPause.fire();
- return "true";
- }
-
- var safeStatus = parseInt(status, 10);
- if(safeStatus === cordova.callbackStatus.NO_RESULT ||
- safeStatus === cordova.callbackStatus.OK) {
- cordova.callbackSuccess(callbackId,args,cast);
- }
- else
- {
- cordova.callbackError(callbackId,args,cast);
- }
- };
+// singular WP7 callback function attached to window, status is used to determin if it is a success or error
+module.exports = function(status,callbackId,args,cast) {
+
+ if(status === "backbutton") {
+ cordova.fireEvent(document,"backbutton");
+ return "true";
+ }
+ else if(status === "resume") {
+ channel.onResume.fire();
+ return "true";
+ }
+ else if(status === "pause") {
+ channel.onPause.fire();
+ return "true";
+ }
+
+ var parsedArgs = JSON.parse(args);
+ try
+ {
+ // For some commands, the message is a JSON encoded string
+ // and other times, it is just a string, the try/catch handles the
+ // case where message was indeed, just a string.
+ parsedArgs.message = JSON.parse(parsedArgs.message);
+ }
+ catch(e)
+ {
+ }
+ var safeStatus = parseInt(status, 10);
+ if(safeStatus === cordova.callbackStatus.NO_RESULT ||
+ safeStatus === cordova.callbackStatus.OK) {
+ cordova.callbackSuccess(callbackId,parsedArgs,cast);
+ }
+ else {
+ cordova.callbackError(callbackId,parsedArgs,cast);
+ }
+};
-//}
-module.exports = CordovaCommandResult;
-console.log("CordovaComandResult is added");
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/af5a9266/lib/wp7/plugin/wp7/device.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/device.js b/lib/wp7/plugin/wp7/device.js
index 729c22a..8940115 100644
--- a/lib/wp7/plugin/wp7/device.js
+++ b/lib/wp7/plugin/wp7/device.js
@@ -1,45 +1,37 @@
+var channel = require('cordova/channel'),
+ utils = require('cordova/utils'),
+ exec = require('cordova/exec');
+
/**
- * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
+ * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
* phone, etc.
* @constructor
*/
-
-console.log("device is being added");
-
-var cordova = require("cordova");
-var exec = require('cordova/exec'),
- channel = require('cordova/channel');
-var utils = require('cordova/utils');
+function Device() {
+ this.available = false;
+ this.platform = null;
+ this.version = null;
+ this.name = null;
+ this.uuid = null;
+ this.cordova = null;
+ var me = this;
-var Device = function() {
- console.log("device constructor");
- this.platform = null;
- this.version = null;
- this.name = null;
- this.cordova = null;
- this.uuid = null;
-
- var me = this;
- this.getInfo(function (res) {
- console.log("Device.gotInfo::" + res);
- var info = JSON.parse(res);
- console.log("GotDeviceInfo :: " + info.version);
+ channel.onCordovaReady.subscribeOnce(function() {
+ me.getInfo(function(info) {
me.available = true;
me.platform = info.platform;
me.version = info.version;
me.name = info.name;
me.uuid = info.uuid;
me.cordova = info.cordova;
-
channel.onCordovaInfoReady.fire();
- },
- function(e) {
+ },function(e) {
me.available = false;
- console.log("Error initializing Cordova: " + e);
+ utils.alert("[ERROR] Error initializing Cordova: " + e);
});
-
-};
+ });
+}
/**
* Get device info
@@ -49,7 +41,6 @@ var Device = function() {
*/
Device.prototype.getInfo = function(successCallback, errorCallback) {
- console.log("device.getInfo");
// successCallback required
if (typeof successCallback !== "function") {
console.log("Device Error: successCallback is not a function");
@@ -63,23 +54,7 @@ Device.prototype.getInfo = function(successCallback, errorCallback) {
}
// Get info
- //exec(successCallback, errorCallback, "Device", "Get");
-};
-
-Device.prototype.setInfo = function(info) {
- console.log("setting device info " + 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!');
- }
+ exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
};
module.exports = new Device();
-
-console.log("device is live + done");