1
+ import { Capacitor } from "@capacitor/core" ;
2
+
1
3
export function isChromium ( ) {
2
4
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
3
5
if ( ! navigator . userAgentData ) {
@@ -12,10 +14,45 @@ export function isChromium() {
12
14
} ) ;
13
15
}
14
16
17
+ export function isAndroid ( ) {
18
+ if ( Capacitor . isNativePlatform ( ) ) {
19
+ return Capacitor . getPlatform ( ) === "android" ;
20
+ }
21
+ return false ;
22
+ }
23
+
24
+ export function isIOS ( ) {
25
+ if ( Capacitor . isNativePlatform ( ) ) {
26
+ return Capacitor . getPlatform ( ) === "ios" ;
27
+ }
28
+ return false ;
29
+ }
30
+
31
+ export function isWeb ( ) {
32
+ if ( Capacitor . isNativePlatform ( ) ) {
33
+ return Capacitor . getPlatform ( ) === "web" ;
34
+ }
35
+ if ( navigator . userAgentData ) {
36
+ return [ "Linux" , "Mac" , "Windows" ] . includes ( navigator . userAgentData . platform ) ;
37
+ }
38
+ }
39
+
15
40
export function checkBrowserCompatibility ( ) {
16
- const compatible = "serial" in navigator ;
41
+ const androidDevice = isAndroid ( ) ;
42
+ const iosDevice = isIOS ( ) ;
43
+ const web = isWeb ( ) ;
44
+ const webSerial = "serial" in navigator ;
45
+ const isNative = Capacitor . isNativePlatform ( ) ;
46
+
47
+ const compatible = isNative || ( web && webSerial && isChromium ( ) ) ;
48
+
49
+ console . log ( "Android: " , androidDevice ) ;
50
+ console . log ( "iOS: " , iosDevice ) ;
51
+ console . log ( "Web: " , web ) ;
52
+ console . log ( "Web Serial: " , webSerial ) ;
53
+ console . log ( "Native: " , isNative ) ;
17
54
18
- if ( isChromium ( ) && compatible ) {
55
+ if ( compatible ) {
19
56
return true ;
20
57
}
21
58
@@ -24,7 +61,7 @@ export function checkBrowserCompatibility() {
24
61
errorMessage = "Betaflight app requires a Chromium based browser (Chrome, Chromium, Edge)." ;
25
62
}
26
63
27
- if ( ! compatible ) {
64
+ if ( ! webSerial ) {
28
65
errorMessage += " Web Serial API support is disabled." ;
29
66
}
30
67
0 commit comments