forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_detect.js
More file actions
72 lines (66 loc) · 1.75 KB
/
os_detect.js
File metadata and controls
72 lines (66 loc) · 1.75 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
const localize = require('./localize').localize;
const systems = {
mac : ['Mac68K', 'MacIntel', 'MacPPC'],
linux: [
'HP-UX',
'Linux i686',
'Linux amd64',
'Linux i686 on x86_64',
'Linux i686 X11',
'Linux x86_64',
'Linux x86_64 X11',
'FreeBSD',
'FreeBSD i386',
'FreeBSD amd64',
'X11',
],
ios: [
'iPhone',
'iPod',
'iPad',
'iPhone Simulator',
'iPod Simulator',
'iPad Simulator',
],
android: [
'Android',
'Linux armv7l', // Samsung galaxy s2 ~ s5, nexus 4/5
'Linux armv8l',
null,
],
windows: [
'Win16',
'Win32',
'Win64',
'WinCE',
],
};
const isDesktop = () => {
const os = OSDetect();
return !!['windows', 'mac', 'linux'].find(system => system === os);
};
const isMobile = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
const OSDetect = () => {
// For testing purposes or more compatibility, if we set 'config.os'
// inside our localStorage, we ignore fetching information from
// navigator object and return what we have straight away.
if (localStorage.getItem('config.os')) {
return localStorage.getItem('config.os');
}
if (typeof navigator !== 'undefined' && navigator.platform) {
return Object.keys(systems)
.map(os => {
if (systems[os].some(platform => navigator.platform === platform)) {
return os;
}
return false;
})
.filter(os => os)[0];
}
return localize('Unknown OS');
};
module.exports = {
OSDetect,
isDesktop,
isMobile,
};