forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOS.js
More file actions
193 lines (149 loc) · 4.74 KB
/
OS.js
File metadata and controls
193 lines (149 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
var OS = {
// @property {boolean} desktop - Is running on a desktop?
desktop: false,
// @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView
webApp: false,
// @property {boolean} iOS - Is running on iOS?
iOS: false,
// @property {number} iOSVersion - If running in iOS this will contain the major version number.
iOSVersion: 0,
// @property {boolean} iPhone - Is running on iPhone?
iPhone: false,
// @property {boolean} iPad - Is running on iPad?
iPad: false,
// @property {boolean} cocoonJS - Is the game running under CocoonJS?
cocoonJS: false,
// @property {boolean} cocoonJSApp - Is this game running with CocoonJS.App?
cocoonJSApp: false,
// @property {boolean} cordova - Is the game running under Apache Cordova?
cordova: false,
// @property {boolean} node - Is the game running under Node.js?
node: false,
// @property {boolean} nodeWebkit - Is the game running under Node-Webkit?
nodeWebkit: false,
// @property {boolean} electron - Is the game running under GitHub Electron?
electron: false,
// @property {boolean} ejecta - Is the game running under Ejecta?
ejecta: false,
// @property {boolean} crosswalk - Is the game running under the Intel Crosswalk XDK?
crosswalk: false,
// @property {boolean} android - Is running on android?
android: false,
// @property {boolean} chromeOS - Is running on chromeOS?
chromeOS: false,
// @property {boolean} linux - Is running on linux?
linux: false,
// @property {boolean} macOS - Is running on macOS?
macOS: false,
// @property {boolean} windows - Is running on windows?
windows: false,
// @property {boolean} windowsPhone - Is running on a Windows Phone?
windowsPhone: false,
// @property {boolean} vita - Is running on a PlayStation Vita?
vita: false,
// @property {boolean} kindle - Is running on an Amazon Kindle?
kindle: false,
// @property {number} pixelRatio - PixelRatio of the host device?
pixelRatio: 1
};
function init ()
{
var ua = navigator.userAgent;
if (/Windows/.test(ua))
{
OS.windows = true;
}
else if (/Mac OS/.test(ua))
{
OS.macOS = true;
}
else if (/Linux/.test(ua))
{
OS.linux = true;
}
else if (/Android/.test(ua))
{
OS.android = true;
}
else if (/iP[ao]d|iPhone/i.test(ua))
{
OS.iOS = true;
(navigator.appVersion).match(/OS (\d+)/);
OS.iOSVersion = parseInt(RegExp.$1, 10);
}
else if (/Kindle/.test(ua) || (/\bKF[A-Z][A-Z]+/).test(ua) || (/Silk.*Mobile Safari/).test(ua))
{
OS.kindle = true;
// This will NOT detect early generations of Kindle Fire, I think there is no reliable way...
// E.g. "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true"
}
else if (/CrOS/.test(ua))
{
OS.chromeOS = true;
}
else if ((/Playstation Vita/).test(ua))
{
OS.vita = true;
}
if (/Windows Phone/i.test(ua) || (/IEMobile/i).test(ua))
{
OS.android = false;
OS.iOS = false;
OS.macOS = false;
OS.windows = true;
OS.windowsPhone = true;
}
var silk = (/Silk/).test(ua);
if (OS.windows || OS.macOS || (OS.linux && !silk) || OS.chromeOS)
{
OS.desktop = true;
}
// Windows Phone / Table reset
if (OS.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua))))
{
OS.desktop = false;
}
// WebApp mode in iOS
if (navigator.standalone)
{
OS.webApp = true;
}
if (window.cordova !== undefined)
{
OS.cordova = true;
}
if ((typeof process !== 'undefined') && (typeof process.versions.node !== 'undefined'))
{
OS.node = true;
}
if (OS.node && typeof process.versions === 'object')
{
OS.nodeWebkit = !!process.versions['node-webkit'];
OS.electron = !!process.versions.electron;
}
if (navigator.isCocoonJS)
{
OS.cocoonJS = true;
try
{
OS.cocoonJSApp = (typeof CocoonJS !== 'undefined');
}
catch (error)
{
OS.cocoonJSApp = false;
}
}
if (window.ejecta !== undefined)
{
OS.ejecta = true;
}
if ((/Crosswalk/).test(ua))
{
OS.crosswalk = true;
}
OS.iPhone = ua.toLowerCase().indexOf('iphone') !== -1;
OS.iPad = ua.toLowerCase().indexOf('ipad') !== -1;
OS.pixelRatio = window['devicePixelRatio'] || 1;
return OS;
}
module.exports = init();