commonroutesServer/www/plugins/cordova-plugin-device/src/firefoxos/DeviceProxy.js
www/plugins/cordova-plugin-device/src/firefoxos/DeviceProxy.jsRaw
1/*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21//example UA String for Firefox OS
22//Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0
23
24//UA parsing not recommended but currently this is the only way to get the Firefox OS version
25//https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
26
27//Should be replaced when better conversion to Firefox OS Version is available
28function convertVersionNumber(ver) {
29 var hashVersion = {
30 '18.0': '1.0.1',
31 '18.1': '1.1',
32 '26.0': '1.2',
33 '28.0': '1.3',
34 '30.0': '1.4',
35 '32.0': '2.0'
36 };
37 var rver = ver;
38 var sStr = ver.substring(0, 4);
39 if (hashVersion[sStr]) {
40 rver = hashVersion[sStr];
41 }
42 return (rver);
43
44}
45function getVersion() {
46 if (navigator.userAgent.match(/(mobile|tablet)/i)) {
47 var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
48 if (ffVersionArray.length === 2) {
49 return (convertVersionNumber(ffVersionArray[1]));
50 }
51 }
52 return (null);
53}
54
55function getModel() {
56 var uaArray = navigator.userAgent.split(/\s*[;)(]\s*/);
57 if (navigator.userAgent.match(/(mobile|tablet)/i)) {
58 if (uaArray.length === 5) {
59 return (uaArray[2]);
60 }
61 }
62 return (null);
63}
64module.exports = {
65 getDeviceInfo: function (success, error) {
66 setTimeout(function () {
67 success({
68 platform: 'firefoxos',
69 model: getModel(),
70 version: getVersion(),
71 uuid: null
72 });
73 }, 0);
74 }
75};
76
77require("cordova/exec/proxy").add("Device", module.exports);