1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Touchgui/plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js Thu Jun 04 14:50:33 2015 +0200 1.3 @@ -0,0 +1,79 @@ 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 +//example UA String for Firefox OS 1.25 +//Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0 1.26 +var firefoxos = require('cordova/platform'); 1.27 +var cordova = require('cordova'); 1.28 + 1.29 +//UA parsing not recommended but currently this is the only way to get the Firefox OS version 1.30 +//https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference 1.31 + 1.32 +//Should be replaced when better conversion to Firefox OS Version is available 1.33 +function convertVersionNumber(ver) { 1.34 + var hashVersion = { 1.35 + '18.0': '1.0.1', 1.36 + '18.1': '1.1', 1.37 + '26.0': '1.2', 1.38 + '28.0': '1.3', 1.39 + '30.0': '1.4', 1.40 + '32.0': '2.0' 1.41 + }; 1.42 + var rver = ver; 1.43 + var sStr = ver.substring(0, 4); 1.44 + if (hashVersion[sStr]) { 1.45 + rver = hashVersion[sStr]; 1.46 + } 1.47 + return (rver); 1.48 + 1.49 +} 1.50 +function getVersion() { 1.51 + if (navigator.userAgent.match(/(mobile|tablet)/i)) { 1.52 + var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/)); 1.53 + if (ffVersionArray.length === 2) { 1.54 + return (convertVersionNumber(ffVersionArray[1])); 1.55 + } 1.56 + } 1.57 + return (null); 1.58 +} 1.59 + 1.60 +function getModel() { 1.61 + var uaArray = navigator.userAgent.split(/\s*[;)(]\s*/); 1.62 + if (navigator.userAgent.match(/(mobile|tablet)/i)) { 1.63 + if (uaArray.length === 5) { 1.64 + return (uaArray[2]); 1.65 + } 1.66 + } 1.67 + return (null); 1.68 +} 1.69 +module.exports = { 1.70 + getDeviceInfo: function (success, error) { 1.71 + setTimeout(function () { 1.72 + success({ 1.73 + platform: 'firefoxos', 1.74 + model: getModel(), 1.75 + version: getVersion(), 1.76 + uuid: null 1.77 + }); 1.78 + }, 0); 1.79 + } 1.80 +}; 1.81 + 1.82 +require("cordova/exec/proxy").add("Device", module.exports);