Updated Branches: refs/heads/master 7e385cb50 -> 30c933afc
Updated javascript and added a debug-simulator command Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/commit/30c933af Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/tree/30c933af Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/diff/30c933af Branch: refs/heads/master Commit: 30c933afcd44084eb3e32080c91c2f7165c97726 Parents: 7e385cb Author: Gord Tanner <[email protected]> Authored: Mon Nov 12 20:57:15 2012 -0500 Committer: Gord Tanner <[email protected]> Committed: Mon Nov 12 20:57:15 2012 -0500 ---------------------------------------------------------------------- bin/templates/project/blackberry.xml | 95 ++++++++++++ bin/templates/project/build.xml | 6 + bin/templates/project/playbook.xml | 15 ++ bin/templates/project/qnx.xml | 17 ++ javascript/cordova.blackberry.js | 230 ++++++++++++++++++----------- 5 files changed, 274 insertions(+), 89 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/30c933af/bin/templates/project/blackberry.xml ---------------------------------------------------------------------- diff --git a/bin/templates/project/blackberry.xml b/bin/templates/project/blackberry.xml index e34ba69..ce3099f 100644 --- a/bin/templates/project/blackberry.xml +++ b/bin/templates/project/blackberry.xml @@ -165,6 +165,101 @@ </then> </if> </target> + + <target name="debug-simulator" depends="package-app"> + <bbwp code-sign="false" debug="true" /> + + <!-- Find the simulator directory --> + <set-simulator-dir /> + + <!-- Locate BBWP simulator directory. There may be multiple, so choose the first. --> + <path id="bbwp.sim.path"> + <first> + <fileset dir="${properties.blackberry.bbwp.dir}/simpack"> + <include name="**/handhelds.manifest.txt" /> + </fileset> + </first> + </path> + <dirname property="bbwp.sim.dir" file="${toString:bbwp.sim.path}" /> + + <!-- Simulator directory: Use sim.dir property if set in project.properties file. + Otherwise, use bbwp simulator directory. --> + <condition + property="simulator.dir" + value="${properties.blackberry.sim.dir}" + else="${bbwp.sim.dir}"> + <available file="${properties.blackberry.sim.dir}" type="dir" /> + </condition> + <echo message="Simulator directory=${simulator.dir}" /> + + <!-- Simulator binary: Use sim.bin property if set in project.properties file + or try setting to 'defaultSimulator.bat' in simulator directory. --> + <condition + property="sim.bin" + value="${properties.blackberry.sim.bin}" + else="defaultSimulator.bat"> + <available file="${simulator.dir}/${properties.blackberry.sim.bin}"/> + </condition> + + <!-- If simulator executable does not exist, use the first device listed + in the 'handhelds.manifest.txt' file in the simulator directory. --> + <loadfile + property="device.list" + srcFile="${simulator.dir}/handhelds.manifest.txt"> + <filterchain> + <tokenFilter> + <stringtokenizer/> + </tokenFilter> + </filterchain> + </loadfile> + + <propertyregex property="device" + input="${device.list}" + regexp="^\d{4}" + select="\0" + override="true" /> + <property name="device.bin" value="${device}.bat" /> + + <condition + property="simulator.bin" + value="${sim.bin}" + else="${device.bin}"> + <available file="${simulator.dir}/${sim.bin}" /> + </condition> + + <echo message="Simulator executable=${simulator.dir}/${simulator.bin}" /> + + <!-- Close running simulators --> + <echo message="Closing all running simulators..." /> + <exec executable="${simulator.dir}/fledgecontroller.exe" dir="${simulator.dir}" spawn="false"> + <arg value="/execute=kill" /> + </exec> + + <!-- MDS directory: Use mds.dir property if set in project.properties file. + Otherwise, use bbwp MDS directory. --> + <condition + property="mds.dir" + value="${properties.blackberry.mds.dir}" + else="${properties.blackberry.bbwp.dir}/mds"> + <available file="${properties.blackberry.mds.dir}" type="dir" /> + </condition> + <echo message="MDS directory=${mds.dir}" /> + + <copy todir="${simulator.dir}"> + <fileset dir="${build.dir}/StandardInstall" includes="*.cod, *.cso, *.csl, *.alx" /> + </copy> + <exec executable="${mds.dir}/run.bat" dir="${mds.dir}" spawn="true" /> + <exec executable="${simulator.dir}/${simulator.bin}" dir="${simulator.dir}" spawn="true" /> + + <!-- Only invoke FledgeHook.exe if it is found. Newer versions of the + WebWorks SDK do not include it. --> + <if> + <available file="${properties.blackberry.bbwp.dir}/FledgeHook.exe" /> + <then> + <exec executable="${properties.blackberry.bbwp.dir}/FledgeHook.exe" dir="${properties.blackberry.bbwp.dir}" spawn="true" /> + </then> + </if> + </target> <!-- PACKAGE-APP --> http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/30c933af/bin/templates/project/build.xml ---------------------------------------------------------------------- diff --git a/bin/templates/project/build.xml b/bin/templates/project/build.xml index cab5c8c..610929b 100644 --- a/bin/templates/project/build.xml +++ b/bin/templates/project/build.xml @@ -57,6 +57,12 @@ </subant> </target> + <target name="debug-simulator"> + <subant target="debug-simulator"> + <fileset dir="." includes="${subant.file}"/> + </subant> + </target> + <target name="debug-device"> <subant target="debug-device"> <fileset dir="." includes="${subant.file}"/> http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/30c933af/bin/templates/project/playbook.xml ---------------------------------------------------------------------- diff --git a/bin/templates/project/playbook.xml b/bin/templates/project/playbook.xml index 6ee2af4..b0b087a 100644 --- a/bin/templates/project/playbook.xml +++ b/bin/templates/project/playbook.xml @@ -97,6 +97,21 @@ </exec> </target> + <target name="debug-simulator" depends="package-app"> + <bbwp code-sign="false" debug="true" /> + <echo>This tool will not open the simulator for you </echo> + + <exec executable="${blackberry-deploy}" dir="." failonerror="true"> + <arg value="-installApp" /> + <arg value="-launchApp" /> + <arg value="-device" /> + <arg value="${properties.playbook.sim.ip}" /> + <arg value="-password" /> + <arg value="${properties.playbook.sim.password}" /> + <arg value="-package" /> + <arg file="${build.dir}/${cod.name}.bar" /> + </exec> + </target> <!-- PACKAGE-APP --> <target name="package-app" depends="generate-cod-name, clean"> http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/30c933af/bin/templates/project/qnx.xml ---------------------------------------------------------------------- diff --git a/bin/templates/project/qnx.xml b/bin/templates/project/qnx.xml index 544511c..d63ae5d 100644 --- a/bin/templates/project/qnx.xml +++ b/bin/templates/project/qnx.xml @@ -97,6 +97,23 @@ </exec> </target> + <target name="debug-simulator" depends="package-app"> + + <bbwp code-sign="false" debug="true" /> + <echo>This tool will not open the simulator for you </echo> + + <exec executable="${blackberry-deploy}" dir="." failonerror="true"> + <arg value="-installApp" /> + <arg value="-launchApp" /> + <arg value="-device" /> + <arg value="${properties.qnx.sim.ip}" /> + <arg value="-password" /> + <arg value="${properties.qnx.sim.password}" /> + <arg value="-package" /> + <arg file="${build.dir}/simulator/${cod.name}.bar" /> + </exec> + </target> + <!-- PACKAGE-APP --> <target name="package-app" depends="generate-cod-name, clean"> http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/30c933af/javascript/cordova.blackberry.js ---------------------------------------------------------------------- diff --git a/javascript/cordova.blackberry.js b/javascript/cordova.blackberry.js index 7890da6..3ed2e15 100644 --- a/javascript/cordova.blackberry.js +++ b/javascript/cordova.blackberry.js @@ -1,6 +1,6 @@ -// commit 0919268c22c87e3b2640999d963ae074a33d445e +// commit 759bd701e4557921913da13555fdd4661dd98cf6 -// File generated at :: Fri Nov 02 2012 09:45:24 GMT-0400 (EDT) +// File generated at :: Mon Nov 12 2012 20:30:55 GMT-0500 (EST) /* Licensed to the Apache Software Foundation (ASF) under one @@ -329,14 +329,24 @@ function each(objects, func, context) { } } +function clobber(obj, key, value) { + obj[key] = value; + // Getters can only be overridden by getters. + if (obj[key] !== value) { + utils.defineGetter(obj, key, function() { + return value; + }); + } +} + function assignOrWrapInDeprecateGetter(obj, key, value, message) { if (message) { utils.defineGetter(obj, key, function() { - window.console && console.log(message); + console.log(message); return value; }); } else { - obj[key] = value; + clobber(obj, key, value); } } @@ -395,8 +405,11 @@ function recursiveMerge(target, src) { // If the target object is a constructor override off prototype. target.prototype[prop] = src[prop]; } else { - target[prop] = typeof src[prop] === 'object' ? recursiveMerge( - target[prop], src[prop]) : src[prop]; + if (typeof src[prop] === 'object') { + target[prop] = recursiveMerge(target[prop], src[prop]); + } else { + clobber(target, prop, src[prop]); + } } } } @@ -737,9 +750,6 @@ module.exports = { compass:{ path: 'cordova/plugin/compass' }, - connection: { - path: 'cordova/plugin/network' - }, contacts: { path: 'cordova/plugin/contacts' }, @@ -907,6 +917,15 @@ module.exports = { resolveLocalFileSystemURI:{ path: 'cordova/plugin/resolveLocalFileSystemURI' } + }, + clobbers: { + navigator: { + children: { + connection: { + path: 'cordova/plugin/network' + } + }, + } } }; @@ -950,7 +969,6 @@ module.exports = function(success, fail, service, action, args) { catch (e) { console.log("Error in success callback: "+cordova.callbackId+" = "+e); } - } return v.message; } else if (v.status == cordova.callbackStatus.NO_RESULT) { @@ -983,15 +1001,17 @@ define("cordova/platform", function(require, exports, module) { module.exports = { id: "blackberry", runtime: function () { - var version = blackberry.system.softwareVersion; - window.wtf = version; - if (version.match(/^10/)) { + if (navigator.userAgent.indexOf("BB10") > -1) { return 'qnx'; } - else if (version.match(/^BlackBerry/)) { + else if (navigator.userAgent.indexOf("PlayBook") > -1) { return 'air'; } + else if (navigator.userAgent.indexOf("BlackBerry") > -1) { + return 'java'; + } else { + console.log("Unknown user agent?!?!? defaulting to java"); return 'java'; } }, @@ -7940,7 +7960,7 @@ module.exports = { // file: lib/blackberry/plugin/java/app.js define("cordova/plugin/java/app", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), platform = require('cordova/platform'), manager = require('cordova/plugin/' + platform.runtime() + '/manager'); @@ -8612,49 +8632,9 @@ if (typeof navigator != 'undefined') { }); } -var NetworkConnection = function () { - this.type = null; - this._firstRun = true; - this._timer = null; - this.timeout = 500; - - var me = this; - - channel.onCordovaReady.subscribe(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); - }); - }); -}; +function NetworkConnection() { + this.type = 'unknown'; +} /** * Get connection info @@ -8662,12 +8642,48 @@ var NetworkConnection = function () { * @param {Function} successCallback The function to call when the Connection data is available * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL) */ -NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) { - // Get info +NetworkConnection.prototype.getInfo = function(successCallback, errorCallback) { exec(successCallback, errorCallback, "NetworkStatus", "getConnectionInfo", []); }; -module.exports = new NetworkConnection(); +var me = new NetworkConnection(); +var timerId = null; +var timeout = 500; + +channel.onCordovaReady.subscribe(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 + timerId = setTimeout(function(){ + cordova.fireDocumentEvent("offline"); + timerId = null; + }, timeout); + } else { + // If there is a current offline event pending clear it + if (timerId !== null) { + clearTimeout(timerId); + timerId = null; + } + cordova.fireDocumentEvent("online"); + } + + // should only fire this once + if (channel.onCordovaConnectionReady.state !== 2) { + channel.onCordovaConnectionReady.fire(); + } + }, + function (e) { + // If we can't get the network info we should still tell Cordova + // to fire the deviceready event. + if (channel.onCordovaConnectionReady.state !== 2) { + channel.onCordovaConnectionReady.fire(); + } + console.log("Error initializing Network Connection: " + e); + }); +}); + +module.exports = me; }); @@ -8743,15 +8759,16 @@ module.exports = { start: function (args, win, fail) { interval = window.setInterval(function () { win({ - level: 0, - isPlugged: false + level: navigator.webkitBattery.level * 100, + isPlugged: navigator.webkitBattery.charging }); }, 500); return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" }; }, stop: function (args, win, fail) { - window.stopInterval(interval); + window.clearInterval(interval); + return { "status" : cordova.callbackStatus.OK, "message" : "stopped" }; } }; @@ -8785,7 +8802,7 @@ function capture(action, win, fail) { blackberry.invoke.card.invokeCamera(action, function (path) { var sb = blackberry.io.sandbox; blackberry.io.sandbox = false; - webkitRequestFileSystem(PERSISTENT, 1024, function (fs) { + window.webkitRequestFileSystem(window.PERSISTENT, 1024, function (fs) { fs.root.getFile(path, {}, function (fe) { fe.file(function (file) { file.fullPath = fe.fullPath; @@ -9112,8 +9129,7 @@ module.exports = { // file: lib/blackberry/plugin/qnx/network.js define("cordova/plugin/qnx/network", function(require, exports, module) { -var cordova = require('cordova'), - connection = require('cordova/plugin/Connection'); +var cordova = require('cordova'); module.exports = { getConnectionInfo: function (args, win, fail) { @@ -9323,7 +9339,7 @@ module.exports = { }, stop: function (args, win, fail) { window.removeEventListener("devicemotion", callback); - return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" }; + return { "status" : cordova.callbackStatus.OK, "message" : "removed" }; } }; @@ -9426,7 +9442,6 @@ module.exports = { result = {"status" : 1, "message" : "Seek to audio succeeded" }; } - return result; }, pausePlayingAudio: function (args, win, fail) { @@ -9570,6 +9585,30 @@ utils.defineGetter = function(obj, key, func) { } }; +utils.arrayIndexOf = function(a, item) { + if (a.indexOf) { + return a.indexOf(item); + } + var len = a.length; + for (var i = 0; i < len; ++i) { + if (a[i] == item) { + return i; + } + } + return -1; +}; + +/** + * Returns whether the item was found in the array. + */ +utils.arrayRemove = function(a, item) { + var index = utils.arrayIndexOf(a, item); + if (index != -1) { + a.splice(index, 1); + } + return index != -1; +}; + /** * Returns an indication of whether the argument is an array or not */ @@ -9765,10 +9804,10 @@ window.cordova = require('cordova'); (function (context) { // Replace navigator before any modules are required(), to ensure it happens as soon as possible. // We replace it so that properties that can't be clobbered can instead be overridden. - if (typeof navigator != 'undefined') { - var CordovaNavigator = function () {}; - CordovaNavigator.prototype = navigator; - navigator = new CordovaNavigator(); + if (context.navigator) { + function CordovaNavigator() {} + CordovaNavigator.prototype = context.navigator; + context.navigator = new CordovaNavigator(); } var channel = require("cordova/channel"), @@ -9783,15 +9822,27 @@ window.cordova = require('cordova'); platform = require('cordova/platform'); // Drop the common globals into the window object, but be nice and don't overwrite anything. - builder.build(base.objects).intoButDoNotClobber(window); + builder.build(base.objects).intoButDoNotClobber(context); + + if (base.merges) { + builder.build(base.merges).intoAndMerge(context); + } + + if (base.clobbers) { + builder.build(base.clobbers).intoAndClobber(context); + } // Drop the platform-specific globals into the window object // and clobber any existing object. - builder.build(platform.objects).intoAndClobber(window); + if (platform.object) { + builder.build(platform.objects).intoAndClobber(context); + } // Merge the platform-specific overrides/enhancements into // the window object. - builder.build(platform.merges).intoAndMerge(window); + if (platform.merges) { + builder.build(platform.merges).intoAndMerge(context); + } // Call the platform-specific initialization platform.initialize(); @@ -9823,20 +9874,21 @@ window.cordova = require('cordova'); // file: lib/scripts/bootstrap-blackberry.js -switch(require('cordova/platform').runtime()) { -case 'qnx': - console.log('booting!'); - document.addEventListener("webworksready", function () { +document.addEventListener("DOMContentLoaded", function () { + switch(require('cordova/platform').runtime()) { + case 'qnx': + document.addEventListener("webworksready", function () { + require('cordova/channel').onNativeReady.fire(); + }); + break; + case 'air': require('cordova/channel').onNativeReady.fire(); - }); - break; -case 'air': - require('cordova/channel').onNativeReady.fire(); - break; -case 'java': - //nothing to do for java - break; -} + break; + case 'java': + //nothing to do for java + break; + } +}); })(); \ No newline at end of file
