Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15747 anikendra 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
var firefoxos = require('cordova/platform');
24
var cordova = require('cordova');
25
 
26
//UA parsing not recommended but currently this is the only way to get the Firefox OS version
27
//https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
28
 
29
//Should be replaced when better conversion to Firefox OS Version is available
30
function convertVersionNumber(ver) {
31
    var hashVersion = {
32
        '18.0': '1.0.1',
33
        '18.1': '1.1',
34
        '26.0': '1.2',
35
        '28.0': '1.3',
36
        '30.0': '1.4',
37
        '32.0': '2.0'
38
    };
39
    var rver = ver;
40
    var sStr = ver.substring(0, 4);
41
    if (hashVersion[sStr]) {
42
        rver = hashVersion[sStr];
43
    }
44
    return (rver);
45
 
46
}
47
function getVersion() {
48
    if (navigator.userAgent.match(/(mobile|tablet)/i)) {
49
        var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
50
        if (ffVersionArray.length === 2) {
51
            return (convertVersionNumber(ffVersionArray[1]));
52
        }
53
    }
54
    return (null);
55
}
56
 
57
function getModel() {
58
    var uaArray = navigator.userAgent.split(/\s*[;)(]\s*/);
59
    if (navigator.userAgent.match(/(mobile|tablet)/i)) {
60
        if (uaArray.length === 5) {
61
            return (uaArray[2]);
62
        }
63
    }
64
    return (null);
65
}
66
module.exports = {
67
    getDeviceInfo: function (success, error) {
68
        setTimeout(function () {
69
            success({
70
                platform: 'firefoxos',
71
                model: getModel(),
72
                version: getVersion(),
73
                uuid: null
74
            });
75
        }, 0);
76
    }
77
};
78
 
79
require("cordova/exec/proxy").add("Device", module.exports);