|
1 | 1 | import { window, document } from 'ssr-window'; |
2 | 2 |
|
3 | 3 | const Device = (function Device() { |
| 4 | + const platform = window.navigator.platform; |
4 | 5 | const ua = window.navigator.userAgent; |
5 | 6 |
|
6 | 7 | const device = { |
7 | 8 | ios: false, |
8 | 9 | android: false, |
9 | 10 | androidChrome: false, |
10 | 11 | desktop: false, |
11 | | - windows: false, |
| 12 | + windowsPhone: false, |
12 | 13 | iphone: false, |
13 | 14 | iphoneX: false, |
14 | 15 | ipod: false, |
15 | 16 | ipad: false, |
16 | | - cordova: window.cordova || window.phonegap, |
17 | | - phonegap: window.cordova || window.phonegap, |
| 17 | + edge: false, |
| 18 | + ie: false, |
| 19 | + macos: false, |
| 20 | + windows: false, |
| 21 | + cordova: !!(window.cordova || window.phonegap), |
| 22 | + phonegap: !!(window.cordova || window.phonegap), |
18 | 23 | }; |
19 | 24 |
|
20 | | - const windows = ua.match(/(Windows Phone);?[\s\/]+([\d.]+)?/); // eslint-disable-line |
| 25 | + const windowsPhone = ua.match(/(Windows Phone);?[\s\/]+([\d.]+)?/); // eslint-disable-line |
21 | 26 | const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line |
22 | 27 | const ipad = ua.match(/(iPad).*OS\s([\d_]+)/); |
23 | 28 | const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); |
24 | 29 | const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/); |
25 | 30 | const iphoneX = iphone && window.screen.width === 375 && window.screen.height === 812; |
| 31 | + const ie = ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0; |
| 32 | + const edge = ua.indexOf('Edge/') >= 0; |
| 33 | + const macos = platform === 'MacIntel'; |
| 34 | + const windows = platform === 'Win32'; |
26 | 35 |
|
| 36 | + device.ie = ie; |
| 37 | + device.edge = edge; |
27 | 38 |
|
28 | 39 | // Windows |
29 | | - if (windows) { |
| 40 | + if (windowsPhone) { |
30 | 41 | device.os = 'windows'; |
31 | 42 | device.osVersion = windows[2]; |
32 | | - device.windows = true; |
| 43 | + device.windowsPhone = true; |
33 | 44 | } |
34 | 45 | // Android |
35 | 46 | if (android && !windows) { |
@@ -70,6 +81,10 @@ const Device = (function Device() { |
70 | 81 |
|
71 | 82 | // Desktop |
72 | 83 | device.desktop = !(device.os || device.android || device.webView); |
| 84 | + if (device.desktop) { |
| 85 | + device.macos = macos; |
| 86 | + device.windows = windows; |
| 87 | + } |
73 | 88 |
|
74 | 89 | // Minimal UI |
75 | 90 | if (device.os && device.os === 'ios') { |
|
0 commit comments