Skip to content

Commit ba420bf

Browse files
committed
Core: Device - detect IE/Edge/Windows/MacOS
1 parent 9bd1d77 commit ba420bf

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/core/utils/device.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
import { window, document } from 'ssr-window';
22

33
const Device = (function Device() {
4+
const platform = window.navigator.platform;
45
const ua = window.navigator.userAgent;
56

67
const device = {
78
ios: false,
89
android: false,
910
androidChrome: false,
1011
desktop: false,
11-
windows: false,
12+
windowsPhone: false,
1213
iphone: false,
1314
iphoneX: false,
1415
ipod: false,
1516
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),
1823
};
1924

20-
const windows = ua.match(/(Windows Phone);?[\s\/]+([\d.]+)?/); // eslint-disable-line
25+
const windowsPhone = ua.match(/(Windows Phone);?[\s\/]+([\d.]+)?/); // eslint-disable-line
2126
const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line
2227
const ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
2328
const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
2429
const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
2530
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';
2635

36+
device.ie = ie;
37+
device.edge = edge;
2738

2839
// Windows
29-
if (windows) {
40+
if (windowsPhone) {
3041
device.os = 'windows';
3142
device.osVersion = windows[2];
32-
device.windows = true;
43+
device.windowsPhone = true;
3344
}
3445
// Android
3546
if (android && !windows) {
@@ -70,6 +81,10 @@ const Device = (function Device() {
7081

7182
// Desktop
7283
device.desktop = !(device.os || device.android || device.webView);
84+
if (device.desktop) {
85+
device.macos = macos;
86+
device.windows = windows;
87+
}
7388

7489
// Minimal UI
7590
if (device.os && device.os === 'ios') {

0 commit comments

Comments
 (0)