1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Touchgui/plugins/org.apache.cordova.device/www/device.js Thu Jun 04 14:50:33 2015 +0200 1.3 @@ -0,0 +1,77 @@ 1.4 +/* 1.5 + * 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * 1.23 +*/ 1.24 + 1.25 +var argscheck = require('cordova/argscheck'), 1.26 + channel = require('cordova/channel'), 1.27 + utils = require('cordova/utils'), 1.28 + exec = require('cordova/exec'), 1.29 + cordova = require('cordova'); 1.30 + 1.31 +channel.createSticky('onCordovaInfoReady'); 1.32 +// Tell cordova channel to wait on the CordovaInfoReady event 1.33 +channel.waitForInitialization('onCordovaInfoReady'); 1.34 + 1.35 +/** 1.36 + * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the 1.37 + * phone, etc. 1.38 + * @constructor 1.39 + */ 1.40 +function Device() { 1.41 + this.available = false; 1.42 + this.platform = null; 1.43 + this.version = null; 1.44 + this.uuid = null; 1.45 + this.cordova = null; 1.46 + this.model = null; 1.47 + 1.48 + var me = this; 1.49 + 1.50 + channel.onCordovaReady.subscribe(function() { 1.51 + me.getInfo(function(info) { 1.52 + //ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js 1.53 + //TODO: CB-5105 native implementations should not return info.cordova 1.54 + var buildLabel = cordova.version; 1.55 + me.available = true; 1.56 + me.platform = info.platform; 1.57 + me.version = info.version; 1.58 + me.uuid = info.uuid; 1.59 + me.cordova = buildLabel; 1.60 + me.model = info.model; 1.61 + channel.onCordovaInfoReady.fire(); 1.62 + },function(e) { 1.63 + me.available = false; 1.64 + utils.alert("[ERROR] Error initializing Cordova: " + e); 1.65 + }); 1.66 + }); 1.67 +} 1.68 + 1.69 +/** 1.70 + * Get device info 1.71 + * 1.72 + * @param {Function} successCallback The function to call when the heading data is available 1.73 + * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL) 1.74 + */ 1.75 +Device.prototype.getInfo = function(successCallback, errorCallback) { 1.76 + argscheck.checkArgs('fF', 'Device.getInfo', arguments); 1.77 + exec(successCallback, errorCallback, "Device", "getDeviceInfo", []); 1.78 +}; 1.79 + 1.80 +module.exports = new Device();