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 */
97import './.internal/ua-parser.js' ;
108
@@ -15,19 +13,21 @@ declare global {
1513}
1614
1715interface 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 ( / .* A p p l e W e b K i t (? ! .* S a f a r i ) / i) ;
8596
0 commit comments