Skip to content

Commit 7344264

Browse files
authored
Update capacitor and browser compat check (#4359)
* Update capacitor and browser compat check * Remove commands * Use native capacitor api
1 parent 80e5770 commit 7344264

File tree

8 files changed

+197
-163
lines changed

8 files changed

+197
-163
lines changed

.gitattributes

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
10+
# Binary files should be left untouched
11+
*.jar binary
12+
113
LICENSE text eol=lf
214
*.md text eol=lf
315
*.c text eol=lf

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ test-results-junit/
3737

3838
# Capacitor config file, we generate it at runtime
3939
capacitor.config.json
40+
41+
# Ignore Gradle project-specific cache directory
42+
.gradle
43+
44+
# Ignore Gradle build output directory
45+
build

android/app/capacitor.build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
android {
44
compileOptions {
5-
sourceCompatibility JavaVersion.VERSION_17
6-
targetCompatibility JavaVersion.VERSION_17
5+
sourceCompatibility JavaVersion.VERSION_21
6+
targetCompatibility JavaVersion.VERSION_21
77
}
88
}
99

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
mavenCentral()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:8.4.0'
10+
classpath 'com.android.tools.build:gradle:8.8.1'
1111
classpath 'com.google.gms:google-services:4.4.0'
1212

1313
// NOTE: Do not place your application dependencies here; they belong

android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"android:dev": "node capacitor.config.generator.mjs --dev && npx cap run android",
1818
"android:open": "vite build && node capacitor.config.generator.mjs && npx cap open android",
1919
"android:run": "vite build && node capacitor.config.generator.mjs && npx cap run android",
20+
"android:sync": "vite build && node capacitor.config.generator.mjs && npx cap sync android",
21+
"android:release": "vite build && node capacitor.config.generator.mjs && npx cap build android --release",
2022
"format": "prettier --write {src,test}/**/*.{js,vue,css,less}",
2123
"storybook": "start-storybook -p 6006",
2224
"prepare": "husky install"
@@ -38,8 +40,8 @@
3840
"node": "20.x"
3941
},
4042
"dependencies": {
41-
"@capacitor/android": "^6.0.0",
42-
"@capacitor/core": "^6.0.0",
43+
"@capacitor/android": "^7.0.1",
44+
"@capacitor/core": "^7.0.1",
4345
"@fortawesome/fontawesome-free": "^6.5.2",
4446
"@vitejs/plugin-vue": "^5.1.4",
4547
"crypto-es": "^2.1.0",
@@ -72,7 +74,7 @@
7274
},
7375
"devDependencies": {
7476
"@babel/core": "^7.24.4",
75-
"@capacitor/cli": "^6.0.0",
77+
"@capacitor/cli": "^7.0.1",
7678
"@quanle94/innosetup": "^6.0.2",
7779
"@rollup/plugin-alias": "^4.0.2",
7880
"@rollup/plugin-commonjs": "^24.0.0",

src/js/utils/checkBrowserCompatibilty.js

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Capacitor } from "@capacitor/core";
2+
13
export function isChromium() {
24
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
35
if (!navigator.userAgentData) {
@@ -12,10 +14,45 @@ export function isChromium() {
1214
});
1315
}
1416

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+
1540
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);
1754

18-
if (isChromium() && compatible) {
55+
if (compatible) {
1956
return true;
2057
}
2158

@@ -24,7 +61,7 @@ export function checkBrowserCompatibility() {
2461
errorMessage = "Betaflight app requires a Chromium based browser (Chrome, Chromium, Edge).";
2562
}
2663

27-
if (!compatible) {
64+
if (!webSerial) {
2865
errorMessage += " Web Serial API support is disabled.";
2966
}
3067

0 commit comments

Comments
 (0)