|
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 var browser = require('cordova/platform'); |
|
22 var cordova = require('cordova'); |
|
23 |
|
24 function getPlatform() { |
|
25 return "browser"; |
|
26 } |
|
27 |
|
28 function getModel() { |
|
29 return getBrowserInfo(true); |
|
30 } |
|
31 |
|
32 function getVersion() { |
|
33 return getBrowserInfo(false); |
|
34 } |
|
35 |
|
36 function getBrowserInfo(getModel) { |
|
37 var userAgent = navigator.userAgent; |
|
38 var returnVal; |
|
39 |
|
40 if ((offset = userAgent.indexOf('Chrome')) !== -1) { |
|
41 returnVal = (getModel) ? 'Chrome' : userAgent.substring(offset + 7); |
|
42 } else if ((offset = userAgent.indexOf('Safari')) !== -1) { |
|
43 if (getModel) { |
|
44 returnVal = 'Safari'; |
|
45 } else { |
|
46 returnVal = userAgent.substring(offset + 7); |
|
47 |
|
48 if ((offset = userAgent.indexOf('Version')) !== -1) { |
|
49 returnVal = userAgent.substring(offset + 8); |
|
50 } |
|
51 } |
|
52 } else if ((offset = userAgent.indexOf('Firefox')) !== -1) { |
|
53 returnVal = (getModel) ? 'Firefox' : userAgent.substring(offset + 8); |
|
54 } |
|
55 |
|
56 if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) { |
|
57 returnVal = returnVal.substring(0, offset); |
|
58 } |
|
59 |
|
60 return returnVal; |
|
61 } |
|
62 |
|
63 |
|
64 module.exports = { |
|
65 getDeviceInfo: function (success, error) { |
|
66 setTimeout(function () { |
|
67 success({ |
|
68 cordova: browser.cordovaVersion, |
|
69 platform: getPlatform(), |
|
70 model: getModel(), |
|
71 version: getVersion(), |
|
72 uuid: null |
|
73 }); |
|
74 }, 0); |
|
75 } |
|
76 }; |
|
77 |
|
78 require("cordova/exec/proxy").add("Device", module.exports); |