Skip to content

Commit cee6fe3

Browse files
committed
refactor: 💡 getDevice 增加针对鸿蒙的判断
1 parent 5ef57b4 commit cee6fe3

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/getDevice.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
* @Author: liwb lwbhtml@163.com
33
* @Date: 2025-04-01 13:07:17
44
* @LastEditors: liwb lwbhtml@163.com
5-
* @LastEditTime: 2025-04-01 13:12:55
6-
* @FilePath: /cloud-utils-rslib/src/getDevice.ts
7-
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
5+
* @LastEditTime: 2025-06-10 13:12:55
86
*/
97
import './.internal/ua-parser.js';
108

@@ -15,19 +13,21 @@ declare global {
1513
}
1614

1715
interface DeviceInfo {
16+
isLightOS: boolean;
17+
hms: boolean;
1818
android: boolean;
1919
iphone: boolean;
2020
ipad: boolean;
2121
result: any; // UAParser result type
2222
osVersion: string;
23-
os?: 'android' | 'ios';
23+
os?: 'android' | 'ios' | 'HarmonyOS';
2424
androidChrome?: boolean;
2525
ios?: boolean;
2626
webView: boolean | null;
2727
}
2828

2929
/**
30-
* 获取移动设备信息,如是否是iOS,android等
30+
* 获取移动设备信息,如是否是iOS,android、hms、isLightOS等
3131
*
3232
* @returns {DeviceInfo} 设备信息对象
3333
* @example
@@ -56,6 +56,8 @@ export function getDevice(): DeviceInfo {
5656
android: false,
5757
iphone: false,
5858
ipad: false,
59+
hms: false,
60+
isLightOS: false,
5961
result,
6062
osVersion: os.version,
6163
webView: null
@@ -65,10 +67,14 @@ export function getDevice(): DeviceInfo {
6567
const ipad = deviceInfo.model === 'iPad';
6668
const ipod = deviceInfo.model === 'iPod';
6769
const iphone = deviceInfo.model === 'iPhone';
70+
const hms = ua.toLowerCase().indexOf('arkweb') !== -1;
71+
const isLightOS = ua.toLowerCase().indexOf('lightos') !== -1;
6872

6973
device.android = android;
7074
device.iphone = iphone;
7175
device.ipad = ipad;
76+
device.hms = hms;
77+
device.isLightOS = isLightOS;
7278

7379
// Android
7480
if (android) {
@@ -80,6 +86,11 @@ export function getDevice(): DeviceInfo {
8086
device.ios = true;
8187
}
8288

89+
// HarmonyOS
90+
if (hms) {
91+
device.os = 'HarmonyOS';
92+
}
93+
8394
// Webview
8495
device.webView = (iphone || ipad || ipod) && ua.match(/.*AppleWebKit(?!.*Safari)/i);
8596

0 commit comments

Comments
 (0)