Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 084b334

Browse files
committed
Improve detection of manufacturers and products.
Adds Huawei, Lenovo, Oppo and Xiaomi as manufacturers as well.
1 parent dd9d7c1 commit 084b334

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

platform.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,17 @@
451451
'Google': { 'Google TV': 1, 'Nexus': 1 },
452452
'HP': { 'TouchPad': 1 },
453453
'HTC': {},
454+
'Huawei': {},
455+
'Lenovo': {},
454456
'LG': {},
455457
'Microsoft': { 'Xbox': 1, 'Xbox One': 1 },
456458
'Motorola': { 'Xoom': 1 },
457459
'Nintendo': { 'Wii U': 1, 'Wii': 1 },
458460
'Nokia': { 'Lumia': 1 },
461+
'Oppo': {},
459462
'Samsung': { 'Galaxy S': 1, 'Galaxy S2': 1, 'Galaxy S3': 1, 'Galaxy S4': 1 },
460-
'Sony': { 'PlayStation': 1, 'PlayStation Vita': 1 }
463+
'Sony': { 'PlayStation': 1, 'PlayStation Vita': 1 },
464+
'Xiaomi': { 'Mi': 1, 'Redmi': 1 }
461465
});
462466

463467
/* Detectable operating systems (order is important). */
@@ -624,18 +628,6 @@
624628
// Convert layout to an array so we can add extra details.
625629
layout && (layout = [layout]);
626630

627-
// Detect product names that contain their manufacturer's name.
628-
if (manufacturer && !product) {
629-
product = getProduct([manufacturer]);
630-
}
631-
// Clean up Google TV.
632-
if ((data = /\bGoogle TV\b/.exec(product))) {
633-
product = data[0];
634-
}
635-
// Detect simulators.
636-
if (/\bSimulator\b/i.test(ua)) {
637-
product = (product ? product + ' ' : '') + 'Simulator';
638-
}
639631
// Detect Android products.
640632
// Browsers on Android devices typically provide their product IDS after "Android;"
641633
// up to "Build" or ") AppleWebKit".
@@ -649,6 +641,22 @@
649641
.replace(/^[a-z]{2}-[a-z]{2};\s*/i, '')
650642
|| null;
651643
}
644+
// Detect product names that contain their manufacturer's name.
645+
if (manufacturer && !product) {
646+
product = getProduct([manufacturer]);
647+
} else if (manufacturer && product) {
648+
product = product
649+
.replace(RegExp('^(' + qualify(manufacturer) + ')[-_.\\s]', 'i'), manufacturer + ' ')
650+
.replace(RegExp('^(' + qualify(manufacturer) + ')[-_.]?(\\w)', 'i'), manufacturer + ' $2');
651+
}
652+
// Clean up Google TV.
653+
if ((data = /\bGoogle TV\b/.exec(product))) {
654+
product = data[0];
655+
}
656+
// Detect simulators.
657+
if (/\bSimulator\b/i.test(ua)) {
658+
product = (product ? product + ' ' : '') + 'Simulator';
659+
}
652660
// Detect Opera Mini 8+ running in Turbo/Uncompressed mode on iOS.
653661
if (name == 'Opera Mini' && /\bOPiOS\b/.test(ua)) {
654662
description.push('running in Turbo/Uncompressed mode');

test/test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,13 @@
166166
'os': 'Android'
167167
},
168168

169-
'Android Browser 4.0 (like Chrome 33.0.0.0) on HUAWEI H891L (Android 4.4.4)': {
169+
'Android Browser 4.0 (like Chrome 33.0.0.0) on Huawei H891L (Android 4.4.4)': {
170170
'ua': 'Mozilla/5.0 (Linux; Android 4.4.4; HUAWEI H891L Build/HuaweiH891L) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36',
171171
'layout': 'Blink',
172+
'manufacturer': 'Huawei',
172173
'name': 'Android Browser',
173174
'os': 'Android 4.4.4',
174-
'product': 'HUAWEI H891L',
175+
'product': 'Huawei H891L',
175176
'version': '4.0'
176177
},
177178

@@ -598,13 +599,13 @@
598599
'version': '63.0.3239.132'
599600
},
600601

601-
'Chrome Mobile 16.0.912.77 on HTC (Android 4.0.3)': {
602+
'Chrome Mobile 16.0.912.77 on HTC Sensation XE with Beats Audio (Android 4.0.3)': {
602603
'ua': 'Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; HTC Sensation XE with Beats Audio Build/IML74K) AppleWebKit/535.7 (KHTML, like Gecko) CrMo/16.0.912.77 Mobile Safari/535.7',
603604
'layout': 'WebKit',
604605
'manufacturer': 'HTC',
605606
'name': 'Chrome Mobile',
606607
'os': 'Android 4.0.3',
607-
'product': 'HTC',
608+
'product': 'HTC Sensation XE with Beats Audio',
608609
'version': '16.0.912.77'
609610
},
610611

0 commit comments

Comments
 (0)