Compare commits
5 Commits
android-ma
...
b581e310ed
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b581e310ed | ||
|
|
c579544351 | ||
|
|
aa08a75aef | ||
|
|
6187976b6b | ||
|
|
59e9203363 |
6
.gitignore
vendored
@@ -25,6 +25,12 @@ vite.config.ts.timestamp-*
|
||||
/src-tauri/target/
|
||||
/src-tauri/target-codex-check*/
|
||||
/src-tauri/gen/schemas/
|
||||
/src-tauri/gen/android/app/build/
|
||||
/src-tauri/gen/android/buildSrc/build/
|
||||
/src-tauri/gen/android/.gradle/
|
||||
/src-tauri/gen/android/app/.gradle/
|
||||
/src-tauri/gen/android/buildSrc/.gradle/
|
||||
/src-tauri/gen/android/build/reports/
|
||||
|
||||
/src-tauri/program.log*
|
||||
/src-tauri/recording_replay_debug_*.csv
|
||||
|
||||
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "eskin-finger-sdk"]
|
||||
path = eskin-finger-sdk
|
||||
url = https://gitea.e-skin.top/yanjie/eskin-finger-sdk.git
|
||||
52
README.md
@@ -1,11 +1,10 @@
|
||||
# JE-Skin (SvelteKit + Tauri)
|
||||
# Tauri Demo (SvelteKit + TypeScript)
|
||||
|
||||
## 环境要求
|
||||
|
||||
- Node.js 18+(建议 LTS)
|
||||
- Rust stable(`rustup` + `cargo`)
|
||||
- Windows 下请确保已安装 WebView2 Runtime 和 MSVC C++ 构建工具
|
||||
- Android 构建需要 Android SDK + NDK
|
||||
|
||||
## 安装依赖
|
||||
|
||||
@@ -43,61 +42,12 @@ npm run build
|
||||
npm run tauri build
|
||||
```
|
||||
|
||||
构建 Android APK / AAB:
|
||||
|
||||
```sh
|
||||
npx tauri android build
|
||||
```
|
||||
|
||||
产物路径:
|
||||
- APK: `src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk`
|
||||
- AAB: `src-tauri/gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab`
|
||||
|
||||
Release APK 默认使用 debug keystore 签名(`src-tauri/gen/android/app/je-skin-debug.keystore`),可直接 `adb install` 到设备。
|
||||
|
||||
## 代码检查
|
||||
|
||||
```sh
|
||||
npm run check
|
||||
```
|
||||
|
||||
## v0.5.0 修改记录
|
||||
|
||||
### Android USB 串口接入
|
||||
|
||||
- **Tauri 插件注册**:Android 端通过 Rust builder 注册 `usb-serial` 插件,移除 `MainActivity` 中的手动加载逻辑
|
||||
- **USB 设备枚举**:使用 `usb-serial-for-android` 的 `UsbSerialProber` 识别串口设备,并返回设备名、厂商 ID、产品 ID、权限状态等信息
|
||||
- **USB 权限申请**:完善 Android USB 授权回调,支持按设备名、vendorId/productId 解析设备并处理授权后的打开流程
|
||||
- **串口数据桥接**:Kotlin 端打开 USB serial port 后通过 Unix socketpair 将 fd 交给 Rust,Rust 端继续复用 `serial_connect_fd` 数据采集链路
|
||||
- **资源释放**:关闭连接时同步释放桥接 fd、USB serial port 和 `UsbDeviceConnection`,避免重复打开后的资源残留
|
||||
|
||||
### Tauri 权限与构建
|
||||
|
||||
- 新增 `src-tauri/permissions/usb-serial/default.toml`,声明 Android USB serial 插件命令和前端所需本地命令权限
|
||||
- `default.json` 增加 USB serial 与本地命令权限,兼容 snake_case / camelCase 插件命令名
|
||||
- Android Gradle 仓库加入 JitPack,用于解析 USB serial 驱动依赖
|
||||
- ProGuard 增加 Tauri 插件注解、`UsbSerialPlugin` 和 `com.hoho.android.usbserial` 保留规则,避免 release 包混淆后插件命令失效
|
||||
- Android 构建下 `serial_enum` 返回空列表,并仅保留 fd 连接入口,避免桌面串口枚举依赖进入 Android 编译路径
|
||||
|
||||
## v0.4.0 修改记录
|
||||
|
||||
### 移动端性能优化
|
||||
|
||||
- **SignalChart / SummaryCurve**:在 `@media (max-width: 900px)` 下移除 SVG 路径上的 `filter: drop-shadow()`,避免移动端 GPU 软件回流导致卡顿
|
||||
- **SignalChart**:隐藏 `.scan-haze`(`mix-blend-mode: screen` 合成开销大),简化面板 `background` / `box-shadow`
|
||||
- **SummaryCurve**:移动端移除 `.summary-line` 和 `.summary-dot` 的 drop-shadow 滤镜
|
||||
- **页面级**:移动端隐藏 `.hud-noise`(`feTurbulence` SVG 滤镜是最大性能杀手),降低 `.hud-vignette` 透明度,简化 `.hud-gradient`
|
||||
- 移除 inactive 面板的 `filter: blur()` 过渡动画
|
||||
- 移除 transition 中的 `filter` 属性,添加 `will-change: d` 优化路径更新
|
||||
|
||||
### 移动端 UI 调整
|
||||
|
||||
- **隐藏三大金刚**:`@media (max-width: 900px)` 下隐藏标题栏右侧的最小化/最大化/关闭按钮(Android 系统自带窗口管理)
|
||||
|
||||
### Android 打包
|
||||
|
||||
- Release 构建配置使用 debug keystore 签名,输出签名 APK 而非 unsigned
|
||||
|
||||
## 推荐 IDE 插件
|
||||
|
||||
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||
|
||||
1
eskin-finger-sdk
Submodule
56
package-lock.json
generated
@@ -6,7 +6,7 @@
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "JE-Skin",
|
||||
"version": "0.4.0",
|
||||
"version": "0.3.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2",
|
||||
@@ -625,6 +625,9 @@
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -639,6 +642,9 @@
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -653,6 +659,9 @@
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -667,6 +676,9 @@
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -681,6 +693,9 @@
|
||||
"loong64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -695,6 +710,9 @@
|
||||
"loong64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -709,6 +727,9 @@
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -723,6 +744,9 @@
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -737,6 +761,9 @@
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -751,6 +778,9 @@
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -765,6 +795,9 @@
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -779,6 +812,9 @@
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -793,6 +829,9 @@
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1091,6 +1130,9 @@
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1108,6 +1150,9 @@
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1125,6 +1170,9 @@
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1142,6 +1190,9 @@
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1159,6 +1210,9 @@
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
|
||||
11
src-tauri/.gitignore
vendored
@@ -7,14 +7,3 @@
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
*log*
|
||||
|
||||
# Android build artifacts
|
||||
/gen/android/app/build/
|
||||
/gen/android/build/
|
||||
/gen/android/.gradle/
|
||||
/gen/android/.tauri/
|
||||
/gen/android/local.properties
|
||||
/gen/android/key.properties
|
||||
/gen/android/keystore.properties
|
||||
/gen/android/tauri.settings.gradle
|
||||
/gen/android/app/src/main/jniLibs/
|
||||
|
||||
1
src-tauri/Cargo.lock
generated
@@ -17,7 +17,6 @@ dependencies = [
|
||||
"fern",
|
||||
"futures-util",
|
||||
"humantime",
|
||||
"libc",
|
||||
"log",
|
||||
"ndarray",
|
||||
"prost",
|
||||
|
||||
@@ -15,7 +15,7 @@ name = "tauri_demo_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["multi-dim"]
|
||||
devkit = ["dep:tonic", "dep:prost", "dep:prost-types", "dep:async-stream", "dep:dirs"]
|
||||
multi-dim = ["dep:ndarray"]
|
||||
|
||||
@@ -53,8 +53,6 @@ uuid = { version = "1", features = ["v4", "serde"] }
|
||||
rand = "0.8"
|
||||
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
|
||||
ndarray = { version = "0.15", optional = true }
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-updater = "2"
|
||||
|
||||
@@ -12,12 +12,6 @@
|
||||
"core:window:allow-start-dragging",
|
||||
"opener:default",
|
||||
"process:default",
|
||||
"allow-usb-serial-list",
|
||||
"allow-usb-serial-open",
|
||||
"allow-usb-serial-close",
|
||||
"allow-usb-serial-list-camel",
|
||||
"allow-usb-serial-open-camel",
|
||||
"allow-usb-serial-close-camel",
|
||||
"allow-local-commands"
|
||||
"updater:default"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = false
|
||||
insert_final_newline = false
|
||||
20
src-tauri/gen/android/.gitignore
vendored
@@ -1,20 +0,0 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
key.properties
|
||||
keystore.properties
|
||||
|
||||
/.tauri
|
||||
/tauri.settings.gradle
|
||||
6
src-tauri/gen/android/app/.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
/src/main/**/generated
|
||||
/src/main/jniLibs/**/*.so
|
||||
/src/main/assets/tauri.conf.json
|
||||
/tauri.build.gradle.kts
|
||||
/proguard-tauri.pro
|
||||
/tauri.properties
|
||||
@@ -1,73 +0,0 @@
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("rust")
|
||||
}
|
||||
|
||||
val tauriProperties = Properties().apply {
|
||||
val propFile = file("tauri.properties")
|
||||
if (propFile.exists()) {
|
||||
propFile.inputStream().use { load(it) }
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk = 36
|
||||
namespace = "com.lenn.tauri_serial"
|
||||
defaultConfig {
|
||||
manifestPlaceholders["usesCleartextTraffic"] = "false"
|
||||
applicationId = "com.lenn.tauri_serial"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt()
|
||||
versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0")
|
||||
}
|
||||
buildTypes {
|
||||
getByName("debug") {
|
||||
manifestPlaceholders["usesCleartextTraffic"] = "true"
|
||||
isDebuggable = true
|
||||
isJniDebuggable = true
|
||||
isMinifyEnabled = false
|
||||
packaging { jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so")
|
||||
jniLibs.keepDebugSymbols.add("*/armeabi-v7a/*.so")
|
||||
jniLibs.keepDebugSymbols.add("*/x86/*.so")
|
||||
jniLibs.keepDebugSymbols.add("*/x86_64/*.so")
|
||||
}
|
||||
}
|
||||
getByName("release") {
|
||||
isMinifyEnabled = true
|
||||
proguardFiles(
|
||||
*fileTree(".") { include("**/*.pro") }
|
||||
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
|
||||
.toList().toTypedArray()
|
||||
)
|
||||
signingConfig = signingConfigs.getByName("debug")
|
||||
}
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
buildFeatures {
|
||||
buildConfig = true
|
||||
}
|
||||
}
|
||||
|
||||
rust {
|
||||
rootDirRel = "../../../"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.webkit:webkit:1.14.0")
|
||||
implementation("androidx.appcompat:appcompat:1.7.1")
|
||||
implementation("androidx.activity:activity-ktx:1.10.1")
|
||||
implementation("com.google.android.material:material:1.12.0")
|
||||
implementation("androidx.lifecycle:lifecycle-process:2.10.0")
|
||||
implementation("com.github.mik3y:usb-serial-for-android:3.9.0")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.4")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
|
||||
}
|
||||
|
||||
apply(from = "tauri.build.gradle.kts")
|
||||
34
src-tauri/gen/android/app/proguard-rules.pro
vendored
@@ -1,34 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keepattributes RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,*Annotation*,Signature,InnerClasses,EnclosingMethod
|
||||
|
||||
-keep class app.tauri.annotation.** { *; }
|
||||
-keep class app.tauri.plugin.** { *; }
|
||||
|
||||
-keep class com.lenn.tauri_serial.MainActivity { *; }
|
||||
-keep class com.lenn.tauri_serial.UsbSerialPlugin { *; }
|
||||
-keepclassmembers class com.lenn.tauri_serial.UsbSerialPlugin {
|
||||
public *;
|
||||
}
|
||||
|
||||
-keep class com.hoho.android.usbserial.** { *; }
|
||||
5
src-tauri/gen/android/app/proguard-tauri.pro
Normal file
@@ -0,0 +1,5 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
|
||||
-keep class com.lenn.tauri_serial.TauriActivity {
|
||||
public app.tauri.plugin.PluginManager getPluginManager();
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<!-- USB Host support for serial devices -->
|
||||
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
|
||||
|
||||
<!-- AndroidTV support -->
|
||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||
|
||||
<application
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.je_skin"
|
||||
android:usesCleartextTraffic="${usesCleartextTraffic}">
|
||||
<activity
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
|
||||
android:launchMode="singleTask"
|
||||
android:label="@string/main_activity_title"
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<!-- AndroidTV support -->
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
<!-- Auto-launch when USB device is attached -->
|
||||
<intent-filter>
|
||||
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
|
||||
android:resource="@xml/usb_device_filter" />
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1 @@
|
||||
{"$schema":"https://schema.tauri.app/config/2","productName":"JE-Skin","version":"0.4.0","identifier":"com.lenn.tauri-serial","app":{"windows":[{"label":"main","create":true,"url":"index.html","dragDropEnabled":true,"center":false,"width":1366.0,"height":860.0,"resizable":true,"maximizable":true,"minimizable":true,"closable":true,"title":"JE-Skin","fullscreen":false,"focus":true,"focusable":true,"transparent":false,"maximized":false,"visible":true,"decorations":false,"alwaysOnBottom":false,"alwaysOnTop":false,"visibleOnAllWorkspaces":false,"contentProtected":false,"skipTaskbar":false,"titleBarStyle":"Visible","hiddenTitle":false,"acceptFirstMouse":false,"shadow":true,"incognito":false,"zoomHotkeysEnabled":false,"browserExtensionsEnabled":false,"useHttpsScheme":false,"javascriptDisabled":false,"allowLinkPreview":true,"disableInputAccessoryView":false,"scrollBarStyle":"default"}],"security":{"freezePrototype":false,"dangerousDisableAssetCspModification":false,"assetProtocol":{"scope":[],"enable":false},"pattern":{"use":"brownfield"},"capabilities":[]},"macOSPrivateApi":false,"withGlobalTauri":false,"enableGTKAppId":false},"build":{"devUrl":"http://localhost:1420/","frontendDist":"../build","beforeDevCommand":"npm run dev","beforeBuildCommand":"npm run build","removeUnusedCommands":false,"additionalWatchFolders":[]},"bundle":{"active":true,"targets":"all","createUpdaterArtifacts":true,"icon":["icons/32x32.png","icons/128x128.png","icons/128x128@2x.png","icons/icon.icns","icons/icon.ico"],"resources":["resources/je-skin-devkit-server.exe"],"useLocalToolsDir":false,"windows":{"digestAlgorithm":null,"certificateThumbprint":null,"timestampUrl":null,"tsp":false,"webviewInstallMode":{"type":"downloadBootstrapper","silent":true},"allowDowngrades":true,"wix":null,"nsis":{"template":"nsis/installer.nsi","headerImage":null,"sidebarImage":null,"installerIcon":"icons/icon.ico","installMode":"both","languages":null,"customLanguageFiles":null,"displayLanguageSelector":false,"compression":"lzma","startMenuFolder":null,"installerHooks":null,"minimumWebview2Version":null},"signCommand":null},"linux":{"appimage":{"bundleMediaFramework":false,"files":{}},"deb":{"files":{}},"rpm":{"release":"1","epoch":0,"files":{}}},"macOS":{"files":{},"minimumSystemVersion":"10.13","hardenedRuntime":true,"dmg":{"windowSize":{"width":660,"height":400},"appPosition":{"x":180,"y":170},"applicationFolderPosition":{"x":480,"y":170}}},"iOS":{"minimumSystemVersion":"14.0"},"android":{"minSdkVersion":24,"autoIncrementVersionCode":false}},"plugins":{}}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
|
||||
class MainActivity : TauriActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
}
|
||||
@@ -1,388 +0,0 @@
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.PendingIntent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbDeviceConnection
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.os.Build
|
||||
import android.os.ParcelFileDescriptor
|
||||
import android.system.Os
|
||||
import android.system.OsConstants
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import app.tauri.plugin.Invoke
|
||||
import app.tauri.plugin.JSObject
|
||||
import app.tauri.plugin.Plugin
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import com.hoho.android.usbserial.driver.UsbSerialPort
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
import java.io.FileDescriptor
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import org.json.JSONArray
|
||||
|
||||
@TauriPlugin
|
||||
class UsbSerialPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
companion object {
|
||||
private const val ACTION_USB_PERMISSION = "com.lenn.tauri_serial.USB_PERMISSION"
|
||||
private const val BAUD_RATE = 921600
|
||||
private const val READ_TIMEOUT_MS = 100
|
||||
private const val WRITE_TIMEOUT_MS = 100
|
||||
}
|
||||
|
||||
private var pendingConnectInvoke: Invoke? = null
|
||||
private var pendingConnectDeviceName: String? = null
|
||||
private var activeBridge: SerialBridge? = null
|
||||
|
||||
private val usbPermissionReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (ACTION_USB_PERMISSION != intent.action) return
|
||||
|
||||
synchronized(this@UsbSerialPlugin) {
|
||||
val device = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
intent.getParcelableExtra(UsbManager.EXTRA_DEVICE, UsbDevice::class.java)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
|
||||
}
|
||||
|
||||
val granted = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)
|
||||
val invoke = pendingConnectInvoke
|
||||
val targetDeviceName = pendingConnectDeviceName
|
||||
|
||||
pendingConnectInvoke = null
|
||||
pendingConnectDeviceName = null
|
||||
|
||||
if (invoke == null || device == null) return
|
||||
|
||||
if (!granted) {
|
||||
invoke.reject("USB permission denied")
|
||||
return
|
||||
}
|
||||
|
||||
if (targetDeviceName != null && device.deviceName == targetDeviceName) {
|
||||
openAndReturn(invoke, device.deviceName)
|
||||
} else {
|
||||
invoke.reject("USB device mismatch")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun load(webView: android.webkit.WebView) {
|
||||
super.load(webView)
|
||||
val filter = IntentFilter(ACTION_USB_PERMISSION)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
activity.applicationContext.registerReceiver(
|
||||
usbPermissionReceiver,
|
||||
filter,
|
||||
Context.RECEIVER_NOT_EXPORTED
|
||||
)
|
||||
} else {
|
||||
activity.applicationContext.registerReceiver(usbPermissionReceiver, filter)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
activeBridge?.close()
|
||||
activeBridge = null
|
||||
try {
|
||||
activity.applicationContext.unregisterReceiver(usbPermissionReceiver)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
fun usb_serial_list(invoke: Invoke) {
|
||||
listDevices(invoke)
|
||||
}
|
||||
|
||||
@Command
|
||||
fun usbSerialList(invoke: Invoke) {
|
||||
listDevices(invoke)
|
||||
}
|
||||
|
||||
private fun listDevices(invoke: Invoke) {
|
||||
val usbManager = activity.getSystemService(Context.USB_SERVICE) as? UsbManager
|
||||
if (usbManager == null) {
|
||||
invoke.reject("USB service not available")
|
||||
return
|
||||
}
|
||||
|
||||
val result = JSObject()
|
||||
val serialDevices = JSONArray()
|
||||
|
||||
for (driver in UsbSerialProber.getDefaultProber().findAllDrivers(usbManager)) {
|
||||
val device = driver.device
|
||||
val obj = JSObject()
|
||||
obj.put("name", device.deviceName)
|
||||
obj.put("vendorId", device.vendorId)
|
||||
obj.put("productId", device.productId)
|
||||
obj.put("manufacturer", safeDeviceString { device.manufacturerName })
|
||||
obj.put("product", safeDeviceString { device.productName })
|
||||
obj.put("serial", safeDeviceString { device.serialNumber })
|
||||
obj.put("hasPermission", usbManager.hasPermission(device))
|
||||
serialDevices.put(obj)
|
||||
}
|
||||
|
||||
result.put("devices", serialDevices)
|
||||
invoke.resolve(result)
|
||||
}
|
||||
|
||||
@Command
|
||||
fun usb_serial_open(invoke: Invoke) {
|
||||
openDevice(invoke)
|
||||
}
|
||||
|
||||
@Command
|
||||
fun usbSerialOpen(invoke: Invoke) {
|
||||
openDevice(invoke)
|
||||
}
|
||||
|
||||
private fun openDevice(invoke: Invoke) {
|
||||
val args = invoke.parseArgs(JSObject::class.java)
|
||||
val deviceName = args.optString("name", "")
|
||||
val vendorId = if (args.has("vendorId")) args.optInt("vendorId") else null
|
||||
val productId = if (args.has("productId")) args.optInt("productId") else null
|
||||
|
||||
val usbManager = activity.getSystemService(Context.USB_SERVICE) as? UsbManager
|
||||
if (usbManager == null) {
|
||||
invoke.reject("USB service not available")
|
||||
return
|
||||
}
|
||||
|
||||
val device = resolveDevice(usbManager, deviceName, vendorId, productId)
|
||||
if (device == null) {
|
||||
val available = usbManager.deviceList.values.joinToString(", ") { it.deviceName }
|
||||
invoke.reject("USB device not found: $deviceName; available: $available")
|
||||
return
|
||||
}
|
||||
|
||||
if (!usbManager.hasPermission(device)) {
|
||||
synchronized(this) {
|
||||
pendingConnectInvoke = invoke
|
||||
pendingConnectDeviceName = device.deviceName
|
||||
}
|
||||
|
||||
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
} else {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
}
|
||||
val permissionRequest = Intent(ACTION_USB_PERMISSION).setPackage(activity.packageName)
|
||||
val permissionIntent = PendingIntent.getBroadcast(
|
||||
activity,
|
||||
0,
|
||||
permissionRequest,
|
||||
flags
|
||||
)
|
||||
usbManager.requestPermission(device, permissionIntent)
|
||||
return
|
||||
}
|
||||
|
||||
openAndReturn(invoke, device.deviceName)
|
||||
}
|
||||
|
||||
@Command
|
||||
fun usb_serial_close(invoke: Invoke) {
|
||||
closeBridge()
|
||||
invoke.resolve(JSObject())
|
||||
}
|
||||
|
||||
@Command
|
||||
fun usbSerialClose(invoke: Invoke) {
|
||||
closeBridge()
|
||||
invoke.resolve(JSObject())
|
||||
}
|
||||
|
||||
private fun closeBridge() {
|
||||
activeBridge?.close()
|
||||
activeBridge = null
|
||||
}
|
||||
|
||||
private fun openAndReturn(invoke: Invoke, deviceName: String) {
|
||||
val usbManager = activity.getSystemService(Context.USB_SERVICE) as? UsbManager
|
||||
if (usbManager == null) {
|
||||
invoke.reject("USB service not available")
|
||||
return
|
||||
}
|
||||
|
||||
val driver = findDriver(usbManager, deviceName)
|
||||
if (driver == null) {
|
||||
invoke.reject("USB serial driver not found: $deviceName")
|
||||
return
|
||||
}
|
||||
|
||||
val connection = usbManager.openDevice(driver.device)
|
||||
if (connection == null) {
|
||||
invoke.reject("Failed to open USB device")
|
||||
return
|
||||
}
|
||||
|
||||
val port = driver.ports.firstOrNull()
|
||||
if (port == null) {
|
||||
connection.close()
|
||||
invoke.reject("No serial port found on USB device")
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
port.open(connection)
|
||||
port.setParameters(
|
||||
BAUD_RATE,
|
||||
UsbSerialPort.DATABITS_8,
|
||||
UsbSerialPort.STOPBITS_1,
|
||||
UsbSerialPort.PARITY_NONE
|
||||
)
|
||||
|
||||
val rustSide = FileDescriptor()
|
||||
val bridgeSide = FileDescriptor()
|
||||
Os.socketpair(OsConstants.AF_UNIX, OsConstants.SOCK_STREAM, 0, rustSide, bridgeSide)
|
||||
val rustFd = ParcelFileDescriptor.dup(rustSide).detachFd()
|
||||
Os.close(rustSide)
|
||||
|
||||
activeBridge?.close()
|
||||
activeBridge = SerialBridge(bridgeSide, port, connection).also { it.start() }
|
||||
|
||||
val result = JSObject()
|
||||
result.put("fd", rustFd)
|
||||
result.put("name", driver.device.deviceName)
|
||||
result.put("vendorId", driver.device.vendorId)
|
||||
result.put("productId", driver.device.productId)
|
||||
invoke.resolve(result)
|
||||
} catch (error: Exception) {
|
||||
try {
|
||||
port.close()
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
connection.close()
|
||||
invoke.reject(error.message ?: "Failed to open USB serial port")
|
||||
}
|
||||
}
|
||||
|
||||
private fun findDriver(usbManager: UsbManager, deviceName: String): UsbSerialDriver? {
|
||||
return UsbSerialProber.getDefaultProber()
|
||||
.findAllDrivers(usbManager)
|
||||
.firstOrNull { it.device.deviceName == deviceName || it.device.deviceName.equals(deviceName, ignoreCase = true) }
|
||||
}
|
||||
|
||||
private fun resolveDevice(
|
||||
usbManager: UsbManager,
|
||||
deviceName: String,
|
||||
vendorId: Int?,
|
||||
productId: Int?
|
||||
): UsbDevice? {
|
||||
usbManager.deviceList[deviceName]?.let { return it }
|
||||
|
||||
val devices = usbManager.deviceList.values.toList()
|
||||
devices.firstOrNull { it.deviceName.equals(deviceName, ignoreCase = true) }?.let { return it }
|
||||
|
||||
if (vendorId != null && productId != null) {
|
||||
devices.firstOrNull { it.vendorId == vendorId && it.productId == productId }?.let { return it }
|
||||
}
|
||||
|
||||
val drivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager)
|
||||
drivers.firstOrNull {
|
||||
it.device.deviceName == deviceName || it.device.deviceName.equals(deviceName, ignoreCase = true)
|
||||
}?.device?.let { return it }
|
||||
|
||||
if (drivers.size == 1) {
|
||||
return drivers.first().device
|
||||
}
|
||||
|
||||
if (devices.size == 1) {
|
||||
return devices.first()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun safeDeviceString(read: () -> String?): String {
|
||||
return try {
|
||||
read() ?: ""
|
||||
} catch (_: SecurityException) {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
private class SerialBridge(
|
||||
private val bridgeFd: FileDescriptor,
|
||||
private val port: UsbSerialPort,
|
||||
private val connection: UsbDeviceConnection
|
||||
) {
|
||||
private val running = AtomicBoolean(false)
|
||||
private lateinit var serialToRustThread: Thread
|
||||
private lateinit var rustToSerialThread: Thread
|
||||
|
||||
fun start() {
|
||||
running.set(true)
|
||||
serialToRustThread = Thread(::copySerialToRust, "JE-Skin-usb-serial-rx")
|
||||
rustToSerialThread = Thread(::copyRustToSerial, "JE-Skin-usb-serial-tx")
|
||||
serialToRustThread.start()
|
||||
rustToSerialThread.start()
|
||||
}
|
||||
|
||||
fun close() {
|
||||
if (!running.getAndSet(false)) return
|
||||
|
||||
try {
|
||||
Os.close(bridgeFd)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
try {
|
||||
port.close()
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
connection.close()
|
||||
}
|
||||
|
||||
private fun copySerialToRust() {
|
||||
val output = FileOutputStream(bridgeFd)
|
||||
val buffer = ByteArray(4096)
|
||||
|
||||
while (running.get()) {
|
||||
try {
|
||||
val count = port.read(buffer, READ_TIMEOUT_MS)
|
||||
if (count > 0) {
|
||||
output.write(buffer, 0, count)
|
||||
output.flush()
|
||||
}
|
||||
} catch (_: IOException) {
|
||||
close()
|
||||
} catch (_: Exception) {
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyRustToSerial() {
|
||||
val input = FileInputStream(bridgeFd)
|
||||
val buffer = ByteArray(4096)
|
||||
|
||||
while (running.get()) {
|
||||
try {
|
||||
val count = input.read(buffer)
|
||||
if (count < 0) {
|
||||
close()
|
||||
return
|
||||
}
|
||||
if (count > 0) {
|
||||
port.write(buffer.copyOf(count), WRITE_TIMEOUT_MS)
|
||||
}
|
||||
} catch (_: IOException) {
|
||||
close()
|
||||
} catch (_: Exception) {
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
@file:Suppress("unused")
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
import android.webkit.*
|
||||
|
||||
class Ipc(val webViewClient: RustWebViewClient) {
|
||||
@JavascriptInterface
|
||||
fun postMessage(message: String?) {
|
||||
message?.let {m ->
|
||||
// we're not using WebView::getUrl() here because it needs to be executed on the main thread
|
||||
// and it would slow down the Ipc
|
||||
// so instead we track the current URL on the webview client
|
||||
this.ipc(webViewClient.currentUrl, m)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("tauri_demo_lib")
|
||||
}
|
||||
}
|
||||
|
||||
private external fun ipc(url: String, message: String)
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
// taken from https://github.com/ionic-team/capacitor/blob/6658bca41e78239347e458175b14ca8bd5c1d6e8/android/capacitor/src/main/java/com/getcapacitor/Logger.java
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
|
||||
class Logger {
|
||||
companion object {
|
||||
private const val LOG_TAG_CORE = "Tauri"
|
||||
|
||||
fun tags(vararg subtags: String): String {
|
||||
return if (subtags.isNotEmpty()) {
|
||||
LOG_TAG_CORE + "/" + TextUtils.join("/", subtags)
|
||||
} else LOG_TAG_CORE
|
||||
}
|
||||
|
||||
fun verbose(message: String) {
|
||||
verbose(LOG_TAG_CORE, message)
|
||||
}
|
||||
|
||||
private fun verbose(tag: String, message: String) {
|
||||
if (!shouldLog()) {
|
||||
return
|
||||
}
|
||||
Log.v(tag, message)
|
||||
}
|
||||
|
||||
fun debug(message: String) {
|
||||
debug(LOG_TAG_CORE, message)
|
||||
}
|
||||
|
||||
fun debug(tag: String, message: String) {
|
||||
if (!shouldLog()) {
|
||||
return
|
||||
}
|
||||
Log.d(tag, message)
|
||||
}
|
||||
|
||||
fun info(message: String) {
|
||||
info(LOG_TAG_CORE, message)
|
||||
}
|
||||
|
||||
fun info(tag: String, message: String) {
|
||||
if (!shouldLog()) {
|
||||
return
|
||||
}
|
||||
Log.i(tag, message)
|
||||
}
|
||||
|
||||
fun warn(message: String) {
|
||||
warn(LOG_TAG_CORE, message)
|
||||
}
|
||||
|
||||
fun warn(tag: String, message: String) {
|
||||
if (!shouldLog()) {
|
||||
return
|
||||
}
|
||||
Log.w(tag, message)
|
||||
}
|
||||
|
||||
fun error(message: String) {
|
||||
error(LOG_TAG_CORE, message, null)
|
||||
}
|
||||
|
||||
fun error(message: String, e: Throwable?) {
|
||||
error(LOG_TAG_CORE, message, e)
|
||||
}
|
||||
|
||||
fun error(tag: String, message: String, e: Throwable?) {
|
||||
if (!shouldLog()) {
|
||||
return
|
||||
}
|
||||
Log.e(tag, message, e)
|
||||
}
|
||||
|
||||
private fun shouldLog(): Boolean {
|
||||
return BuildConfig.DEBUG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
// taken from https://github.com/ionic-team/capacitor/blob/6658bca41e78239347e458175b14ca8bd5c1d6e8/android/capacitor/src/main/java/com/getcapacitor/PermissionHelper.java
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.core.app.ActivityCompat
|
||||
import java.util.ArrayList
|
||||
|
||||
object PermissionHelper {
|
||||
/**
|
||||
* Checks if a list of given permissions are all granted by the user
|
||||
*
|
||||
* @param permissions Permissions to check.
|
||||
* @return True if all permissions are granted, false if at least one is not.
|
||||
*/
|
||||
fun hasPermissions(context: Context?, permissions: Array<String>): Boolean {
|
||||
for (perm in permissions) {
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
context!!,
|
||||
perm
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given permission has been defined in the AndroidManifest.xml
|
||||
*
|
||||
* @param permission A permission to check.
|
||||
* @return True if the permission has been defined in the Manifest, false if not.
|
||||
*/
|
||||
fun hasDefinedPermission(context: Context, permission: String): Boolean {
|
||||
var hasPermission = false
|
||||
val requestedPermissions = getManifestPermissions(context)
|
||||
if (!requestedPermissions.isNullOrEmpty()) {
|
||||
val requestedPermissionsList = listOf(*requestedPermissions)
|
||||
val requestedPermissionsArrayList = ArrayList(requestedPermissionsList)
|
||||
if (requestedPermissionsArrayList.contains(permission)) {
|
||||
hasPermission = true
|
||||
}
|
||||
}
|
||||
return hasPermission
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether all of the given permissions have been defined in the AndroidManifest.xml
|
||||
* @param context the app context
|
||||
* @param permissions a list of permissions
|
||||
* @return true only if all permissions are defined in the AndroidManifest.xml
|
||||
*/
|
||||
fun hasDefinedPermissions(context: Context, permissions: Array<String>): Boolean {
|
||||
for (permission in permissions) {
|
||||
if (!hasDefinedPermission(context, permission)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the permissions defined in AndroidManifest.xml
|
||||
*
|
||||
* @return The permissions defined in AndroidManifest.xml
|
||||
*/
|
||||
private fun getManifestPermissions(context: Context): Array<String>? {
|
||||
var requestedPermissions: Array<String>? = null
|
||||
try {
|
||||
val pm = context.packageManager
|
||||
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
pm.getPackageInfo(context.packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong()))
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
pm.getPackageInfo(context.packageName, PackageManager.GET_PERMISSIONS)
|
||||
}
|
||||
if (packageInfo != null) {
|
||||
requestedPermissions = packageInfo.requestedPermissions
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
return requestedPermissions
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of permissions, return a new list with the ones not present in AndroidManifest.xml
|
||||
*
|
||||
* @param neededPermissions The permissions needed.
|
||||
* @return The permissions not present in AndroidManifest.xml
|
||||
*/
|
||||
fun getUndefinedPermissions(context: Context, neededPermissions: Array<String?>): Array<String?> {
|
||||
val undefinedPermissions = ArrayList<String?>()
|
||||
val requestedPermissions = getManifestPermissions(context)
|
||||
if (!requestedPermissions.isNullOrEmpty()) {
|
||||
val requestedPermissionsList = listOf(*requestedPermissions)
|
||||
val requestedPermissionsArrayList = ArrayList(requestedPermissionsList)
|
||||
for (permission in neededPermissions) {
|
||||
if (!requestedPermissionsArrayList.contains(permission)) {
|
||||
undefinedPermissions.add(permission)
|
||||
}
|
||||
}
|
||||
var undefinedPermissionArray = arrayOfNulls<String>(undefinedPermissions.size)
|
||||
undefinedPermissionArray = undefinedPermissions.toArray(undefinedPermissionArray)
|
||||
return undefinedPermissionArray
|
||||
}
|
||||
return neededPermissions
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,495 @@
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
@file:Suppress("ObsoleteSdkInt", "RedundantOverride", "QueryPermissionsNeeded", "SimpleDateFormat")
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
// taken from https://github.com/ionic-team/capacitor/blob/6658bca41e78239347e458175b14ca8bd5c1d6e8/android/capacitor/src/main/java/com/getcapacitor/BridgeWebChromeClient.java
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.view.View
|
||||
import android.webkit.*
|
||||
import android.widget.EditText
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.ActivityResultCallback
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class RustWebChromeClient(appActivity: WryActivity) : WebChromeClient() {
|
||||
private interface PermissionListener {
|
||||
fun onPermissionSelect(isGranted: Boolean?)
|
||||
}
|
||||
|
||||
private interface ActivityResultListener {
|
||||
fun onActivityResult(result: ActivityResult?)
|
||||
}
|
||||
|
||||
private val activity: WryActivity
|
||||
private var permissionLauncher: ActivityResultLauncher<Array<String>>
|
||||
private var activityLauncher: ActivityResultLauncher<Intent>
|
||||
private var permissionListener: PermissionListener? = null
|
||||
private var activityListener: ActivityResultListener? = null
|
||||
|
||||
init {
|
||||
activity = appActivity
|
||||
val permissionCallback =
|
||||
ActivityResultCallback { isGranted: Map<String, Boolean> ->
|
||||
if (permissionListener != null) {
|
||||
var granted = true
|
||||
for ((_, value) in isGranted) {
|
||||
if (!value) granted = false
|
||||
}
|
||||
permissionListener!!.onPermissionSelect(granted)
|
||||
}
|
||||
}
|
||||
permissionLauncher =
|
||||
activity.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions(), permissionCallback)
|
||||
activityLauncher = activity.registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (activityListener != null) {
|
||||
activityListener!!.onActivityResult(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render web content in `view`.
|
||||
*
|
||||
* Both this method and [.onHideCustomView] are required for
|
||||
* rendering web content in full screen.
|
||||
*
|
||||
* @see [](https://developer.android.com/reference/android/webkit/WebChromeClient.onShowCustomView
|
||||
) */
|
||||
override fun onShowCustomView(view: View, callback: CustomViewCallback) {
|
||||
callback.onCustomViewHidden()
|
||||
super.onShowCustomView(view, callback)
|
||||
}
|
||||
|
||||
/**
|
||||
* Render web content in the original Web View again.
|
||||
*
|
||||
* Do not remove this method--@see #onShowCustomView(View, CustomViewCallback).
|
||||
*/
|
||||
override fun onHideCustomView() {
|
||||
super.onHideCustomView()
|
||||
}
|
||||
|
||||
override fun onPermissionRequest(request: PermissionRequest) {
|
||||
val isRequestPermissionRequired = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
val permissionList: MutableList<String> = ArrayList()
|
||||
if (listOf(*request.resources).contains("android.webkit.resource.VIDEO_CAPTURE")) {
|
||||
permissionList.add(Manifest.permission.CAMERA)
|
||||
}
|
||||
if (listOf(*request.resources).contains("android.webkit.resource.AUDIO_CAPTURE")) {
|
||||
permissionList.add(Manifest.permission.MODIFY_AUDIO_SETTINGS)
|
||||
permissionList.add(Manifest.permission.RECORD_AUDIO)
|
||||
}
|
||||
if (permissionList.isNotEmpty() && isRequestPermissionRequired) {
|
||||
val permissions = permissionList.toTypedArray()
|
||||
permissionListener = object : PermissionListener {
|
||||
override fun onPermissionSelect(isGranted: Boolean?) {
|
||||
if (isGranted == true) {
|
||||
request.grant(request.resources)
|
||||
} else {
|
||||
request.deny()
|
||||
}
|
||||
}
|
||||
}
|
||||
permissionLauncher.launch(permissions)
|
||||
} else {
|
||||
request.grant(request.resources)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the browser alert modal
|
||||
* @param view
|
||||
* @param url
|
||||
* @param message
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
override fun onJsAlert(view: WebView, url: String, message: String, result: JsResult): Boolean {
|
||||
if (activity.isFinishing) {
|
||||
return true
|
||||
}
|
||||
val builder = AlertDialog.Builder(view.context)
|
||||
builder
|
||||
.setMessage(message)
|
||||
.setPositiveButton(
|
||||
"OK"
|
||||
) { dialog: DialogInterface, _: Int ->
|
||||
dialog.dismiss()
|
||||
result.confirm()
|
||||
}
|
||||
.setOnCancelListener { dialog: DialogInterface ->
|
||||
dialog.dismiss()
|
||||
result.cancel()
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the browser confirm modal
|
||||
* @param view
|
||||
* @param url
|
||||
* @param message
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
override fun onJsConfirm(view: WebView, url: String, message: String, result: JsResult): Boolean {
|
||||
if (activity.isFinishing) {
|
||||
return true
|
||||
}
|
||||
val builder = AlertDialog.Builder(view.context)
|
||||
builder
|
||||
.setMessage(message)
|
||||
.setPositiveButton(
|
||||
"OK"
|
||||
) { dialog: DialogInterface, _: Int ->
|
||||
dialog.dismiss()
|
||||
result.confirm()
|
||||
}
|
||||
.setNegativeButton(
|
||||
"Cancel"
|
||||
) { dialog: DialogInterface, _: Int ->
|
||||
dialog.dismiss()
|
||||
result.cancel()
|
||||
}
|
||||
.setOnCancelListener { dialog: DialogInterface ->
|
||||
dialog.dismiss()
|
||||
result.cancel()
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the browser prompt modal
|
||||
* @param view
|
||||
* @param url
|
||||
* @param message
|
||||
* @param defaultValue
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
override fun onJsPrompt(
|
||||
view: WebView,
|
||||
url: String,
|
||||
message: String,
|
||||
defaultValue: String,
|
||||
result: JsPromptResult
|
||||
): Boolean {
|
||||
if (activity.isFinishing) {
|
||||
return true
|
||||
}
|
||||
val builder = AlertDialog.Builder(view.context)
|
||||
val input = EditText(view.context)
|
||||
builder
|
||||
.setMessage(message)
|
||||
.setView(input)
|
||||
.setPositiveButton(
|
||||
"OK"
|
||||
) { dialog: DialogInterface, _: Int ->
|
||||
dialog.dismiss()
|
||||
val inputText1 = input.text.toString().trim { it <= ' ' }
|
||||
result.confirm(inputText1)
|
||||
}
|
||||
.setNegativeButton(
|
||||
"Cancel"
|
||||
) { dialog: DialogInterface, _: Int ->
|
||||
dialog.dismiss()
|
||||
result.cancel()
|
||||
}
|
||||
.setOnCancelListener { dialog: DialogInterface ->
|
||||
dialog.dismiss()
|
||||
result.cancel()
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the browser geolocation permission prompt
|
||||
* @param origin
|
||||
* @param callback
|
||||
*/
|
||||
override fun onGeolocationPermissionsShowPrompt(
|
||||
origin: String,
|
||||
callback: GeolocationPermissions.Callback
|
||||
) {
|
||||
super.onGeolocationPermissionsShowPrompt(origin, callback)
|
||||
Logger.debug("onGeolocationPermissionsShowPrompt: DOING IT HERE FOR ORIGIN: $origin")
|
||||
val geoPermissions =
|
||||
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
if (!PermissionHelper.hasPermissions(activity, geoPermissions)) {
|
||||
permissionListener = object : PermissionListener {
|
||||
override fun onPermissionSelect(isGranted: Boolean?) {
|
||||
if (isGranted == true) {
|
||||
callback.invoke(origin, true, false)
|
||||
} else {
|
||||
val coarsePermission =
|
||||
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
|
||||
PermissionHelper.hasPermissions(activity, coarsePermission)
|
||||
) {
|
||||
callback.invoke(origin, true, false)
|
||||
} else {
|
||||
callback.invoke(origin, false, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
permissionLauncher.launch(geoPermissions)
|
||||
} else {
|
||||
// permission is already granted
|
||||
callback.invoke(origin, true, false)
|
||||
Logger.debug("onGeolocationPermissionsShowPrompt: has required permission")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onShowFileChooser(
|
||||
webView: WebView,
|
||||
filePathCallback: ValueCallback<Array<Uri?>?>,
|
||||
fileChooserParams: FileChooserParams
|
||||
): Boolean {
|
||||
val acceptTypes = listOf(*fileChooserParams.acceptTypes)
|
||||
val captureEnabled = fileChooserParams.isCaptureEnabled
|
||||
val capturePhoto = captureEnabled && acceptTypes.contains("image/*")
|
||||
val captureVideo = captureEnabled && acceptTypes.contains("video/*")
|
||||
if (capturePhoto || captureVideo) {
|
||||
if (isMediaCaptureSupported) {
|
||||
showMediaCaptureOrFilePicker(filePathCallback, fileChooserParams, captureVideo)
|
||||
} else {
|
||||
permissionListener = object : PermissionListener {
|
||||
override fun onPermissionSelect(isGranted: Boolean?) {
|
||||
if (isGranted == true) {
|
||||
showMediaCaptureOrFilePicker(filePathCallback, fileChooserParams, captureVideo)
|
||||
} else {
|
||||
Logger.warn(Logger.tags("FileChooser"), "Camera permission not granted")
|
||||
filePathCallback.onReceiveValue(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
val camPermission = arrayOf(Manifest.permission.CAMERA)
|
||||
permissionLauncher.launch(camPermission)
|
||||
}
|
||||
} else {
|
||||
showFilePicker(filePathCallback, fileChooserParams)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private val isMediaCaptureSupported: Boolean
|
||||
get() {
|
||||
val permissions = arrayOf(Manifest.permission.CAMERA)
|
||||
return PermissionHelper.hasPermissions(activity, permissions) ||
|
||||
!PermissionHelper.hasDefinedPermission(activity, Manifest.permission.CAMERA)
|
||||
}
|
||||
|
||||
private fun showMediaCaptureOrFilePicker(
|
||||
filePathCallback: ValueCallback<Array<Uri?>?>,
|
||||
fileChooserParams: FileChooserParams,
|
||||
isVideo: Boolean
|
||||
) {
|
||||
val isVideoCaptureSupported = true
|
||||
val shown = if (isVideo && isVideoCaptureSupported) {
|
||||
showVideoCapturePicker(filePathCallback)
|
||||
} else {
|
||||
showImageCapturePicker(filePathCallback)
|
||||
}
|
||||
if (!shown) {
|
||||
Logger.warn(
|
||||
Logger.tags("FileChooser"),
|
||||
"Media capture intent could not be launched. Falling back to default file picker."
|
||||
)
|
||||
showFilePicker(filePathCallback, fileChooserParams)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showImageCapturePicker(filePathCallback: ValueCallback<Array<Uri?>?>): Boolean {
|
||||
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
|
||||
if (takePictureIntent.resolveActivity(activity.packageManager) == null) {
|
||||
return false
|
||||
}
|
||||
val imageFileUri: Uri = try {
|
||||
createImageFileUri()
|
||||
} catch (ex: Exception) {
|
||||
Logger.error("Unable to create temporary media capture file: " + ex.message)
|
||||
return false
|
||||
}
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri)
|
||||
activityListener = object : ActivityResultListener {
|
||||
override fun onActivityResult(result: ActivityResult?) {
|
||||
var res: Array<Uri?>? = null
|
||||
if (result?.resultCode == Activity.RESULT_OK) {
|
||||
res = arrayOf(imageFileUri)
|
||||
}
|
||||
filePathCallback.onReceiveValue(res)
|
||||
}
|
||||
}
|
||||
activityLauncher.launch(takePictureIntent)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun showVideoCapturePicker(filePathCallback: ValueCallback<Array<Uri?>?>): Boolean {
|
||||
val takeVideoIntent = Intent(MediaStore.ACTION_VIDEO_CAPTURE)
|
||||
if (takeVideoIntent.resolveActivity(activity.packageManager) == null) {
|
||||
return false
|
||||
}
|
||||
activityListener = object : ActivityResultListener {
|
||||
override fun onActivityResult(result: ActivityResult?) {
|
||||
var res: Array<Uri?>? = null
|
||||
if (result?.resultCode == Activity.RESULT_OK) {
|
||||
res = arrayOf(result.data!!.data)
|
||||
}
|
||||
filePathCallback.onReceiveValue(res)
|
||||
}
|
||||
}
|
||||
activityLauncher.launch(takeVideoIntent)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun showFilePicker(
|
||||
filePathCallback: ValueCallback<Array<Uri?>?>,
|
||||
fileChooserParams: FileChooserParams
|
||||
) {
|
||||
val intent = fileChooserParams.createIntent()
|
||||
if (fileChooserParams.mode == FileChooserParams.MODE_OPEN_MULTIPLE) {
|
||||
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
|
||||
}
|
||||
if (fileChooserParams.acceptTypes.size > 1 || intent.type!!.startsWith(".")) {
|
||||
val validTypes = getValidTypes(fileChooserParams.acceptTypes)
|
||||
intent.putExtra(Intent.EXTRA_MIME_TYPES, validTypes)
|
||||
if (intent.type!!.startsWith(".")) {
|
||||
intent.type = validTypes[0]
|
||||
}
|
||||
}
|
||||
try {
|
||||
activityListener = object : ActivityResultListener {
|
||||
override fun onActivityResult(result: ActivityResult?) {
|
||||
val res: Array<Uri?>?
|
||||
val resultIntent = result?.data
|
||||
if (result?.resultCode == Activity.RESULT_OK && resultIntent!!.clipData != null) {
|
||||
val numFiles = resultIntent.clipData!!.itemCount
|
||||
res = arrayOfNulls(numFiles)
|
||||
for (i in 0 until numFiles) {
|
||||
res[i] = resultIntent.clipData!!.getItemAt(i).uri
|
||||
}
|
||||
} else {
|
||||
res = FileChooserParams.parseResult(
|
||||
result?.resultCode ?: 0,
|
||||
resultIntent
|
||||
)
|
||||
}
|
||||
filePathCallback.onReceiveValue(res)
|
||||
}
|
||||
}
|
||||
activityLauncher.launch(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
filePathCallback.onReceiveValue(null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getValidTypes(currentTypes: Array<String>): Array<String> {
|
||||
val validTypes: MutableList<String> = ArrayList()
|
||||
val mtm = MimeTypeMap.getSingleton()
|
||||
for (mime in currentTypes) {
|
||||
if (mime.startsWith(".")) {
|
||||
val extension = mime.substring(1)
|
||||
val extensionMime = mtm.getMimeTypeFromExtension(extension)
|
||||
if (extensionMime != null && !validTypes.contains(extensionMime)) {
|
||||
validTypes.add(extensionMime)
|
||||
}
|
||||
} else if (!validTypes.contains(mime)) {
|
||||
validTypes.add(mime)
|
||||
}
|
||||
}
|
||||
val validObj: Array<Any> = validTypes.toTypedArray()
|
||||
return Arrays.copyOf(
|
||||
validObj, validObj.size,
|
||||
Array<String>::class.java
|
||||
)
|
||||
}
|
||||
|
||||
override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
|
||||
val tag: String = Logger.tags("Console")
|
||||
if (consoleMessage.message() != null && isValidMsg(consoleMessage.message())) {
|
||||
val msg = String.format(
|
||||
"File: %s - Line %d - Msg: %s",
|
||||
consoleMessage.sourceId(),
|
||||
consoleMessage.lineNumber(),
|
||||
consoleMessage.message()
|
||||
)
|
||||
val level = consoleMessage.messageLevel().name
|
||||
if ("ERROR".equals(level, ignoreCase = true)) {
|
||||
Logger.error(tag, msg, null)
|
||||
} else if ("WARNING".equals(level, ignoreCase = true)) {
|
||||
Logger.warn(tag, msg)
|
||||
} else if ("TIP".equals(level, ignoreCase = true)) {
|
||||
Logger.debug(tag, msg)
|
||||
} else {
|
||||
Logger.info(tag, msg)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun isValidMsg(msg: String): Boolean {
|
||||
return !(msg.contains("%cresult %c") ||
|
||||
msg.contains("%cnative %c") ||
|
||||
msg.equals("[object Object]", ignoreCase = true) ||
|
||||
msg.equals("console.groupEnd", ignoreCase = true))
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun createImageFileUri(): Uri {
|
||||
val photoFile = createImageFile(activity)
|
||||
return FileProvider.getUriForFile(
|
||||
activity,
|
||||
activity.packageName.toString() + ".fileprovider",
|
||||
photoFile
|
||||
)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun createImageFile(activity: Activity): File {
|
||||
// Create an image file name
|
||||
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
|
||||
val imageFileName = "JPEG_" + timeStamp + "_"
|
||||
val storageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
|
||||
return File.createTempFile(imageFileName, ".jpg", storageDir)
|
||||
}
|
||||
|
||||
override fun onReceivedTitle(
|
||||
view: WebView,
|
||||
title: String
|
||||
) {
|
||||
handleReceivedTitle(view, title)
|
||||
}
|
||||
|
||||
private external fun handleReceivedTitle(webview: WebView, title: String)
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
@file:Suppress("unused", "SetJavaScriptEnabled")
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.webkit.*
|
||||
import android.content.Context
|
||||
import androidx.webkit.WebViewCompat
|
||||
import androidx.webkit.WebViewFeature
|
||||
import kotlin.collections.Map
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
class RustWebView(context: Context, val initScripts: Array<String>, val id: String): WebView(context) {
|
||||
val isDocumentStartScriptEnabled: Boolean
|
||||
|
||||
init {
|
||||
settings.javaScriptEnabled = true
|
||||
settings.domStorageEnabled = true
|
||||
settings.setGeolocationEnabled(true)
|
||||
settings.databaseEnabled = true
|
||||
settings.mediaPlaybackRequiresUserGesture = false
|
||||
settings.javaScriptCanOpenWindowsAutomatically = true
|
||||
|
||||
if (WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) {
|
||||
isDocumentStartScriptEnabled = true
|
||||
for (script in initScripts) {
|
||||
WebViewCompat.addDocumentStartJavaScript(this, script, setOf("*"));
|
||||
}
|
||||
} else {
|
||||
isDocumentStartScriptEnabled = false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun loadUrlMainThread(url: String) {
|
||||
post {
|
||||
loadUrl(url)
|
||||
}
|
||||
}
|
||||
|
||||
fun loadUrlMainThread(url: String, additionalHttpHeaders: Map<String, String>) {
|
||||
post {
|
||||
loadUrl(url, additionalHttpHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadUrl(url: String) {
|
||||
if (!shouldOverride(url)) {
|
||||
super.loadUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadUrl(url: String, additionalHttpHeaders: Map<String, String>) {
|
||||
if (!shouldOverride(url)) {
|
||||
super.loadUrl(url, additionalHttpHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
fun loadHTMLMainThread(html: String) {
|
||||
post {
|
||||
super.loadData(html, "text/html", null)
|
||||
}
|
||||
}
|
||||
|
||||
fun evalScript(id: Int, script: String) {
|
||||
post {
|
||||
super.evaluateJavascript(script) { result ->
|
||||
onEval(id, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearAllBrowsingData() {
|
||||
try {
|
||||
super.getContext().deleteDatabase("webviewCache.db")
|
||||
super.getContext().deleteDatabase("webview.db")
|
||||
super.clearCache(true)
|
||||
super.clearHistory()
|
||||
super.clearFormData()
|
||||
} catch (ex: Exception) {
|
||||
Logger.error("Unable to create temporary media capture file: " + ex.message)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCookies(url: String): String {
|
||||
val cookieManager = CookieManager.getInstance()
|
||||
return cookieManager.getCookie(url)
|
||||
}
|
||||
|
||||
private external fun shouldOverride(url: String): Boolean
|
||||
private external fun onEval(id: Int, result: String)
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
import android.net.Uri
|
||||
import android.webkit.*
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.webkit.WebViewAssetLoader
|
||||
|
||||
class RustWebViewClient(context: Context): WebViewClient() {
|
||||
private val interceptedState = mutableMapOf<String, Boolean>()
|
||||
var currentUrl: String = "about:blank"
|
||||
private var lastInterceptedUrl: Uri? = null
|
||||
private var pendingUrlRedirect: String? = null
|
||||
|
||||
private val assetLoader = WebViewAssetLoader.Builder()
|
||||
.setDomain(assetLoaderDomain())
|
||||
.addPathHandler("/", WebViewAssetLoader.AssetsPathHandler(context))
|
||||
.build()
|
||||
|
||||
override fun shouldInterceptRequest(
|
||||
view: WebView,
|
||||
request: WebResourceRequest
|
||||
): WebResourceResponse? {
|
||||
pendingUrlRedirect?.let {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
view.loadUrl(it)
|
||||
}
|
||||
pendingUrlRedirect = null
|
||||
return null
|
||||
}
|
||||
|
||||
lastInterceptedUrl = request.url
|
||||
return if (withAssetLoader()) {
|
||||
assetLoader.shouldInterceptRequest(request.url)
|
||||
} else {
|
||||
val rustWebview = view as RustWebView;
|
||||
val response = handleRequest(rustWebview.id, request, rustWebview.isDocumentStartScriptEnabled)
|
||||
interceptedState[request.url.toString()] = response != null
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun shouldOverrideUrlLoading(
|
||||
view: WebView,
|
||||
request: WebResourceRequest
|
||||
): Boolean {
|
||||
return shouldOverride(request.url.toString())
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
|
||||
currentUrl = url
|
||||
if (interceptedState[url] == false) {
|
||||
val webView = view as RustWebView
|
||||
for (script in webView.initScripts) {
|
||||
view.evaluateJavascript(script, null)
|
||||
}
|
||||
}
|
||||
return onPageLoading(url)
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
onPageLoaded(url)
|
||||
}
|
||||
|
||||
override fun onReceivedError(
|
||||
view: WebView,
|
||||
request: WebResourceRequest,
|
||||
error: WebResourceError
|
||||
) {
|
||||
// we get a net::ERR_CONNECTION_REFUSED when an external URL redirects to a custom protocol
|
||||
// e.g. oauth flow, because shouldInterceptRequest is not called on redirects
|
||||
// so we must force retry here with loadUrl() to get a chance of the custom protocol to kick in
|
||||
if (error.errorCode == ERROR_CONNECT && request.isForMainFrame && request.url != lastInterceptedUrl) {
|
||||
// prevent the default error page from showing
|
||||
view.stopLoading()
|
||||
// without this initial loadUrl the app is stuck
|
||||
view.loadUrl(request.url.toString())
|
||||
// ensure the URL is actually loaded - for some reason there's a race condition and we need to call loadUrl() again later
|
||||
pendingUrlRedirect = request.url.toString()
|
||||
} else {
|
||||
super.onReceivedError(view, request, error)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("tauri_demo_lib")
|
||||
}
|
||||
}
|
||||
|
||||
private external fun assetLoaderDomain(): String
|
||||
private external fun withAssetLoader(): Boolean
|
||||
private external fun handleRequest(webviewId: String, request: WebResourceRequest, isDocumentStartScriptEnabled: Boolean): WebResourceResponse?
|
||||
private external fun shouldOverride(url: String): Boolean
|
||||
private external fun onPageLoading(url: String)
|
||||
private external fun onPageLoaded(url: String)
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import app.tauri.plugin.PluginManager
|
||||
|
||||
abstract class TauriActivity : WryActivity() {
|
||||
var pluginManager: PluginManager = PluginManager(this)
|
||||
override val handleBackNavigation: Boolean = false
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
pluginManager.onNewIntent(intent)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
pluginManager.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
pluginManager.onPause()
|
||||
}
|
||||
|
||||
override fun onRestart() {
|
||||
super.onRestart()
|
||||
pluginManager.onRestart()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
pluginManager.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
pluginManager.onDestroy()
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
pluginManager.onConfigurationChanged(newConfig)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */
|
||||
|
||||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package com.lenn.tauri_serial
|
||||
|
||||
import com.lenn.tauri_serial.RustWebView
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.webkit.WebView
|
||||
import android.view.KeyEvent
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
abstract class WryActivity : AppCompatActivity() {
|
||||
private lateinit var mWebView: RustWebView
|
||||
open val handleBackNavigation: Boolean = true
|
||||
|
||||
open fun onWebViewCreate(webView: WebView) { }
|
||||
|
||||
fun setWebView(webView: RustWebView) {
|
||||
mWebView = webView
|
||||
|
||||
if (handleBackNavigation) {
|
||||
val callback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
if (this@WryActivity.mWebView.canGoBack()) {
|
||||
this@WryActivity.mWebView.goBack()
|
||||
} else {
|
||||
this.isEnabled = false
|
||||
this@WryActivity.onBackPressed()
|
||||
this.isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
onBackPressedDispatcher.addCallback(this, callback)
|
||||
}
|
||||
|
||||
onWebViewCreate(webView)
|
||||
}
|
||||
|
||||
val version: String
|
||||
@SuppressLint("WebViewApiAvailability", "ObsoleteSdkInt")
|
||||
get() {
|
||||
// Check getCurrentWebViewPackage() directly if above Android 8
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
return WebView.getCurrentWebViewPackage()?.versionName ?: ""
|
||||
}
|
||||
|
||||
// Otherwise manually check WebView versions
|
||||
var webViewPackage = "com.google.android.webview"
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
webViewPackage = "com.android.chrome"
|
||||
}
|
||||
try {
|
||||
@Suppress("DEPRECATION")
|
||||
val info = packageManager.getPackageInfo(webViewPackage, 0)
|
||||
return info.versionName.toString()
|
||||
} catch (ex: Exception) {
|
||||
Logger.warn("Unable to get package info for '$webViewPackage'$ex")
|
||||
}
|
||||
|
||||
try {
|
||||
@Suppress("DEPRECATION")
|
||||
val info = packageManager.getPackageInfo("com.android.webview", 0)
|
||||
return info.versionName.toString()
|
||||
} catch (ex: Exception) {
|
||||
Logger.warn("Unable to get package info for 'com.android.webview'$ex")
|
||||
}
|
||||
|
||||
// Could not detect any webview, return empty string
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
create(this)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
start()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
resume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
pause()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
stop()
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
focus(hasFocus)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
save()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
destroy()
|
||||
onActivityDestroy()
|
||||
}
|
||||
|
||||
override fun onLowMemory() {
|
||||
super.onLowMemory()
|
||||
memory()
|
||||
}
|
||||
|
||||
fun getAppClass(name: String): Class<*> {
|
||||
return Class.forName(name)
|
||||
}
|
||||
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("tauri_demo_lib")
|
||||
}
|
||||
}
|
||||
|
||||
private external fun create(activity: WryActivity)
|
||||
private external fun start()
|
||||
private external fun resume()
|
||||
private external fun pause()
|
||||
private external fun stop()
|
||||
private external fun save()
|
||||
private external fun destroy()
|
||||
private external fun onActivityDestroy()
|
||||
private external fun memory()
|
||||
private external fun focus(focus: Boolean)
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
# THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!!
|
||||
|
||||
# Copyright 2020-2023 Tauri Programme within The Commons Conservancy
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
-keep class com.lenn.tauri_serial.* {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keep class com.lenn.tauri_serial.WryActivity {
|
||||
public <init>(...);
|
||||
|
||||
void setWebView(com.lenn.tauri_serial.RustWebView);
|
||||
java.lang.Class getAppClass(...);
|
||||
java.lang.String getVersion();
|
||||
}
|
||||
|
||||
-keep class com.lenn.tauri_serial.Ipc {
|
||||
public <init>(...);
|
||||
|
||||
@android.webkit.JavascriptInterface public <methods>;
|
||||
}
|
||||
|
||||
-keep class com.lenn.tauri_serial.RustWebView {
|
||||
public <init>(...);
|
||||
|
||||
void loadUrlMainThread(...);
|
||||
void loadHTMLMainThread(...);
|
||||
void evalScript(...);
|
||||
}
|
||||
|
||||
-keep class com.lenn.tauri_serial.RustWebChromeClient,com.lenn.tauri_serial.RustWebViewClient {
|
||||
public <init>(...);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/home/lenn/Workspace/JE-Skin/src-tauri/target/aarch64-linux-android/release/libtauri_demo_lib.so
|
||||
@@ -0,0 +1 @@
|
||||
/home/lenn/Workspace/JE-Skin/src-tauri/target/armv7-linux-androideabi/release/libtauri_demo_lib.so
|
||||
@@ -0,0 +1 @@
|
||||
/home/lenn/Workspace/JE-Skin/src-tauri/target/i686-linux-android/release/libtauri_demo_lib.so
|
||||
@@ -0,0 +1 @@
|
||||
/home/lenn/Workspace/JE-Skin/src-tauri/target/x86_64-linux-android/release/libtauri_demo_lib.so
|
||||
@@ -1,30 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
@@ -1,170 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 8.9 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,6 +0,0 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.je_skin" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
@@ -1,4 +0,0 @@
|
||||
<resources>
|
||||
<string name="app_name">JE-Skin</string>
|
||||
<string name="main_activity_title">JE-Skin</string>
|
||||
</resources>
|
||||
@@ -1,6 +0,0 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.je_skin" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="my_images" path="." />
|
||||
<cache-path name="my_cache_images" path="." />
|
||||
</paths>
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- CH340 / CH341 USB-Serial -->
|
||||
<usb-device vendor-id="1a86" product-id="7523" />
|
||||
<!-- CP2102 / CP2104 -->
|
||||
<usb-device vendor-id="10c4" product-id="ea60" />
|
||||
<usb-device vendor-id="10c4" product-id="ea70" />
|
||||
<!-- FTDI FT232R / FT232H -->
|
||||
<usb-device vendor-id="0403" product-id="6001" />
|
||||
<usb-device vendor-id="0403" product-id="6014" />
|
||||
<!-- PL2303 -->
|
||||
<usb-device vendor-id="067b" product-id="2303" />
|
||||
<usb-device vendor-id="067b" product-id="23a3" />
|
||||
<!-- CDC ACM (generic USB serial) -->
|
||||
<usb-device vendor-id="2341" product-id="0001" />
|
||||
<usb-device vendor-id="2341" product-id="0043" />
|
||||
<usb-device vendor-id="2341" product-id="0042" />
|
||||
<!-- Allow any USB device (catch-all) -->
|
||||
<usb-device />
|
||||
</resources>
|
||||
6
src-tauri/gen/android/app/tauri.build.gradle.kts
Normal file
@@ -0,0 +1,6 @@
|
||||
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
val implementation by configurations
|
||||
dependencies {
|
||||
implementation(project(":tauri-android"))
|
||||
implementation(project(":tauri-plugin-opener"))
|
||||
}
|
||||
3
src-tauri/gen/android/app/tauri.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
tauri.android.versionName=0.4.0
|
||||
tauri.android.versionCode=4000
|
||||
@@ -1,22 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:8.11.0")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.25")
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven(url = "https://jitpack.io")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("clean").configure {
|
||||
delete("build")
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("pluginsForCoolKids") {
|
||||
id = "rust"
|
||||
implementationClass = "RustPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(gradleApi())
|
||||
implementation("com.android.tools.build:gradle:8.11.0")
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
import java.io.File
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
open class BuildTask : DefaultTask() {
|
||||
@Input
|
||||
var rootDirRel: String? = null
|
||||
@Input
|
||||
var target: String? = null
|
||||
@Input
|
||||
var release: Boolean? = null
|
||||
|
||||
@TaskAction
|
||||
fun assemble() {
|
||||
val executable = """cargo""";
|
||||
try {
|
||||
runTauriCli(executable)
|
||||
} catch (e: Exception) {
|
||||
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
||||
// Try different Windows-specific extensions
|
||||
val fallbacks = listOf(
|
||||
"$executable.exe",
|
||||
"$executable.cmd",
|
||||
"$executable.bat",
|
||||
)
|
||||
|
||||
var lastException: Exception = e
|
||||
for (fallback in fallbacks) {
|
||||
try {
|
||||
runTauriCli(fallback)
|
||||
return
|
||||
} catch (fallbackException: Exception) {
|
||||
lastException = fallbackException
|
||||
}
|
||||
}
|
||||
throw lastException
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun runTauriCli(executable: String) {
|
||||
val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null")
|
||||
val target = target ?: throw GradleException("target cannot be null")
|
||||
val release = release ?: throw GradleException("release cannot be null")
|
||||
val args = listOf("tauri", "android", "android-studio-script");
|
||||
|
||||
project.exec {
|
||||
workingDir(File(project.projectDir, rootDirRel))
|
||||
executable(executable)
|
||||
args(args)
|
||||
if (project.logger.isEnabled(LogLevel.DEBUG)) {
|
||||
args("-vv")
|
||||
} else if (project.logger.isEnabled(LogLevel.INFO)) {
|
||||
args("-v")
|
||||
}
|
||||
if (release) {
|
||||
args("--release")
|
||||
}
|
||||
args(listOf("--target", target))
|
||||
}.assertNormalExitValue()
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.get
|
||||
|
||||
const val TASK_GROUP = "rust"
|
||||
|
||||
open class Config {
|
||||
lateinit var rootDirRel: String
|
||||
}
|
||||
|
||||
open class RustPlugin : Plugin<Project> {
|
||||
private lateinit var config: Config
|
||||
|
||||
override fun apply(project: Project) = with(project) {
|
||||
config = extensions.create("rust", Config::class.java)
|
||||
|
||||
val defaultAbiList = listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64");
|
||||
val abiList = (findProperty("abiList") as? String)?.split(',') ?: defaultAbiList
|
||||
|
||||
val defaultArchList = listOf("arm64", "arm", "x86", "x86_64");
|
||||
val archList = (findProperty("archList") as? String)?.split(',') ?: defaultArchList
|
||||
|
||||
val targetsList = (findProperty("targetList") as? String)?.split(',') ?: listOf("aarch64", "armv7", "i686", "x86_64")
|
||||
|
||||
extensions.configure<ApplicationExtension> {
|
||||
@Suppress("UnstableApiUsage")
|
||||
flavorDimensions.add("abi")
|
||||
productFlavors {
|
||||
create("universal") {
|
||||
dimension = "abi"
|
||||
ndk {
|
||||
abiFilters += abiList
|
||||
}
|
||||
}
|
||||
defaultArchList.forEachIndexed { index, arch ->
|
||||
create(arch) {
|
||||
dimension = "abi"
|
||||
ndk {
|
||||
abiFilters.add(defaultAbiList[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
for (profile in listOf("debug", "release")) {
|
||||
val profileCapitalized = profile.replaceFirstChar { it.uppercase() }
|
||||
val buildTask = tasks.maybeCreate(
|
||||
"rustBuildUniversal$profileCapitalized",
|
||||
DefaultTask::class.java
|
||||
).apply {
|
||||
group = TASK_GROUP
|
||||
description = "Build dynamic library in $profile mode for all targets"
|
||||
}
|
||||
|
||||
tasks["mergeUniversal${profileCapitalized}JniLibFolders"].dependsOn(buildTask)
|
||||
|
||||
for (targetPair in targetsList.withIndex()) {
|
||||
val targetName = targetPair.value
|
||||
val targetArch = archList[targetPair.index]
|
||||
val targetArchCapitalized = targetArch.replaceFirstChar { it.uppercase() }
|
||||
val targetBuildTask = project.tasks.maybeCreate(
|
||||
"rustBuild$targetArchCapitalized$profileCapitalized",
|
||||
BuildTask::class.java
|
||||
).apply {
|
||||
group = TASK_GROUP
|
||||
description = "Build dynamic library in $profile mode for $targetArch"
|
||||
rootDirRel = config.rootDirRel
|
||||
target = targetName
|
||||
release = profile == "release"
|
||||
}
|
||||
|
||||
buildTask.dependsOn(targetBuildTask)
|
||||
tasks["merge$targetArchCapitalized${profileCapitalized}JniLibFolders"].dependsOn(
|
||||
targetBuildTask
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app"s APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
# Enables namespacing of each library's R class so that its R class includes only the
|
||||
# resources declared in the library itself and none from the library's dependencies,
|
||||
# thereby reducing the size of the R class for that library
|
||||
android.nonTransitiveRClass=true
|
||||
android.nonFinalResIds=false
|
||||
@@ -1,6 +0,0 @@
|
||||
#Tue May 10 19:22:52 CST 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
185
src-tauri/gen/android/gradlew
vendored
@@ -1,185 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
89
src-tauri/gen/android/gradlew.bat
vendored
@@ -1,89 +0,0 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -1,3 +0,0 @@
|
||||
include ':app'
|
||||
|
||||
apply from: 'tauri.settings.gradle'
|
||||
5
src-tauri/gen/android/tauri.settings.gradle
Normal file
@@ -0,0 +1,5 @@
|
||||
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
include ':tauri-android'
|
||||
project(':tauri-android').projectDir = new File("/home/lenn/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tauri-2.10.3/mobile/android")
|
||||
include ':tauri-plugin-opener'
|
||||
project(':tauri-plugin-opener').projectDir = new File("/home/lenn/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tauri-plugin-opener-2.5.3/android")
|
||||
@@ -1,66 +0,0 @@
|
||||
[default]
|
||||
description = "Allows Android USB serial plugin commands."
|
||||
permissions = [
|
||||
"allow-usb-serial-list",
|
||||
"allow-usb-serial-open",
|
||||
"allow-usb-serial-close",
|
||||
"allow-usb-serial-list-camel",
|
||||
"allow-usb-serial-open-camel",
|
||||
"allow-usb-serial-close-camel",
|
||||
"allow-local-commands"
|
||||
]
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-usb-serial-list"
|
||||
description = "Allows listing Android USB serial devices."
|
||||
commands.allow = ["plugin:usb-serial|usb_serial_list"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-usb-serial-open"
|
||||
description = "Allows opening Android USB serial devices."
|
||||
commands.allow = ["plugin:usb-serial|usb_serial_open"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-usb-serial-close"
|
||||
description = "Allows closing Android USB serial devices."
|
||||
commands.allow = ["plugin:usb-serial|usb_serial_close"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-usb-serial-list-camel"
|
||||
description = "Allows listing Android USB serial devices via camelCase command."
|
||||
commands.allow = ["plugin:usb-serial|usbSerialList"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-usb-serial-open-camel"
|
||||
description = "Allows opening Android USB serial devices via camelCase command."
|
||||
commands.allow = ["plugin:usb-serial|usbSerialOpen"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-usb-serial-close-camel"
|
||||
description = "Allows closing Android USB serial devices via camelCase command."
|
||||
commands.allow = ["plugin:usb-serial|usbSerialClose"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-local-commands"
|
||||
description = "Allows application commands used by the Android frontend."
|
||||
commands.allow = [
|
||||
"file_explorer_list",
|
||||
"serial_enum",
|
||||
"serial_connect",
|
||||
"serial_connect_fd",
|
||||
"serial_disconnect",
|
||||
"serial_export_csv",
|
||||
"serial_has_record_data",
|
||||
"serial_export_csv_to_path",
|
||||
"serial_import_csv",
|
||||
"serial_import_csv_from_path",
|
||||
"win_minimize",
|
||||
"win_toggle_maximize",
|
||||
"win_close",
|
||||
"devkit_status",
|
||||
"devkit_start",
|
||||
"devkit_stop",
|
||||
"devkit_get_config",
|
||||
"devkit_set_config",
|
||||
"devkit_process_export"
|
||||
]
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"plugins": {
|
||||
"usb-serial": {
|
||||
"android": {
|
||||
"package": "com.lenn.tauri_serial.UsbSerialPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,6 @@ fn resolve_start_path(app: &AppHandle, raw_path: Option<String>) -> Result<PathB
|
||||
}
|
||||
|
||||
fn resolve_default_path(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
if let Ok(path) = app.path().desktop_dir() {
|
||||
return Ok(path);
|
||||
}
|
||||
@@ -176,7 +175,6 @@ fn collect_roots(app: &AppHandle) -> Vec<FileExplorerRoot> {
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
if let Ok(path) = app.path().desktop_dir() {
|
||||
push_root("Desktop", path);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
use tauri::{async_runtime::JoinHandle, AppHandle, Manager, State};
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use tokio_serial::{available_ports, SerialPortBuilderExt};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
@@ -114,31 +113,22 @@ pub async fn shutdown_active_session(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn serial_enum() -> Result<Vec<String>, SerialError> {
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
Ok(Vec::new())
|
||||
}
|
||||
let ports = available_ports()
|
||||
.map_err(|_| SerialError::ScanError)?
|
||||
.into_iter()
|
||||
.filter_map(|p| {
|
||||
let name = p.port_name;
|
||||
#[cfg(unix)]
|
||||
if !name.contains("USB") {
|
||||
return None;
|
||||
}
|
||||
Some(name)
|
||||
})
|
||||
.collect();
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
let ports = available_ports()
|
||||
.map_err(|_| SerialError::ScanError)?
|
||||
.into_iter()
|
||||
.filter_map(|p| {
|
||||
let name = p.port_name;
|
||||
#[cfg(unix)]
|
||||
if !name.contains("USB") {
|
||||
return None;
|
||||
}
|
||||
Some(name)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(ports)
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[tauri::command]
|
||||
pub async fn serial_connect(
|
||||
app: AppHandle,
|
||||
@@ -256,122 +246,15 @@ pub async fn serial_disconnect(
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
#[tauri::command]
|
||||
pub async fn serial_connect_fd(
|
||||
app: AppHandle,
|
||||
fd: i32,
|
||||
device_name: String,
|
||||
state: State<'_, SerialConnectionState>,
|
||||
) -> Result<SerialConnectResponse, SerialError> {
|
||||
if fd < 0 {
|
||||
return Err(SerialError::InvalidConfig);
|
||||
}
|
||||
|
||||
{
|
||||
let session = state.session.lock().map_err(|_| SerialError::StateError)?;
|
||||
if session.is_some() {
|
||||
return Err(SerialError::AlreadyConnected);
|
||||
}
|
||||
}
|
||||
|
||||
let cancel = CancellationToken::new();
|
||||
let current_record = Arc::new(Mutex::new(TactileARecording::new()));
|
||||
let task_record = current_record.clone();
|
||||
let task_cancel = cancel.clone();
|
||||
let task_app = app.clone();
|
||||
let task_port_name = device_name.clone();
|
||||
|
||||
let port = crate::serial_core::raw_fd_stream::RawFdStream::new(fd)
|
||||
.map_err(|_| SerialError::OpenError)?;
|
||||
let session_started_at = Instant::now();
|
||||
|
||||
let task = tauri::async_runtime::spawn(async move {
|
||||
let codec = TactileACodec::new(DEFAULT_TACTILE_COLS, DEFAULT_TACTILE_ROWS);
|
||||
let handler = TactileAHandler;
|
||||
let poll_mode = PollMode::Enabled(Box::new(TactileAPollRequester::new(
|
||||
Duration::from_millis(DEFAULT_TACTILE_POLL_INTERVAL_MS),
|
||||
DEFAULT_TACTILE_COLS,
|
||||
DEFAULT_TACTILE_ROWS,
|
||||
Duration::from_millis(DEFAULT_TACTILE_REPLY_TIMEOUT_MS),
|
||||
)));
|
||||
|
||||
if let Err(error) = serial::run_serial_with_poll(
|
||||
task_app.clone(),
|
||||
port,
|
||||
codec,
|
||||
handler,
|
||||
session_started_at,
|
||||
task_record.clone(),
|
||||
task_cancel,
|
||||
poll_mode,
|
||||
)
|
||||
.await
|
||||
{
|
||||
eprintln!("serial task exited with error: {error}");
|
||||
}
|
||||
|
||||
let manager = task_app.state::<SerialConnectionState>();
|
||||
if let Ok(mut last_record) = manager.last_record.lock() {
|
||||
*last_record = Some(task_record);
|
||||
}
|
||||
|
||||
let mut session = match manager.session.lock() {
|
||||
Ok(session) => session,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
{
|
||||
let should_clear = session
|
||||
.as_ref()
|
||||
.map(|current| current.port.as_str() == task_port_name.as_str())
|
||||
.unwrap_or(false);
|
||||
|
||||
if should_clear {
|
||||
session.take();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let mut session = state.session.lock().map_err(|_| SerialError::StateError)?;
|
||||
if session.is_some() {
|
||||
cancel.cancel();
|
||||
task.abort();
|
||||
return Err(SerialError::AlreadyConnected);
|
||||
}
|
||||
|
||||
*session = Some(SerialSession {
|
||||
port: device_name.clone(),
|
||||
cancel,
|
||||
task,
|
||||
current_record,
|
||||
});
|
||||
|
||||
Ok(SerialConnectResponse {
|
||||
port: device_name,
|
||||
connected: true,
|
||||
message: "connected".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn serial_export_csv(
|
||||
app: AppHandle,
|
||||
state: State<'_, SerialConnectionState>,
|
||||
) -> Result<SerialExportResponse, SerialError> {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
let mut output_dir = match app.path().desktop_dir() {
|
||||
Ok(path) => path,
|
||||
Err(_) => std::env::current_dir().map_err(|_| SerialError::ExportError)?,
|
||||
};
|
||||
#[cfg(target_os = "android")]
|
||||
let mut output_dir = match app.path().download_dir() {
|
||||
Ok(path) => path,
|
||||
Err(_) => app.path().document_dir()
|
||||
.or_else(|_| app.path().home_dir())
|
||||
.or_else(|_| std::env::current_dir())
|
||||
.map_err(|_| SerialError::ExportError)?,
|
||||
};
|
||||
|
||||
let timestamp = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
|
||||
@@ -9,36 +9,20 @@ fn main_window(app: &AppHandle) -> Result<WebviewWindow, String> {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn win_minimize(app: AppHandle) -> Result<(), String> {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
main_window(&app)?
|
||||
.minimize()
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let _ = app;
|
||||
Ok(())
|
||||
}
|
||||
main_window(&app)?
|
||||
.minimize()
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn win_toggle_maximize(app: AppHandle) -> Result<(), String> {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
let window = main_window(&app)?;
|
||||
let is_maximized = window.is_maximized().map_err(|error| error.to_string())?;
|
||||
let window = main_window(&app)?;
|
||||
let is_maximized = window.is_maximized().map_err(|error| error.to_string())?;
|
||||
|
||||
if is_maximized {
|
||||
window.unmaximize().map_err(|error| error.to_string())
|
||||
} else {
|
||||
window.maximize().map_err(|error| error.to_string())
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let _ = app;
|
||||
Ok(())
|
||||
if is_maximized {
|
||||
window.unmaximize().map_err(|error| error.to_string())
|
||||
} else {
|
||||
window.maximize().map_err(|error| error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,6 @@ use commands::serial::SerialConnectionState;
|
||||
#[cfg(feature = "devkit")]
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn usb_serial_plugin<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
||||
tauri::plugin::Builder::new("usb-serial")
|
||||
.setup(|_app, api| {
|
||||
api.register_android_plugin("com.lenn.tauri_serial", "UsbSerialPlugin")?;
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
#[cfg(feature = "devkit")]
|
||||
fn start_server_exe(exe_path: &std::path::Path) {
|
||||
let mut command = std::process::Command::new(exe_path);
|
||||
@@ -76,9 +66,6 @@ pub fn run() {
|
||||
.manage(SerialConnectionState::default())
|
||||
.plugin(tauri_plugin_opener::init());
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
let builder = builder.plugin(usb_serial_plugin());
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
let builder = builder.plugin(tauri_plugin_updater::Builder::new().build());
|
||||
|
||||
@@ -148,7 +135,7 @@ pub fn run() {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
#[cfg(all(feature = "devkit", not(target_os = "android")))]
|
||||
#[cfg(feature = "devkit")]
|
||||
let builder = builder.invoke_handler(tauri::generate_handler![
|
||||
commands::file_explorer::file_explorer_list,
|
||||
commands::serial::serial_enum,
|
||||
@@ -170,7 +157,7 @@ pub fn run() {
|
||||
commands::devkit::devkit_process_export
|
||||
]);
|
||||
|
||||
#[cfg(all(not(feature = "devkit"), not(target_os = "android")))]
|
||||
#[cfg(not(feature = "devkit"))]
|
||||
let builder = builder.invoke_handler(tauri::generate_handler![
|
||||
commands::file_explorer::file_explorer_list,
|
||||
commands::serial::serial_enum,
|
||||
@@ -186,44 +173,6 @@ pub fn run() {
|
||||
commands::window::win_close
|
||||
]);
|
||||
|
||||
#[cfg(all(feature = "devkit", target_os = "android"))]
|
||||
let builder = builder.invoke_handler(tauri::generate_handler![
|
||||
commands::file_explorer::file_explorer_list,
|
||||
commands::serial::serial_enum,
|
||||
commands::serial::serial_connect_fd,
|
||||
commands::serial::serial_disconnect,
|
||||
commands::serial::serial_export_csv,
|
||||
commands::serial::serial_has_record_data,
|
||||
commands::serial::serial_export_csv_to_path,
|
||||
commands::serial::serial_import_csv,
|
||||
commands::serial::serial_import_csv_from_path,
|
||||
commands::window::win_minimize,
|
||||
commands::window::win_toggle_maximize,
|
||||
commands::window::win_close,
|
||||
commands::devkit::devkit_status,
|
||||
commands::devkit::devkit_start,
|
||||
commands::devkit::devkit_stop,
|
||||
commands::devkit::devkit_get_config,
|
||||
commands::devkit::devkit_set_config,
|
||||
commands::devkit::devkit_process_export
|
||||
]);
|
||||
|
||||
#[cfg(all(not(feature = "devkit"), target_os = "android"))]
|
||||
let builder = builder.invoke_handler(tauri::generate_handler![
|
||||
commands::file_explorer::file_explorer_list,
|
||||
commands::serial::serial_enum,
|
||||
commands::serial::serial_connect_fd,
|
||||
commands::serial::serial_disconnect,
|
||||
commands::serial::serial_export_csv,
|
||||
commands::serial::serial_has_record_data,
|
||||
commands::serial::serial_export_csv_to_path,
|
||||
commands::serial::serial_import_csv,
|
||||
commands::serial::serial_import_csv_from_path,
|
||||
commands::window::win_minimize,
|
||||
commands::window::win_toggle_maximize,
|
||||
commands::window::win_close
|
||||
]);
|
||||
|
||||
builder
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
@@ -11,8 +11,6 @@ pub mod model;
|
||||
pub mod serial;
|
||||
pub mod record;
|
||||
pub mod utils;
|
||||
#[cfg(target_os = "android")]
|
||||
pub mod raw_fd_stream;
|
||||
#[cfg(feature = "multi-dim")]
|
||||
pub mod multi_dim_force;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ pub struct HudPacket {
|
||||
pub panels: Vec<HudSignalPanel>,
|
||||
pub summary: HudSummary,
|
||||
pub pressure_matrix: Option<Vec<f32>>,
|
||||
pub spatial_force: Option<HudSpatialForce>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
@@ -74,6 +75,14 @@ pub struct HudSignalIcon {
|
||||
pub tone: HudTone,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HudSpatialForce {
|
||||
pub angle_deg: f32,
|
||||
pub magnitude: f32,
|
||||
pub confidence: f32,
|
||||
}
|
||||
|
||||
struct HudPanelUpdate {
|
||||
source_id: String,
|
||||
values: Vec<f32>,
|
||||
@@ -89,6 +98,7 @@ pub struct HudChartState {
|
||||
order: Vec<String>,
|
||||
summary_points: Vec<f32>,
|
||||
pressure_matrix: Option<Vec<f32>>,
|
||||
spatial_force: Option<HudSpatialForce>,
|
||||
last_frame_seen: Option<Instant>,
|
||||
}
|
||||
|
||||
@@ -99,6 +109,7 @@ impl HudChartState {
|
||||
order: Vec::new(),
|
||||
summary_points: Vec::new(),
|
||||
pressure_matrix: None,
|
||||
spatial_force: None,
|
||||
last_frame_seen: None,
|
||||
}
|
||||
}
|
||||
@@ -115,6 +126,10 @@ impl HudChartState {
|
||||
self.pressure_matrix = Some(values.iter().map(|value| *value as f32).collect());
|
||||
}
|
||||
|
||||
pub fn record_spatial_force(&mut self, spatial_force: Option<HudSpatialForce>) {
|
||||
self.spatial_force = spatial_force;
|
||||
}
|
||||
|
||||
pub fn apply_frame(&mut self, frame: &TestFrame, decoded_values: Option<&[i32]>) -> HudPacket {
|
||||
let now = Instant::now();
|
||||
self.last_frame_seen = Some(now);
|
||||
@@ -130,9 +145,15 @@ impl HudChartState {
|
||||
pub fn prune_stale(&mut self) -> Option<HudPacket> {
|
||||
let before = self.panels.len();
|
||||
let summary_points_before = self.summary_points.len();
|
||||
let had_pressure_matrix = self.pressure_matrix.is_some();
|
||||
let had_spatial_force = self.spatial_force.is_some();
|
||||
self.prune_stale_at(Instant::now());
|
||||
|
||||
if before == self.panels.len() && summary_points_before == self.summary_points.len() {
|
||||
if before == self.panels.len()
|
||||
&& summary_points_before == self.summary_points.len()
|
||||
&& had_pressure_matrix == self.pressure_matrix.is_some()
|
||||
&& had_spatial_force == self.spatial_force.is_some()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -187,6 +208,7 @@ impl HudChartState {
|
||||
if summary_stale {
|
||||
self.summary_points.clear();
|
||||
self.pressure_matrix = None;
|
||||
self.spatial_force = None;
|
||||
self.last_frame_seen = None;
|
||||
}
|
||||
}
|
||||
@@ -205,6 +227,7 @@ impl HudChartState {
|
||||
panels,
|
||||
summary: build_summary(&self.summary_points),
|
||||
pressure_matrix: self.pressure_matrix.clone(),
|
||||
spatial_force: self.spatial_force.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,122 +1,527 @@
|
||||
use ndarray::Array2;
|
||||
|
||||
const TOTAL_PRESSURE_LOW_THRESHOLD: usize = 500;
|
||||
const COP_STABILITY_FRAMES_REQUIRED: usize = 5;
|
||||
const SENSOR_ROWS: usize = 12;
|
||||
const SENSOR_COLS: usize = 7;
|
||||
const SENSOR_COUNT: usize = SENSOR_ROWS * SENSOR_COLS;
|
||||
|
||||
const CONTACT_ENTER_TOTAL_THRESHOLD: f32 = 520.0;
|
||||
const CONTACT_ENTER_PEAK_THRESHOLD: f32 = 50.0;
|
||||
const CONTACT_EXIT_TOTAL_THRESHOLD: f32 = 260.0;
|
||||
const CONTACT_EXIT_PEAK_THRESHOLD: f32 = 28.0;
|
||||
const CONTACT_ENTER_FRAMES_REQUIRED: usize = 2;
|
||||
const CONTACT_EXIT_FRAMES_REQUIRED: usize = 8;
|
||||
|
||||
const BASELINE_IDLE_ALPHA: f32 = 0.035;
|
||||
const BASELINE_BOOTSTRAP_ALPHA: f32 = 1.0;
|
||||
const BASELINE_NOISE_FLOOR: f32 = 5.0;
|
||||
|
||||
const ACTIVE_CELL_MIN_VALUE: f32 = 18.0;
|
||||
const ACTIVE_CELL_PEAK_RATIO: f32 = 0.14;
|
||||
const MIN_ACTIVE_CELLS: usize = 3;
|
||||
|
||||
const ANCHOR_LERP_ALPHA: f32 = 0.018;
|
||||
const VECTOR_SMOOTHING_ALPHA: f32 = 0.16;
|
||||
|
||||
const REPORT_MAGNITUDE_ENTER: f32 = 0.12;
|
||||
const REPORT_MAGNITUDE_EXIT: f32 = 0.045;
|
||||
const REPORT_CONFIDENCE_ENTER: f32 = 0.14;
|
||||
const REPORT_CONFIDENCE_EXIT: f32 = 0.06;
|
||||
const REPORT_HOLD_FRAMES: usize = 10;
|
||||
|
||||
const ASYMMETRY_WEIGHT: f32 = 1.1;
|
||||
const DRIFT_WEIGHT: f32 = 0.65;
|
||||
const MOTION_WEIGHT: f32 = 0.25;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PztSpatialAnalysis {
|
||||
pub angle_deg: f32,
|
||||
pub magnitude: f32,
|
||||
pub planar_x: f32,
|
||||
pub planar_y: f32,
|
||||
pub confidence: f32,
|
||||
pub contact_active: bool,
|
||||
pub reportable: bool,
|
||||
}
|
||||
|
||||
pub struct PztProcessor {
|
||||
first_frame: Option<Vec<f32>>,
|
||||
first_contact_cop_x: Option<f32>,
|
||||
first_contact_cop_y: Option<f32>,
|
||||
contact_initialized: bool,
|
||||
total_pressure_low_counter: usize,
|
||||
baseline_frame: Option<Vec<f32>>,
|
||||
contact_active: bool,
|
||||
contact_enter_counter: usize,
|
||||
contact_exit_counter: usize,
|
||||
anchor_cop_x: Option<f32>,
|
||||
anchor_cop_y: Option<f32>,
|
||||
last_cop_x: Option<f32>,
|
||||
last_cop_y: Option<f32>,
|
||||
smoothed_x: f32,
|
||||
smoothed_y: f32,
|
||||
report_active: bool,
|
||||
report_hold_counter: usize,
|
||||
held_report: Option<PztSpatialAnalysis>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct ContactStats {
|
||||
total: f32,
|
||||
peak: f32,
|
||||
active_total: f32,
|
||||
active_cells: usize,
|
||||
min_row: usize,
|
||||
max_row: usize,
|
||||
min_col: usize,
|
||||
max_col: usize,
|
||||
cop_x: f32,
|
||||
cop_y: f32,
|
||||
asymmetry_x: f32,
|
||||
asymmetry_y: f32,
|
||||
}
|
||||
|
||||
impl PztProcessor {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
first_frame: None,
|
||||
first_contact_cop_x: None,
|
||||
first_contact_cop_y: None,
|
||||
contact_initialized: false,
|
||||
total_pressure_low_counter: 0,
|
||||
baseline_frame: None,
|
||||
contact_active: false,
|
||||
contact_enter_counter: 0,
|
||||
contact_exit_counter: 0,
|
||||
anchor_cop_x: None,
|
||||
anchor_cop_y: None,
|
||||
last_cop_x: None,
|
||||
last_cop_y: None,
|
||||
smoothed_x: 0.0,
|
||||
smoothed_y: 0.0,
|
||||
report_active: false,
|
||||
report_hold_counter: 0,
|
||||
held_report: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn subtract_baseline(&mut self, current_frame: &[f32]) -> Vec<f32> {
|
||||
if self.first_frame.is_none() {
|
||||
self.first_frame = Some(current_frame.to_vec());
|
||||
fn reset_tracking_state(&mut self) {
|
||||
self.contact_active = false;
|
||||
self.contact_enter_counter = 0;
|
||||
self.contact_exit_counter = 0;
|
||||
self.anchor_cop_x = None;
|
||||
self.anchor_cop_y = None;
|
||||
self.last_cop_x = None;
|
||||
self.last_cop_y = None;
|
||||
self.smoothed_x = 0.0;
|
||||
self.smoothed_y = 0.0;
|
||||
}
|
||||
|
||||
fn reset_report_state(&mut self) {
|
||||
self.report_active = false;
|
||||
self.report_hold_counter = 0;
|
||||
self.held_report = None;
|
||||
}
|
||||
|
||||
fn update_idle_baseline(&mut self, raw_frame: &[f32], alpha: f32) {
|
||||
match self.baseline_frame.as_mut() {
|
||||
Some(baseline) => {
|
||||
for (base, current) in baseline.iter_mut().zip(raw_frame.iter().copied()) {
|
||||
*base += (current - *base) * alpha;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
self.baseline_frame = Some(raw_frame.to_vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn subtract_baseline(&mut self, raw_frame: &[f32]) -> Vec<f32> {
|
||||
if self.baseline_frame.is_none() {
|
||||
self.update_idle_baseline(raw_frame, BASELINE_BOOTSTRAP_ALPHA);
|
||||
}
|
||||
|
||||
let baseline = self.first_frame.as_ref().unwrap();
|
||||
current_frame
|
||||
let baseline = self
|
||||
.baseline_frame
|
||||
.as_ref()
|
||||
.expect("baseline should exist after bootstrap");
|
||||
|
||||
raw_frame
|
||||
.iter()
|
||||
.zip(baseline.iter())
|
||||
.map(|(c, b)| (c - b).max(0.0))
|
||||
.map(|(raw, base)| (raw - base - BASELINE_NOISE_FLOOR).max(0.0))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn reset_cop_state(&mut self) {
|
||||
self.first_contact_cop_x = None;
|
||||
self.first_contact_cop_y = None;
|
||||
self.contact_initialized = false;
|
||||
self.total_pressure_low_counter = 0;
|
||||
fn pressure_metrics(frame: &[f32]) -> (f32, f32) {
|
||||
let total = frame.iter().sum::<f32>();
|
||||
let peak = frame.iter().copied().fold(0.0, f32::max);
|
||||
(total, peak)
|
||||
}
|
||||
|
||||
fn compute_pressure_direction(&mut self, frame: &[f32]) -> (f32, f32) {
|
||||
let frame2d = Array2::from_shape_vec((SENSOR_ROWS, SENSOR_COLS), frame.to_vec()).unwrap();
|
||||
let total_pressure: f32 = frame2d.sum();
|
||||
if total_pressure < TOTAL_PRESSURE_LOW_THRESHOLD as f32 {
|
||||
self.total_pressure_low_counter += 1;
|
||||
} else {
|
||||
self.total_pressure_low_counter = 0;
|
||||
fn is_contact_enter_frame(frame: &[f32]) -> bool {
|
||||
let (total, peak) = Self::pressure_metrics(frame);
|
||||
total >= CONTACT_ENTER_TOTAL_THRESHOLD && peak >= CONTACT_ENTER_PEAK_THRESHOLD
|
||||
}
|
||||
|
||||
fn is_contact_exit_frame(frame: &[f32]) -> bool {
|
||||
let (total, peak) = Self::pressure_metrics(frame);
|
||||
total <= CONTACT_EXIT_TOTAL_THRESHOLD || peak <= CONTACT_EXIT_PEAK_THRESHOLD
|
||||
}
|
||||
|
||||
fn inactive_analysis() -> PztSpatialAnalysis {
|
||||
PztSpatialAnalysis {
|
||||
angle_deg: 0.0,
|
||||
magnitude: 0.0,
|
||||
planar_x: 0.0,
|
||||
planar_y: 0.0,
|
||||
confidence: 0.0,
|
||||
contact_active: false,
|
||||
reportable: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn weak_contact_analysis() -> PztSpatialAnalysis {
|
||||
PztSpatialAnalysis {
|
||||
contact_active: true,
|
||||
..Self::inactive_analysis()
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_contact_stats(frame: &[f32]) -> Option<ContactStats> {
|
||||
let total = frame.iter().sum::<f32>();
|
||||
if total <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
if self.total_pressure_low_counter >= COP_STABILITY_FRAMES_REQUIRED {
|
||||
self.reset_cop_state();
|
||||
return (0.0, 0.0);
|
||||
let peak = frame.iter().copied().fold(0.0, f32::max);
|
||||
if peak <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
if total_pressure == 0.0 {
|
||||
return (0.0, 0.0);
|
||||
}
|
||||
let active_threshold = (peak * ACTIVE_CELL_PEAK_RATIO).max(ACTIVE_CELL_MIN_VALUE);
|
||||
|
||||
let mut sum_x = 0.0;
|
||||
let mut sum_y = 0.0;
|
||||
let mut active_total = 0.0;
|
||||
let mut active_cells = 0usize;
|
||||
let mut weighted_col_sum = 0.0;
|
||||
let mut weighted_row_sum = 0.0;
|
||||
let mut min_row = SENSOR_ROWS;
|
||||
let mut max_row = 0usize;
|
||||
let mut min_col = SENSOR_COLS;
|
||||
let mut max_col = 0usize;
|
||||
|
||||
for r in 0..SENSOR_ROWS {
|
||||
for c in 0..SENSOR_COLS {
|
||||
let val = frame2d[(r, c)];
|
||||
sum_x += val * c as f32;
|
||||
sum_y += val * r as f32;
|
||||
for row in 0..SENSOR_ROWS {
|
||||
for col in 0..SENSOR_COLS {
|
||||
let index = row * SENSOR_COLS + col;
|
||||
let value = frame[index];
|
||||
if value < active_threshold {
|
||||
continue;
|
||||
}
|
||||
|
||||
active_cells += 1;
|
||||
active_total += value;
|
||||
weighted_col_sum += value * col as f32;
|
||||
weighted_row_sum += value * row as f32;
|
||||
min_row = min_row.min(row);
|
||||
max_row = max_row.max(row);
|
||||
min_col = min_col.min(col);
|
||||
max_col = max_col.max(col);
|
||||
}
|
||||
}
|
||||
|
||||
let cop_x = sum_x / total_pressure;
|
||||
let cop_y = sum_y / total_pressure;
|
||||
|
||||
if !self.contact_initialized {
|
||||
self.first_contact_cop_x = Some(cop_x);
|
||||
self.first_contact_cop_y = Some(cop_y);
|
||||
self.contact_initialized = true;
|
||||
return (0.0, 0.0);
|
||||
if active_cells < MIN_ACTIVE_CELLS || active_total <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let dx = cop_x - self.first_contact_cop_x.unwrap();
|
||||
let dy = cop_y - self.first_contact_cop_y.unwrap();
|
||||
let cop_x = weighted_col_sum / active_total;
|
||||
let cop_y = weighted_row_sum / active_total;
|
||||
let bbox_center_x = (min_col + max_col) as f32 * 0.5;
|
||||
let bbox_center_y = (min_row + max_row) as f32 * 0.5;
|
||||
let half_width = ((max_col - min_col).max(1) as f32) * 0.5;
|
||||
let half_height = ((max_row - min_row).max(1) as f32) * 0.5;
|
||||
|
||||
(dx, dy)
|
||||
let mut asymmetry_x = 0.0;
|
||||
let mut asymmetry_y = 0.0;
|
||||
|
||||
for row in min_row..=max_row {
|
||||
for col in min_col..=max_col {
|
||||
let index = row * SENSOR_COLS + col;
|
||||
let value = frame[index];
|
||||
if value < active_threshold {
|
||||
continue;
|
||||
}
|
||||
|
||||
asymmetry_x += value * ((col as f32 - bbox_center_x) / half_width);
|
||||
asymmetry_y += value * ((row as f32 - bbox_center_y) / half_height);
|
||||
}
|
||||
}
|
||||
|
||||
Some(ContactStats {
|
||||
total,
|
||||
peak,
|
||||
active_total,
|
||||
active_cells,
|
||||
min_row,
|
||||
max_row,
|
||||
min_col,
|
||||
max_col,
|
||||
cop_x,
|
||||
cop_y,
|
||||
asymmetry_x: asymmetry_x / active_total,
|
||||
asymmetry_y: asymmetry_y / active_total,
|
||||
})
|
||||
}
|
||||
|
||||
fn compute_vector_angle(x: f32, y: f32) -> (f32, f32) {
|
||||
let epsilon = 1e-8;
|
||||
let mag = (x * x + y * y).sqrt();
|
||||
let mut angle = (y).atan2(x + epsilon).to_degrees();
|
||||
let magnitude = (x * x + y * y).sqrt();
|
||||
if magnitude <= f32::EPSILON {
|
||||
return (0.0, 0.0);
|
||||
}
|
||||
|
||||
let mut angle = y.atan2(x).to_degrees();
|
||||
if angle < 0.0 {
|
||||
angle += 360.0;
|
||||
}
|
||||
(angle, mag)
|
||||
|
||||
(angle, magnitude)
|
||||
}
|
||||
|
||||
fn compute_pzt_angle(px: f32, py: f32) -> (f32, f32) {
|
||||
Self::compute_vector_angle(px, -py)
|
||||
fn update_contact_state(&mut self, raw_frame: &[f32], frame: &[f32]) -> bool {
|
||||
if self.contact_active {
|
||||
if Self::is_contact_exit_frame(frame) {
|
||||
self.contact_exit_counter += 1;
|
||||
if self.contact_exit_counter >= CONTACT_EXIT_FRAMES_REQUIRED {
|
||||
self.update_idle_baseline(raw_frame, BASELINE_IDLE_ALPHA);
|
||||
self.reset_tracking_state();
|
||||
self.reset_report_state();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
self.contact_exit_counter = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if Self::is_contact_enter_frame(frame) {
|
||||
self.contact_enter_counter += 1;
|
||||
if self.contact_enter_counter >= CONTACT_ENTER_FRAMES_REQUIRED {
|
||||
self.contact_active = true;
|
||||
self.contact_enter_counter = 0;
|
||||
self.contact_exit_counter = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
self.contact_enter_counter = 0;
|
||||
self.update_idle_baseline(raw_frame, BASELINE_IDLE_ALPHA);
|
||||
false
|
||||
}
|
||||
|
||||
pub fn get_pzt_angle(&mut self, adc_data: &[f32]) -> Result<f32, &'static str> {
|
||||
if adc_data.len() != 84 {
|
||||
fn store_report(&mut self, mut analysis: PztSpatialAnalysis) -> PztSpatialAnalysis {
|
||||
analysis.reportable = true;
|
||||
self.report_active = true;
|
||||
self.report_hold_counter = 0;
|
||||
self.held_report = Some(analysis);
|
||||
analysis
|
||||
}
|
||||
|
||||
fn hold_or_drop_report(&mut self) -> PztSpatialAnalysis {
|
||||
if self.report_active && self.report_hold_counter < REPORT_HOLD_FRAMES {
|
||||
self.report_hold_counter += 1;
|
||||
if let Some(mut held) = self.held_report {
|
||||
held.reportable = true;
|
||||
return held;
|
||||
}
|
||||
}
|
||||
|
||||
self.reset_report_state();
|
||||
Self::weak_contact_analysis()
|
||||
}
|
||||
|
||||
fn stabilize_report(&mut self, analysis: PztSpatialAnalysis) -> PztSpatialAnalysis {
|
||||
if !analysis.contact_active {
|
||||
self.reset_report_state();
|
||||
return analysis;
|
||||
}
|
||||
|
||||
let can_enter = analysis.magnitude >= REPORT_MAGNITUDE_ENTER
|
||||
&& analysis.confidence >= REPORT_CONFIDENCE_ENTER;
|
||||
let can_stay = analysis.magnitude >= REPORT_MAGNITUDE_EXIT
|
||||
&& analysis.confidence >= REPORT_CONFIDENCE_EXIT;
|
||||
|
||||
if self.report_active {
|
||||
if can_stay {
|
||||
return self.store_report(analysis);
|
||||
}
|
||||
|
||||
return self.hold_or_drop_report();
|
||||
}
|
||||
|
||||
if can_enter {
|
||||
return self.store_report(analysis);
|
||||
}
|
||||
|
||||
analysis
|
||||
}
|
||||
|
||||
pub fn get_pzt_analysis(
|
||||
&mut self,
|
||||
adc_data: &[f32],
|
||||
) -> Result<PztSpatialAnalysis, &'static str> {
|
||||
if adc_data.len() != SENSOR_COUNT {
|
||||
return Err("ADC data length must be 84");
|
||||
}
|
||||
|
||||
let baseline = self.subtract_baseline(adc_data);
|
||||
let (dx, dy) = self.compute_pressure_direction(&baseline);
|
||||
let (angle, _) = Self::compute_pzt_angle(dx, dy);
|
||||
let baseline_subtracted = self.subtract_baseline(adc_data);
|
||||
if !self.update_contact_state(adc_data, &baseline_subtracted) {
|
||||
return Ok(Self::inactive_analysis());
|
||||
}
|
||||
|
||||
Ok(angle)
|
||||
let Some(stats) = Self::compute_contact_stats(&baseline_subtracted) else {
|
||||
return Ok(self.stabilize_report(Self::weak_contact_analysis()));
|
||||
};
|
||||
|
||||
let Some(anchor_x) = self.anchor_cop_x else {
|
||||
self.anchor_cop_x = Some(stats.cop_x);
|
||||
self.anchor_cop_y = Some(stats.cop_y);
|
||||
self.last_cop_x = Some(stats.cop_x);
|
||||
self.last_cop_y = Some(stats.cop_y);
|
||||
|
||||
return Ok(self.stabilize_report(Self::weak_contact_analysis()));
|
||||
};
|
||||
let anchor_y = self.anchor_cop_y.unwrap_or(stats.cop_y);
|
||||
let last_x = self.last_cop_x.unwrap_or(stats.cop_x);
|
||||
let last_y = self.last_cop_y.unwrap_or(stats.cop_y);
|
||||
|
||||
let drift_x = stats.cop_x - anchor_x;
|
||||
let drift_y = stats.cop_y - anchor_y;
|
||||
let motion_x = stats.cop_x - last_x;
|
||||
let motion_y = stats.cop_y - last_y;
|
||||
|
||||
let combined_x = stats.asymmetry_x * ASYMMETRY_WEIGHT
|
||||
+ drift_x * DRIFT_WEIGHT
|
||||
+ motion_x * MOTION_WEIGHT;
|
||||
let combined_y = stats.asymmetry_y * ASYMMETRY_WEIGHT
|
||||
+ drift_y * DRIFT_WEIGHT
|
||||
+ motion_y * MOTION_WEIGHT;
|
||||
|
||||
self.smoothed_x += (combined_x - self.smoothed_x) * VECTOR_SMOOTHING_ALPHA;
|
||||
self.smoothed_y += (combined_y - self.smoothed_y) * VECTOR_SMOOTHING_ALPHA;
|
||||
|
||||
self.anchor_cop_x = Some(anchor_x + drift_x * ANCHOR_LERP_ALPHA);
|
||||
self.anchor_cop_y = Some(anchor_y + drift_y * ANCHOR_LERP_ALPHA);
|
||||
self.last_cop_x = Some(stats.cop_x);
|
||||
self.last_cop_y = Some(stats.cop_y);
|
||||
|
||||
let planar_x = self.smoothed_x;
|
||||
let planar_y = -self.smoothed_y;
|
||||
let (angle_deg, magnitude) = Self::compute_vector_angle(planar_x, planar_y);
|
||||
|
||||
let active_span_rows = (stats.max_row - stats.min_row + 1) as f32 / SENSOR_ROWS as f32;
|
||||
let active_span_cols = (stats.max_col - stats.min_col + 1) as f32 / SENSOR_COLS as f32;
|
||||
let activity = (stats.active_cells as f32 / SENSOR_COUNT as f32).clamp(0.0, 1.0);
|
||||
let span = ((active_span_rows + active_span_cols) * 0.5).clamp(0.0, 1.0);
|
||||
let pressure_ratio = (stats.active_total / stats.total.max(1.0)).clamp(0.0, 1.0);
|
||||
let peak_ratio =
|
||||
(stats.peak / (stats.total / stats.active_cells as f32 + 1.0)).clamp(0.0, 1.0);
|
||||
let confidence =
|
||||
((activity * 0.35) + (span * 0.2) + (pressure_ratio * 0.3) + (peak_ratio * 0.15))
|
||||
.clamp(0.0, 1.0);
|
||||
|
||||
Ok(self.stabilize_report(PztSpatialAnalysis {
|
||||
angle_deg,
|
||||
magnitude,
|
||||
planar_x,
|
||||
planar_y,
|
||||
confidence,
|
||||
contact_active: true,
|
||||
reportable: false,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn get_pzt_angle(&mut self, adc_data: &[f32]) -> Result<f32, &'static str> {
|
||||
Ok(self.get_pzt_analysis(adc_data)?.angle_deg)
|
||||
}
|
||||
|
||||
pub fn should_report(analysis: &PztSpatialAnalysis) -> bool {
|
||||
analysis.reportable
|
||||
}
|
||||
|
||||
pub fn reset_baseline(&mut self) {
|
||||
self.first_frame = None;
|
||||
self.reset_cop_state();
|
||||
self.baseline_frame = None;
|
||||
self.reset_tracking_state();
|
||||
self.reset_report_state();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{PztProcessor, SENSOR_COLS, SENSOR_ROWS};
|
||||
|
||||
fn index(row: usize, col: usize) -> usize {
|
||||
row * SENSOR_COLS + col
|
||||
}
|
||||
|
||||
fn make_frame(active: &[(usize, usize, f32)]) -> [f32; SENSOR_ROWS * SENSOR_COLS] {
|
||||
let mut frame = [0.0; SENSOR_ROWS * SENSOR_COLS];
|
||||
for (row, col, value) in active {
|
||||
frame[index(*row, *col)] = *value;
|
||||
}
|
||||
frame
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idle_frame_does_not_report_contact() {
|
||||
let mut processor = PztProcessor::new();
|
||||
let frame = [0.0; SENSOR_ROWS * SENSOR_COLS];
|
||||
let analysis = processor.get_pzt_analysis(&frame).unwrap();
|
||||
assert!(!analysis.contact_active);
|
||||
assert!(!analysis.reportable);
|
||||
assert_eq!(analysis.magnitude, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_heavy_contact_reports_rightward_angle_after_confirmation() {
|
||||
let mut processor = PztProcessor::new();
|
||||
let baseline = [0.0; SENSOR_ROWS * SENSOR_COLS];
|
||||
let contact = make_frame(&[
|
||||
(5, 2, 120.0),
|
||||
(5, 3, 180.0),
|
||||
(5, 4, 280.0),
|
||||
(6, 2, 110.0),
|
||||
(6, 3, 170.0),
|
||||
(6, 4, 260.0),
|
||||
(7, 2, 100.0),
|
||||
(7, 3, 150.0),
|
||||
(7, 4, 240.0),
|
||||
]);
|
||||
|
||||
let _ = processor.get_pzt_analysis(&baseline).unwrap();
|
||||
|
||||
let mut analysis = processor.get_pzt_analysis(&contact).unwrap();
|
||||
for _ in 0..8 {
|
||||
analysis = processor.get_pzt_analysis(&contact).unwrap();
|
||||
}
|
||||
|
||||
assert!(analysis.contact_active);
|
||||
assert!(analysis.reportable);
|
||||
assert!(analysis.magnitude > 0.0);
|
||||
assert!(analysis.angle_deg <= 45.0 || analysis.angle_deg >= 315.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn report_stays_active_through_short_weak_gap() {
|
||||
let mut processor = PztProcessor::new();
|
||||
let baseline = [0.0; SENSOR_ROWS * SENSOR_COLS];
|
||||
let contact = make_frame(&[
|
||||
(5, 2, 120.0),
|
||||
(5, 3, 180.0),
|
||||
(5, 4, 280.0),
|
||||
(6, 2, 110.0),
|
||||
(6, 3, 170.0),
|
||||
(6, 4, 260.0),
|
||||
(7, 2, 100.0),
|
||||
(7, 3, 150.0),
|
||||
(7, 4, 240.0),
|
||||
]);
|
||||
let weak = make_frame(&[(5, 3, 55.0), (5, 4, 60.0), (6, 3, 50.0), (6, 4, 58.0)]);
|
||||
|
||||
let _ = processor.get_pzt_analysis(&baseline).unwrap();
|
||||
for _ in 0..10 {
|
||||
let _ = processor.get_pzt_analysis(&contact).unwrap();
|
||||
}
|
||||
|
||||
let analysis = processor.get_pzt_analysis(&weak).unwrap();
|
||||
assert!(analysis.reportable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
use std::io;
|
||||
use std::os::unix::io::RawFd;
|
||||
use tokio::io::unix::AsyncFd;
|
||||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
||||
|
||||
/// A wrapper around a raw file descriptor that implements AsyncRead + AsyncWrite.
|
||||
/// Uses tokio's AsyncFd to properly integrate with the async reactor.
|
||||
/// Used on Android to wrap USB device file descriptors obtained from the USB Host API.
|
||||
pub struct RawFdStream {
|
||||
inner: AsyncFd<RawFd>,
|
||||
}
|
||||
|
||||
impl RawFdStream {
|
||||
pub fn new(fd: RawFd) -> io::Result<Self> {
|
||||
if fd < 0 {
|
||||
return Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid fd"));
|
||||
}
|
||||
|
||||
// Set non-blocking
|
||||
unsafe {
|
||||
let flags = libc::fcntl(fd, libc::F_GETFL);
|
||||
if flags < 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
if libc::fcntl(fd, libc::F_SETFL, flags | libc::O_NONBLOCK) < 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
|
||||
let inner = AsyncFd::new(fd)?;
|
||||
Ok(Self { inner })
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RawFdStream {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
libc::close(*self.inner.get_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncRead for RawFdStream {
|
||||
fn poll_read(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &mut ReadBuf<'_>,
|
||||
) -> std::task::Poll<io::Result<()>> {
|
||||
loop {
|
||||
let mut guard = match self.inner.poll_read_ready(cx) {
|
||||
std::task::Poll::Ready(Ok(guard)) => guard,
|
||||
std::task::Poll::Ready(Err(e)) => return std::task::Poll::Ready(Err(e)),
|
||||
std::task::Poll::Pending => return std::task::Poll::Pending,
|
||||
};
|
||||
|
||||
let unfilled = buf.initialize_unfilled();
|
||||
let result = unsafe {
|
||||
libc::read(
|
||||
*self.inner.get_ref(),
|
||||
unfilled.as_mut_ptr() as *mut libc::c_void,
|
||||
unfilled.len(),
|
||||
)
|
||||
};
|
||||
|
||||
if result < 0 {
|
||||
let err = io::Error::last_os_error();
|
||||
if err.kind() == io::ErrorKind::WouldBlock {
|
||||
guard.clear_ready();
|
||||
continue;
|
||||
}
|
||||
return std::task::Poll::Ready(Err(err));
|
||||
}
|
||||
|
||||
buf.advance(result as usize);
|
||||
return std::task::Poll::Ready(Ok(()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncWrite for RawFdStream {
|
||||
fn poll_write(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> std::task::Poll<io::Result<usize>> {
|
||||
loop {
|
||||
let mut guard = match self.inner.poll_write_ready(cx) {
|
||||
std::task::Poll::Ready(Ok(guard)) => guard,
|
||||
std::task::Poll::Ready(Err(e)) => return std::task::Poll::Ready(Err(e)),
|
||||
std::task::Poll::Pending => return std::task::Poll::Pending,
|
||||
};
|
||||
|
||||
let result = unsafe {
|
||||
libc::write(
|
||||
*self.inner.get_ref(),
|
||||
buf.as_ptr() as *const libc::c_void,
|
||||
buf.len(),
|
||||
)
|
||||
};
|
||||
|
||||
if result < 0 {
|
||||
let err = io::Error::last_os_error();
|
||||
if err.kind() == io::ErrorKind::WouldBlock {
|
||||
guard.clear_ready();
|
||||
continue;
|
||||
}
|
||||
return std::task::Poll::Ready(Err(err));
|
||||
}
|
||||
|
||||
return std::task::Poll::Ready(Ok(result as usize));
|
||||
}
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
_cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<io::Result<()>> {
|
||||
std::task::Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
_cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<io::Result<()>> {
|
||||
std::task::Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
#[cfg(feature = "devkit")]
|
||||
use crate::devkit::{proto::SensorFrame, DevKitState};
|
||||
use crate::serial_core::codec::Codec;
|
||||
use crate::serial_core::codecs::tactile_a::TactileACodec;
|
||||
use crate::serial_core::frame::{FrameHandler, TactileAFrame, TestFrame};
|
||||
use crate::serial_core::model::{HudChartState, HudPacket};
|
||||
use crate::serial_core::model::{HudChartState, HudPacket, HudSpatialForce};
|
||||
#[cfg(feature = "multi-dim")]
|
||||
use crate::serial_core::multi_dim_force::PztProcessor;
|
||||
use crate::serial_core::record::Recording;
|
||||
use crate::serial_core::record::{FrameTiming, RecordedFrame};
|
||||
#[cfg(feature = "devkit")]
|
||||
use crate::devkit::{proto::SensorFrame, DevKitState};
|
||||
use anyhow::Result;
|
||||
use log::debug;
|
||||
use std::future::pending;
|
||||
@@ -15,12 +15,11 @@ use std::future::pending;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
use tauri::{AppHandle, Emitter};
|
||||
#[cfg(feature = "devkit")]
|
||||
use tauri::Manager;
|
||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||
use tauri::{AppHandle, Emitter};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::time::{self, Duration, MissedTickBehavior};
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use tokio_serial::SerialStream;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
@@ -34,6 +33,7 @@ pub enum PollMode<F> {
|
||||
struct PendingSubFrame<F> {
|
||||
frame: F,
|
||||
values: Vec<i32>,
|
||||
spatial_force: Option<HudSpatialForce>,
|
||||
}
|
||||
|
||||
pub trait SerialFrame: Clone + Send + 'static {
|
||||
@@ -172,7 +172,6 @@ impl PollRequester<TactileAFrame> for TactileAPollRequester {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub async fn run_serial<C, H, T, F>(
|
||||
app: AppHandle,
|
||||
port: SerialStream,
|
||||
@@ -203,7 +202,7 @@ where
|
||||
|
||||
pub async fn run_serial_with_poll<C, H, T, F>(
|
||||
app: AppHandle,
|
||||
mut port: impl AsyncRead + AsyncWrite + Unpin,
|
||||
mut port: SerialStream,
|
||||
mut codec: C,
|
||||
mut handler: H,
|
||||
session_started_at: Instant,
|
||||
@@ -268,6 +267,7 @@ where
|
||||
let display_values = build_display_values(
|
||||
&mut chart_state,
|
||||
pending.values.as_slice(),
|
||||
pending.spatial_force,
|
||||
);
|
||||
|
||||
if let Some(packet) = pending
|
||||
@@ -311,11 +311,22 @@ where
|
||||
drop(record);
|
||||
|
||||
if let Some(vals) = decode_res {
|
||||
let mut spatial_force = None;
|
||||
#[cfg(feature = "multi-dim")]
|
||||
{
|
||||
let pzt_values = vals.iter().map(|value| *value as f32).collect::<Vec<f32>>();
|
||||
if let Ok(angle) = pzt_processor.get_pzt_angle(&pzt_values) {
|
||||
// debug!("pzt angle: {:.2}", angle);
|
||||
if let Ok(analysis) = pzt_processor.get_pzt_analysis(&pzt_values) {
|
||||
debug!(
|
||||
"spatial force: angle={:.2}°, magnitude={:.2}, dx={:.2}, dy={:.2}",
|
||||
analysis.angle_deg, analysis.magnitude, analysis.planar_x, analysis.planar_y
|
||||
);
|
||||
if PztProcessor::should_report(&analysis) {
|
||||
spatial_force = Some(HudSpatialForce {
|
||||
angle_deg: analysis.angle_deg,
|
||||
magnitude: analysis.magnitude,
|
||||
confidence: analysis.confidence,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "devkit")]
|
||||
@@ -328,6 +339,7 @@ where
|
||||
pending_sub_frame = Some(PendingSubFrame {
|
||||
frame: frame.clone(),
|
||||
values: vals,
|
||||
spatial_force,
|
||||
});
|
||||
} else if let Some(packet) = frame.to_hud_packet(&mut chart_state, None) {
|
||||
app.emit("hud_stream", packet)?;
|
||||
@@ -339,11 +351,16 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_display_values(chart_state: &mut HudChartState, values: &[i32]) -> Option<Vec<i32>> {
|
||||
fn build_display_values(
|
||||
chart_state: &mut HudChartState,
|
||||
values: &[i32],
|
||||
spatial_force: Option<HudSpatialForce>,
|
||||
) -> Option<Vec<i32>> {
|
||||
let summary = values.iter().copied().sum::<i32>();
|
||||
let force = raw_to_g1(summary as u32);
|
||||
chart_state.record_summary(force as f32);
|
||||
chart_state.record_pressure_matrix(values);
|
||||
chart_state.record_spatial_force(spatial_force);
|
||||
Some(vec![summary])
|
||||
}
|
||||
|
||||
|
||||
@@ -45,5 +45,15 @@
|
||||
"resources/je-skin-devkit-server.exe"
|
||||
]
|
||||
},
|
||||
"plugins": {}
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"windows": {
|
||||
"installMode": "passive"
|
||||
},
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDkwODM1QkFEODI2NkZENgpSV1RXYnliWXVqVUlDUVRxbjlseDNDNjhQTGpDYis4TEZMeUk2WVhiMEhTRWJhN3hGRnQ3TTJtcwo=",
|
||||
"endpoints": [
|
||||
"https://je-skin.cn-nb1.rains3.com/latest.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,21 @@
|
||||
import { fly } from "svelte/transition";
|
||||
import { DEFAULT_PRESSURE_RANGE_MAX, DEFAULT_PRESSURE_RANGE_MIN } from "$lib/config/pressure-range";
|
||||
import ConfigPanel from "$lib/components/ConfigPanel.svelte";
|
||||
import ModelStage from "$lib/components/ModelStage.svelte";
|
||||
import NeonBreakoutArena from "$lib/components/NeonBreakoutArena.svelte";
|
||||
import PressureMatrixViewer from "$lib/components/PressureMatrixViewer.svelte";
|
||||
import SignalChart from "$lib/components/SignalChart.svelte";
|
||||
import SpatialForcePanel from "$lib/components/SpatialForcePanel.svelte";
|
||||
import SummaryCurve from "$lib/components/SummaryCurve.svelte";
|
||||
import type {
|
||||
HudColorMapOption,
|
||||
HudSignalPanel,
|
||||
HudSpatialForce,
|
||||
HudSummary,
|
||||
LocaleCode,
|
||||
MatrixDisplayMode,
|
||||
PressureColorMapPreset
|
||||
PressureColorMapPreset,
|
||||
StageViewMode
|
||||
} from "$lib/types/hud";
|
||||
|
||||
export let locale: LocaleCode = "zh-CN";
|
||||
@@ -24,6 +28,8 @@
|
||||
export let rightPanels: HudSignalPanel[] = [];
|
||||
export let summary: HudSummary;
|
||||
export let pressureMatrix: number[] | null = null;
|
||||
export let spatialForce: HudSpatialForce | null = null;
|
||||
export let devkitSpatialForce: HudSpatialForce | null = null;
|
||||
export let showConfigPanel = false;
|
||||
export let configPanelTitle = "";
|
||||
export let configPanelHint = "";
|
||||
@@ -41,6 +47,8 @@
|
||||
export let rangeMax = DEFAULT_PRESSURE_RANGE_MAX;
|
||||
export let colorMapPreset: PressureColorMapPreset = "emerald";
|
||||
export let matrixDisplayMode: MatrixDisplayMode = "dots";
|
||||
export let stageViewMode: StageViewMode = "webgl";
|
||||
export let modelUrl = "/models/je-skin-model.glb";
|
||||
export let replaySectionLabel = "";
|
||||
export let replayPlayLabel = "";
|
||||
export let replayPauseLabel = "";
|
||||
@@ -84,6 +92,7 @@
|
||||
$: summaryCurveVisible = summary.points.length > 0 && summary.points.some((value) => Number.isFinite(value) && Math.abs(value) >= 0.0001);
|
||||
$: splitMatrixTitle = locale === "zh-CN" ? "数字矩阵" : "Matrix";
|
||||
$: splitMatrixHint = locale === "zh-CN" ? "实时压力数据 / 数字矩阵" : "Live pressure matrix";
|
||||
$: isModelStage = stageViewMode === "model3d";
|
||||
|
||||
function toPxNumber(rawValue: string): number {
|
||||
const value = Number.parseFloat(rawValue);
|
||||
@@ -176,7 +185,13 @@
|
||||
bind:this={stagePlaneEl}
|
||||
style="--panel-zone-top-dyn: {panelZoneTopPx}px; --rail-scale-left: {leftRailScale}; --rail-scale-right: {rightRailScale};"
|
||||
>
|
||||
{#if showPrecisionTestPanel}
|
||||
{#if isModelStage}
|
||||
<div class="canvas-wrap">
|
||||
{#key modelUrl}
|
||||
<ModelStage {locale} {modelUrl} />
|
||||
{/key}
|
||||
</div>
|
||||
{:else if showPrecisionTestPanel}
|
||||
<div class="split-game-wrap">
|
||||
<section class="split-panel split-matrix-panel">
|
||||
<header class="split-panel-head">
|
||||
@@ -232,7 +247,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if showConfigPanel && !showPrecisionTestPanel}
|
||||
{#if showConfigPanel && !showPrecisionTestPanel && !isModelStage}
|
||||
<div class="config-panel-wrap">
|
||||
<ConfigPanel
|
||||
bind:matrixRows
|
||||
@@ -254,7 +269,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if !showPrecisionTestPanel}
|
||||
{#if !showPrecisionTestPanel && !isModelStage}
|
||||
<div class="panel-zone" bind:this={panelZoneEl}>
|
||||
<aside class="side-rail left-rail">
|
||||
<div class="rail-stack" bind:this={leftStackEl}>
|
||||
@@ -303,6 +318,42 @@
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<div
|
||||
class="panel-motion-shell"
|
||||
in:fly={{ x: 180, duration: 340, opacity: 0.08, easing: cubicOut }}
|
||||
out:fly={{ x: 180, duration: 280, opacity: 0.06, easing: cubicIn }}
|
||||
>
|
||||
<SpatialForcePanel
|
||||
{spatialForce}
|
||||
{locale}
|
||||
side="right"
|
||||
panelIndex={rightPanels.length}
|
||||
panelCode="ALG"
|
||||
panelTitle={locale === "zh-CN" ? "本地切向力" : "Local Tangential"}
|
||||
badgeLabel={locale === "zh-CN" ? "算法" : "ALGO"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="panel-motion-shell"
|
||||
in:fly={{ x: 180, duration: 340, opacity: 0.08, easing: cubicOut }}
|
||||
out:fly={{ x: 180, duration: 280, opacity: 0.06, easing: cubicIn }}
|
||||
>
|
||||
<SpatialForcePanel
|
||||
spatialForce={devkitSpatialForce}
|
||||
{locale}
|
||||
side="right"
|
||||
panelIndex={rightPanels.length + 1}
|
||||
panelCode="DKT"
|
||||
panelTitle={locale === "zh-CN" ? "DevKit 切向力" : "DevKit Tangential"}
|
||||
badgeLabel="DEVKIT"
|
||||
badgeTone="lime"
|
||||
showMetrics={false}
|
||||
requireMagnitude={false}
|
||||
compactMetaText={locale === "zh-CN" ? "等待 DevKit 角度流" : "Waiting for DevKit angle"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if summaryCurveVisible && summarySide === "right"}
|
||||
<div
|
||||
class="panel-motion-shell"
|
||||
@@ -326,7 +377,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if replayHasData && !showPrecisionTestPanel}
|
||||
{#if replayHasData && !showPrecisionTestPanel && !isModelStage}
|
||||
<aside class="replay-floating-panel" class:is-left={replaySide === "left"} class:is-right={replaySide === "right"}>
|
||||
<div class="replay-panel-head">
|
||||
<div class="replay-panel-title-group">
|
||||
@@ -364,7 +415,7 @@
|
||||
</aside>
|
||||
{/if}
|
||||
|
||||
{#if !showPrecisionTestPanel}
|
||||
{#if !showPrecisionTestPanel && !isModelStage}
|
||||
<div class="stage-bottom-overlay">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
HudNoticeTone,
|
||||
LocaleCode,
|
||||
MatrixDisplayMode,
|
||||
StageViewMode,
|
||||
WindowControlAction
|
||||
} from "$lib/types/hud";
|
||||
|
||||
@@ -34,6 +35,10 @@
|
||||
export let matrixViewNumericLabel = "";
|
||||
export let matrixViewDotsLabel = "";
|
||||
export let matrixDisplayMode: MatrixDisplayMode = "dots";
|
||||
export let stageModeLabel = "";
|
||||
export let stageModeWebglLabel = "";
|
||||
export let stageModeModelLabel = "";
|
||||
export let stageViewMode: StageViewMode = "webgl";
|
||||
export let connectActionLabel = "";
|
||||
export let disconnectActionLabel = "";
|
||||
export let exportActionLabel = "";
|
||||
@@ -56,6 +61,7 @@
|
||||
localechange: LocaleCode;
|
||||
configlink: string;
|
||||
matrixdisplaytoggle: boolean;
|
||||
stagemodechange: StageViewMode;
|
||||
portchange: string;
|
||||
serialrefresh: void;
|
||||
serialconnect: string;
|
||||
@@ -105,6 +111,10 @@
|
||||
dispatch("matrixdisplaytoggle", matrixDisplayMode !== "dots");
|
||||
}
|
||||
|
||||
function emitStageModeChange(nextMode: StageViewMode): void {
|
||||
dispatch("stagemodechange", nextMode);
|
||||
}
|
||||
|
||||
function emitPortChange(event: Event): void {
|
||||
const target = event.currentTarget as HTMLSelectElement;
|
||||
dispatch("portchange", target.value);
|
||||
@@ -217,6 +227,28 @@
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="stage-mode-switch" aria-label={stageModeLabel}>
|
||||
<span class="stage-mode-label">{stageModeLabel}</span>
|
||||
<div class="stage-mode-options" role="group" aria-label={stageModeLabel}>
|
||||
<button
|
||||
type="button"
|
||||
class="stage-mode-btn"
|
||||
class:is-active={stageViewMode === "webgl"}
|
||||
on:click={() => emitStageModeChange("webgl")}
|
||||
>
|
||||
{stageModeWebglLabel}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="stage-mode-btn"
|
||||
class:is-active={stageViewMode === "model3d"}
|
||||
on:click={() => emitStageModeChange("model3d")}
|
||||
>
|
||||
{stageModeModelLabel}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="state-card" aria-label={connectionLabel}>
|
||||
<span class="state-dot" class:ok={connectionTone === "ok"} class:warn={connectionTone === "warn"}></span>
|
||||
<span class="state-label">{connectionLabel}</span>
|
||||
@@ -460,12 +492,6 @@
|
||||
color: rgb(var(--hud-orange-rgb) / 0.96);
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.window-controls {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.control-bar {
|
||||
display: grid;
|
||||
gap: 0.45rem;
|
||||
@@ -491,7 +517,8 @@
|
||||
background: var(--panel-surface);
|
||||
}
|
||||
|
||||
.matrix-switch-wrap {
|
||||
.matrix-switch-wrap,
|
||||
.stage-mode-switch {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
@@ -502,7 +529,8 @@
|
||||
background: var(--panel-surface);
|
||||
}
|
||||
|
||||
.matrix-switch-label {
|
||||
.matrix-switch-label,
|
||||
.stage-mode-label {
|
||||
color: var(--panel-text-dim);
|
||||
font-size: 0.66rem;
|
||||
letter-spacing: 0.08em;
|
||||
@@ -593,6 +621,45 @@
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.stage-mode-options {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.18rem;
|
||||
padding: 0.16rem;
|
||||
border: 1px solid rgb(var(--hud-border-rgb) / 0.24);
|
||||
border-radius: 999px;
|
||||
background: rgb(var(--hud-surface-deep-rgb) / 0.8);
|
||||
}
|
||||
|
||||
.stage-mode-btn {
|
||||
min-block-size: 1.38rem;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 999px;
|
||||
padding: 0.18rem 0.54rem;
|
||||
background: transparent;
|
||||
color: rgb(var(--hud-text-dim-rgb) / 0.88);
|
||||
font: inherit;
|
||||
font-size: 0.7rem;
|
||||
letter-spacing: 0.04em;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
border-color 180ms ease,
|
||||
background-color 180ms ease,
|
||||
color 180ms ease,
|
||||
box-shadow 180ms ease;
|
||||
}
|
||||
|
||||
.stage-mode-btn:hover {
|
||||
color: rgb(var(--hud-text-main-rgb) / 0.96);
|
||||
}
|
||||
|
||||
.stage-mode-btn.is-active {
|
||||
border-color: rgb(var(--hud-cyan-rgb) / 0.42);
|
||||
background: rgb(var(--hud-cyan-rgb) / 0.14);
|
||||
color: rgb(var(--hud-text-main-rgb) / 0.98);
|
||||
box-shadow: 0 0 12px rgb(var(--hud-cyan-rgb) / 0.1);
|
||||
}
|
||||
|
||||
.state-dot {
|
||||
inline-size: 0.55rem;
|
||||
block-size: 0.55rem;
|
||||
@@ -1222,4 +1289,4 @@
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
469
src/lib/components/ModelStage.svelte
Normal file
@@ -0,0 +1,469 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import * as THREE from "three";
|
||||
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
||||
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
||||
import type { GLTF } from "three/examples/jsm/loaders/GLTFLoader.js";
|
||||
import type { LocaleCode } from "$lib/types/hud";
|
||||
|
||||
type ModelLoadState = "loading" | "ready" | "missing" | "error";
|
||||
|
||||
export let locale: LocaleCode = "zh-CN";
|
||||
export let modelUrl = "/models/je-skin-model.glb";
|
||||
|
||||
let rootEl: HTMLDivElement | undefined;
|
||||
let canvasEl: HTMLCanvasElement | undefined;
|
||||
let loadState: ModelLoadState = "loading";
|
||||
let loadProgress = 0;
|
||||
let loadError = "";
|
||||
|
||||
const FLOOR_Y = -1.15;
|
||||
const MODEL_FLOOR_CLEARANCE = 0.035;
|
||||
const MODEL_TARGET_HEIGHT = 8.4;
|
||||
const MODEL_MIN_SCALE = 0.02;
|
||||
const MODEL_MAX_SCALE = 80;
|
||||
const CAMERA_DISTANCE_FACTOR = 1.35;
|
||||
const CAMERA_DISTANCE_MIN = 7.5;
|
||||
const CAMERA_DISTANCE_MAX = 24;
|
||||
|
||||
$: copy =
|
||||
locale === "zh-CN"
|
||||
? {
|
||||
title: "3D 模型舱",
|
||||
subtitle: "Dark Grid / Future Lab",
|
||||
loading: "正在加载模型",
|
||||
ready: "模型已载入",
|
||||
missing: "等待模型文件",
|
||||
error: "模型加载失败",
|
||||
modelPath: "模型路径",
|
||||
hint: "请使用 glTF 2.0 的 .glb/.gltf;旧版 glTF 1.0 需要先转换"
|
||||
}
|
||||
: {
|
||||
title: "3D Model Bay",
|
||||
subtitle: "Dark Grid / Future Lab",
|
||||
loading: "Loading model",
|
||||
ready: "Model loaded",
|
||||
missing: "Waiting for model file",
|
||||
error: "Model load failed",
|
||||
modelPath: "Model path",
|
||||
hint: "Use glTF 2.0 .glb/.gltf assets; older glTF 1.0 files need conversion first"
|
||||
};
|
||||
$: statusText =
|
||||
loadState === "ready"
|
||||
? copy.ready
|
||||
: loadState === "missing"
|
||||
? copy.missing
|
||||
: loadState === "error"
|
||||
? copy.error
|
||||
: `${copy.loading} ${Math.round(loadProgress)}%`;
|
||||
|
||||
function disposeObject3D(object: THREE.Object3D): void {
|
||||
object.traverse((child) => {
|
||||
const mesh = child as THREE.Mesh;
|
||||
if (mesh.geometry) {
|
||||
mesh.geometry.dispose();
|
||||
}
|
||||
|
||||
const material = mesh.material;
|
||||
if (Array.isArray(material)) {
|
||||
for (const item of material) {
|
||||
item.dispose();
|
||||
}
|
||||
} else if (material) {
|
||||
material.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildPlaceholderModel(): THREE.Group {
|
||||
const group = new THREE.Group();
|
||||
const cyan = new THREE.Color(0x5ee7ff);
|
||||
const lime = new THREE.Color(0xa6ff7a);
|
||||
|
||||
const platform = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(5.8, 6.7, 0.36, 96),
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x0c1824,
|
||||
emissive: 0x07131f,
|
||||
metalness: 0.62,
|
||||
roughness: 0.34
|
||||
})
|
||||
);
|
||||
platform.position.y = 0.18;
|
||||
group.add(platform);
|
||||
|
||||
const ringGeometry = new THREE.TorusGeometry(4.35, 0.035, 10, 128);
|
||||
const ringMaterial = new THREE.MeshBasicMaterial({ color: cyan, transparent: true, opacity: 0.78 });
|
||||
for (let index = 0; index < 3; index += 1) {
|
||||
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
|
||||
ring.position.y = 0.52 + index * 0.52;
|
||||
ring.rotation.x = Math.PI / 2;
|
||||
group.add(ring);
|
||||
}
|
||||
|
||||
const coreMaterial = new THREE.MeshStandardMaterial({
|
||||
color: 0x1b2a38,
|
||||
emissive: 0x0a2632,
|
||||
metalness: 0.48,
|
||||
roughness: 0.42,
|
||||
transparent: true,
|
||||
opacity: 0.72
|
||||
});
|
||||
const core = new THREE.Mesh(new THREE.BoxGeometry(2.2, 3.4, 1.1), coreMaterial);
|
||||
core.position.y = 2.4;
|
||||
core.rotation.y = -0.36;
|
||||
group.add(core);
|
||||
|
||||
const sensorMaterial = new THREE.MeshBasicMaterial({ color: lime, transparent: true, opacity: 0.88 });
|
||||
for (let index = 0; index < 7; index += 1) {
|
||||
const bead = new THREE.Mesh(new THREE.SphereGeometry(0.13, 18, 18), sensorMaterial);
|
||||
bead.position.set(-0.72 + index * 0.24, 3.18 + Math.sin(index * 0.72) * 0.18, 0.6);
|
||||
group.add(bead);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
function clamp(value: number, min: number, max: number): number {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
function normalizeObjectToStage(object: THREE.Object3D): THREE.Box3 {
|
||||
object.updateMatrixWorld(true);
|
||||
let bounds = new THREE.Box3().setFromObject(object);
|
||||
const size = bounds.getSize(new THREE.Vector3());
|
||||
const currentHeight = Math.max(size.y, 0.001);
|
||||
const scale = clamp(MODEL_TARGET_HEIGHT / currentHeight, MODEL_MIN_SCALE, MODEL_MAX_SCALE);
|
||||
|
||||
object.scale.multiplyScalar(scale);
|
||||
object.updateMatrixWorld(true);
|
||||
|
||||
bounds = new THREE.Box3().setFromObject(object);
|
||||
const center = bounds.getCenter(new THREE.Vector3());
|
||||
object.position.x -= center.x;
|
||||
object.position.z -= center.z;
|
||||
object.position.y += FLOOR_Y + MODEL_FLOOR_CLEARANCE - bounds.min.y;
|
||||
object.updateMatrixWorld(true);
|
||||
|
||||
return new THREE.Box3().setFromObject(object);
|
||||
}
|
||||
|
||||
function frameObject(object: THREE.Object3D, camera: THREE.PerspectiveCamera, controls: OrbitControls): void {
|
||||
const bounds = normalizeObjectToStage(object);
|
||||
const size = bounds.getSize(new THREE.Vector3());
|
||||
const maxAxis = Math.max(size.x, size.y, size.z, 1);
|
||||
const distance = clamp(maxAxis * CAMERA_DISTANCE_FACTOR, CAMERA_DISTANCE_MIN, CAMERA_DISTANCE_MAX);
|
||||
const targetY = FLOOR_Y + Math.max(size.y * 0.46, 1.4);
|
||||
|
||||
camera.position.set(distance * 0.48, targetY + distance * 0.24, distance * 0.68);
|
||||
camera.near = Math.max(distance / 80, 0.01);
|
||||
camera.far = distance * 24;
|
||||
camera.updateProjectionMatrix();
|
||||
controls.target.set(0, targetY, 0);
|
||||
controls.minDistance = Math.max(distance * 0.32, 2);
|
||||
controls.maxDistance = Math.max(distance * 2.5, 12);
|
||||
controls.update();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!rootEl || !canvasEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const renderer = new THREE.WebGLRenderer({
|
||||
canvas: canvasEl,
|
||||
antialias: true,
|
||||
alpha: true,
|
||||
powerPreference: "high-performance"
|
||||
});
|
||||
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
|
||||
renderer.setClearColor(0x03070d, 1);
|
||||
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 1.08;
|
||||
|
||||
const scene = new THREE.Scene();
|
||||
scene.fog = new THREE.FogExp2(0x03070d, 0.028);
|
||||
|
||||
const camera = new THREE.PerspectiveCamera(38, 1, 0.05, 600);
|
||||
camera.position.set(8, 6, 9);
|
||||
|
||||
const controls = new OrbitControls(camera, canvasEl);
|
||||
controls.enableDamping = true;
|
||||
controls.dampingFactor = 0.08;
|
||||
controls.minDistance = 2.4;
|
||||
controls.maxDistance = 32;
|
||||
controls.target.set(0, FLOOR_Y + 3.2, 0);
|
||||
|
||||
const labGroup = new THREE.Group();
|
||||
scene.add(labGroup);
|
||||
|
||||
const grid = new THREE.GridHelper(42, 42, 0x63e6ff, 0x123047);
|
||||
grid.position.y = FLOOR_Y;
|
||||
const gridMaterial = grid.material;
|
||||
if (Array.isArray(gridMaterial)) {
|
||||
for (const material of gridMaterial) {
|
||||
material.transparent = true;
|
||||
material.opacity = 0.28;
|
||||
}
|
||||
} else {
|
||||
gridMaterial.transparent = true;
|
||||
gridMaterial.opacity = 0.28;
|
||||
}
|
||||
labGroup.add(grid);
|
||||
|
||||
const backGrid = new THREE.GridHelper(42, 42, 0x5ee7ff, 0x0c2436);
|
||||
backGrid.position.set(0, 9.5, -17);
|
||||
backGrid.rotation.x = Math.PI / 2;
|
||||
const backGridMaterial = backGrid.material;
|
||||
if (Array.isArray(backGridMaterial)) {
|
||||
for (const material of backGridMaterial) {
|
||||
material.transparent = true;
|
||||
material.opacity = 0.12;
|
||||
}
|
||||
} else {
|
||||
backGridMaterial.transparent = true;
|
||||
backGridMaterial.opacity = 0.12;
|
||||
}
|
||||
labGroup.add(backGrid);
|
||||
|
||||
const floor = new THREE.Mesh(
|
||||
new THREE.PlaneGeometry(42, 42),
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x050c14,
|
||||
metalness: 0.28,
|
||||
roughness: 0.64,
|
||||
transparent: true,
|
||||
opacity: 0.72
|
||||
})
|
||||
);
|
||||
floor.rotation.x = -Math.PI / 2;
|
||||
floor.position.y = FLOOR_Y - 0.018;
|
||||
labGroup.add(floor);
|
||||
|
||||
const ambient = new THREE.AmbientLight(0x9fb8d0, 0.22);
|
||||
const keyLight = new THREE.DirectionalLight(0x7be7ff, 1.5);
|
||||
keyLight.position.set(8, 12, 8);
|
||||
const rimLight = new THREE.PointLight(0xa6ff7a, 26, 24, 2.1);
|
||||
rimLight.position.set(-4.5, 4.8, -3.6);
|
||||
const sideLight = new THREE.PointLight(0x5c8cff, 15, 28, 1.7);
|
||||
sideLight.position.set(5.8, 3.2, -5.4);
|
||||
scene.add(ambient, keyLight, rimLight, sideLight);
|
||||
|
||||
let activeModel: THREE.Object3D = buildPlaceholderModel();
|
||||
scene.add(activeModel);
|
||||
frameObject(activeModel, camera, controls);
|
||||
|
||||
const loader = new GLTFLoader();
|
||||
loader.load(
|
||||
modelUrl,
|
||||
(gltf: GLTF) => {
|
||||
scene.remove(activeModel);
|
||||
disposeObject3D(activeModel);
|
||||
activeModel = gltf.scene;
|
||||
activeModel.traverse((child) => {
|
||||
const mesh = child as THREE.Mesh;
|
||||
if (mesh.isMesh) {
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
scene.add(activeModel);
|
||||
frameObject(activeModel, camera, controls);
|
||||
loadState = "ready";
|
||||
loadProgress = 100;
|
||||
},
|
||||
(event) => {
|
||||
if (event.total > 0) {
|
||||
loadProgress = (event.loaded / event.total) * 100;
|
||||
} else {
|
||||
loadProgress = 12;
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
loadError = message || "Unknown model loader error";
|
||||
loadState = message.toLowerCase().includes("404") ? "missing" : "error";
|
||||
loadProgress = 0;
|
||||
}
|
||||
);
|
||||
|
||||
const resize = () => {
|
||||
if (!rootEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const width = rootEl.clientWidth;
|
||||
const height = rootEl.clientHeight;
|
||||
if (width <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderer.setSize(width, height, false);
|
||||
camera.aspect = width / height;
|
||||
camera.updateProjectionMatrix();
|
||||
};
|
||||
|
||||
resize();
|
||||
const resizeObserver = new ResizeObserver(resize);
|
||||
resizeObserver.observe(rootEl);
|
||||
|
||||
renderer.setAnimationLoop((timestamp) => {
|
||||
const seconds = timestamp / 1000;
|
||||
labGroup.position.y = Math.sin(seconds * 0.75) * 0.015;
|
||||
if (loadState !== "ready") {
|
||||
activeModel.rotation.y = seconds * 0.32;
|
||||
}
|
||||
controls.update();
|
||||
renderer.render(scene, camera);
|
||||
});
|
||||
|
||||
return () => {
|
||||
resizeObserver.disconnect();
|
||||
renderer.setAnimationLoop(null);
|
||||
controls.dispose();
|
||||
disposeObject3D(activeModel);
|
||||
disposeObject3D(labGroup);
|
||||
renderer.dispose();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="model-stage" bind:this={rootEl}>
|
||||
<canvas class="model-canvas" bind:this={canvasEl} aria-label={copy.title}></canvas>
|
||||
<div class="model-vignette" aria-hidden="true"></div>
|
||||
<div class="model-scanlines" aria-hidden="true"></div>
|
||||
|
||||
<section class="model-hud" aria-label={copy.title}>
|
||||
<p class="model-kicker">{copy.subtitle}</p>
|
||||
<h2>{copy.title}</h2>
|
||||
<div class="model-status-row">
|
||||
<span class="status-light" class:is-ready={loadState === "ready"}></span>
|
||||
<span>{statusText}</span>
|
||||
</div>
|
||||
<p class="model-path">{copy.modelPath}: {modelUrl}</p>
|
||||
<p class="model-hint">{loadError || copy.hint}</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.model-stage {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
overflow: hidden;
|
||||
background:
|
||||
radial-gradient(circle at 52% 62%, rgb(94 231 255 / 0.12), transparent 26%),
|
||||
radial-gradient(circle at 24% 18%, rgb(166 255 122 / 0.07), transparent 24%),
|
||||
linear-gradient(180deg, #03070d 0%, #07111b 48%, #02050a 100%);
|
||||
}
|
||||
|
||||
.model-canvas,
|
||||
.model-vignette,
|
||||
.model-scanlines {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.model-canvas {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.model-vignette,
|
||||
.model-scanlines {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.model-vignette {
|
||||
background:
|
||||
linear-gradient(90deg, rgb(0 0 0 / 0.36), transparent 22%, transparent 78%, rgb(0 0 0 / 0.34)),
|
||||
radial-gradient(circle at center, transparent 48%, rgb(0 0 0 / 0.58) 100%);
|
||||
}
|
||||
|
||||
.model-scanlines {
|
||||
opacity: 0.32;
|
||||
background:
|
||||
repeating-linear-gradient(180deg, rgb(94 231 255 / 0.045) 0, rgb(94 231 255 / 0.045) 1px, transparent 1px, transparent 4px);
|
||||
mix-blend-mode: screen;
|
||||
}
|
||||
|
||||
.model-hud {
|
||||
position: absolute;
|
||||
top: clamp(1.2rem, 2.8vw, 2.2rem);
|
||||
left: clamp(1.2rem, 2.8vw, 2.4rem);
|
||||
z-index: 2;
|
||||
display: grid;
|
||||
gap: 0.42rem;
|
||||
max-inline-size: min(22rem, 42vw);
|
||||
padding: 0.9rem 1rem 1rem;
|
||||
border: 1px solid rgb(94 231 255 / 0.24);
|
||||
border-radius: 0.7rem;
|
||||
background:
|
||||
linear-gradient(180deg, rgb(8 18 28 / 0.82), rgb(3 9 15 / 0.72)),
|
||||
radial-gradient(circle at 0 0, rgb(94 231 255 / 0.1), transparent 44%);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgb(255 255 255 / 0.06),
|
||||
0 0 28px rgb(94 231 255 / 0.08);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.model-kicker,
|
||||
.model-path,
|
||||
.model-hint {
|
||||
margin: 0;
|
||||
color: rgb(198 226 239 / 0.72);
|
||||
font-size: 0.6rem;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
color: rgb(241 251 255 / 0.96);
|
||||
font-size: clamp(1.15rem, 1.1vw + 0.88rem, 1.72rem);
|
||||
line-height: 1.05;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.model-status-row {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.44rem;
|
||||
color: rgb(229 249 255 / 0.94);
|
||||
font-size: 0.78rem;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.status-light {
|
||||
inline-size: 0.58rem;
|
||||
block-size: 0.58rem;
|
||||
border-radius: 50%;
|
||||
background: rgb(255 188 92 / 0.95);
|
||||
box-shadow: 0 0 0 2px rgb(255 188 92 / 0.16), 0 0 12px rgb(255 188 92 / 0.18);
|
||||
}
|
||||
|
||||
.status-light.is-ready {
|
||||
background: rgb(166 255 122 / 0.95);
|
||||
box-shadow: 0 0 0 2px rgb(166 255 122 / 0.16), 0 0 14px rgb(166 255 122 / 0.22);
|
||||
}
|
||||
|
||||
.model-path {
|
||||
color: rgb(94 231 255 / 0.78);
|
||||
text-transform: none;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.model-hint {
|
||||
color: rgb(198 226 239 / 0.66);
|
||||
text-transform: none;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.model-hud {
|
||||
max-inline-size: min(20rem, calc(100% - 2.4rem));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -461,28 +461,6 @@
|
||||
const heightField = new Float32Array(instanceCount);
|
||||
const compactField = new Uint16Array(instanceCount);
|
||||
let lastFrameAt = performance.now();
|
||||
let lastStatsCurrent: number | null = null;
|
||||
let lastStatsMax: number | null = null;
|
||||
let lastStatsMin: number | null = null;
|
||||
|
||||
const syncStats = () => {
|
||||
const nextCurrent = summary?.latest ?? null;
|
||||
const nextMax = summary?.max ?? null;
|
||||
const nextMin = summary?.min ?? null;
|
||||
|
||||
if (nextCurrent === lastStatsCurrent && nextMax === lastStatsMax && nextMin === lastStatsMin) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastStatsCurrent = nextCurrent;
|
||||
lastStatsMax = nextMax;
|
||||
lastStatsMin = nextMin;
|
||||
stats = {
|
||||
current: nextCurrent,
|
||||
max: nextMax,
|
||||
min: nextMin
|
||||
};
|
||||
};
|
||||
|
||||
const drawOverlay = () => {
|
||||
if (!viewerEl || !overlayEl) {
|
||||
@@ -645,7 +623,12 @@
|
||||
|
||||
renderer.render(scene, camera);
|
||||
drawOverlay();
|
||||
syncStats();
|
||||
|
||||
stats = {
|
||||
current: summary?.latest ?? null,
|
||||
max: summary?.max ?? null,
|
||||
min: summary?.min ?? null
|
||||
};
|
||||
});
|
||||
|
||||
return () => {
|
||||
|
||||
@@ -182,7 +182,8 @@
|
||||
transition:
|
||||
opacity var(--fade-ms) cubic-bezier(0.18, 0.88, 0.3, 1),
|
||||
transform var(--enter-ms) cubic-bezier(0.2, 0.9, 0.28, 1),
|
||||
border-color 460ms ease;
|
||||
border-color 460ms ease,
|
||||
filter 760ms ease;
|
||||
transition-delay: calc(var(--panel-index) * 140ms);
|
||||
}
|
||||
|
||||
@@ -199,6 +200,7 @@
|
||||
border-color: transparent;
|
||||
opacity: 0;
|
||||
transform: translateX(var(--offset-x)) scale(0.98) rotate(-0.6deg);
|
||||
filter: blur(1.3px);
|
||||
pointer-events: none;
|
||||
transition-delay: 0ms;
|
||||
}
|
||||
@@ -299,6 +301,7 @@
|
||||
stroke-width: 1.3;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
filter: drop-shadow(0 0 2px rgb(0 0 0 / 0.42));
|
||||
}
|
||||
|
||||
.series-line.tone-cyan {
|
||||
@@ -394,10 +397,6 @@
|
||||
aspect-ratio: 1.5 / 1;
|
||||
min-block-size: 10.1rem;
|
||||
}
|
||||
|
||||
.chart-stage {
|
||||
block-size: clamp(5.7rem, 7.6vw, 6.9rem);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-height: 900px) {
|
||||
@@ -453,17 +452,6 @@
|
||||
inline-size: 100%;
|
||||
aspect-ratio: 1.7 / 1;
|
||||
min-block-size: 0;
|
||||
background: linear-gradient(160deg, rgb(var(--hud-surface-alt-rgb) / 0.86) 0%, rgb(var(--hud-surface-deep-rgb) / 0.9) 100%);
|
||||
box-shadow: inset 0 0 0 1px rgb(var(--hud-border-strong-rgb) / 0.08), 0 0 8px rgb(var(--hud-glow-rgb) / 0.1);
|
||||
}
|
||||
|
||||
.scan-haze {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chart-stage {
|
||||
background: linear-gradient(180deg, rgb(var(--hud-surface-alt-rgb) / 0.78), rgb(var(--hud-surface-deep-rgb) / 0.88));
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
523
src/lib/components/SpatialForcePanel.svelte
Normal file
@@ -0,0 +1,523 @@
|
||||
<script lang="ts">
|
||||
import type { HudSpatialForce } from "$lib/types/hud";
|
||||
|
||||
export let spatialForce: HudSpatialForce | null = null;
|
||||
export let side: "left" | "right" = "right";
|
||||
export let panelIndex = 0;
|
||||
export let locale: "zh-CN" | "en-US" = "zh-CN";
|
||||
export let panelCode = "TAN";
|
||||
export let panelTitle = "";
|
||||
export let badgeLabel = "";
|
||||
export let badgeTone: "cyan" | "lime" | "orange" = "cyan";
|
||||
export let showMetrics = true;
|
||||
export let requireMagnitude = true;
|
||||
export let compactMetaText = "";
|
||||
|
||||
function formatValue(value: number | null, digits = 1): string {
|
||||
if (value === null || !Number.isFinite(value)) {
|
||||
return "--";
|
||||
}
|
||||
|
||||
return value.toFixed(digits);
|
||||
}
|
||||
|
||||
function normalizeAngle(value: number): number {
|
||||
return ((value % 360) + 360) % 360;
|
||||
}
|
||||
|
||||
function shortestAngleDelta(from: number, to: number): number {
|
||||
const delta = ((to - from + 540) % 360) - 180;
|
||||
return delta === -180 ? 180 : delta;
|
||||
}
|
||||
|
||||
const jumpAngleThresholdDeg = 72;
|
||||
|
||||
let visualAngleDeg = 0;
|
||||
let previousRawAngleDeg: number | null = null;
|
||||
let snapVector = false;
|
||||
let snapResetFrame: number | null = null;
|
||||
|
||||
function setSnapVector(): void {
|
||||
snapVector = true;
|
||||
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (snapResetFrame !== null) {
|
||||
window.cancelAnimationFrame(snapResetFrame);
|
||||
}
|
||||
|
||||
snapResetFrame = window.requestAnimationFrame(() => {
|
||||
snapVector = false;
|
||||
snapResetFrame = null;
|
||||
});
|
||||
}
|
||||
|
||||
function updateVisualAngle(rawAngleDeg: number, active: boolean): void {
|
||||
if (!active) {
|
||||
previousRawAngleDeg = null;
|
||||
visualAngleDeg = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (previousRawAngleDeg === null) {
|
||||
previousRawAngleDeg = rawAngleDeg;
|
||||
visualAngleDeg = rawAngleDeg;
|
||||
return;
|
||||
}
|
||||
|
||||
const delta = shortestAngleDelta(previousRawAngleDeg, rawAngleDeg);
|
||||
if (Math.abs(delta) < 0.001) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.abs(delta) >= jumpAngleThresholdDeg) {
|
||||
setSnapVector();
|
||||
}
|
||||
|
||||
visualAngleDeg += delta;
|
||||
previousRawAngleDeg = rawAngleDeg;
|
||||
}
|
||||
|
||||
$: i18n =
|
||||
locale === "zh-CN"
|
||||
? {
|
||||
title: "切向力方向",
|
||||
waiting: "等待数据",
|
||||
angle: "ANGLE",
|
||||
heading: "方向角",
|
||||
strength: "强度",
|
||||
confidence: "置信度"
|
||||
}
|
||||
: {
|
||||
title: "Tangential Direction",
|
||||
waiting: "Waiting",
|
||||
angle: "ANGLE",
|
||||
heading: "Heading",
|
||||
strength: "Strength",
|
||||
confidence: "Confidence"
|
||||
};
|
||||
$: resolvedTitle = panelTitle || i18n.title;
|
||||
$: resolvedBadgeLabel = badgeLabel || i18n.angle;
|
||||
$: resolvedCompactMetaText =
|
||||
compactMetaText || (locale === "zh-CN" ? "仅使用角度流" : "Angle stream only");
|
||||
|
||||
$: hasData =
|
||||
spatialForce !== null &&
|
||||
Number.isFinite(spatialForce.angleDeg) &&
|
||||
(!requireMagnitude || Number.isFinite(spatialForce.magnitude));
|
||||
$: angleDeg = hasData ? normalizeAngle(spatialForce?.angleDeg ?? 0) : 0;
|
||||
$: updateVisualAngle(angleDeg, hasData);
|
||||
$: magnitude = hasData ? spatialForce?.magnitude ?? 0 : null;
|
||||
$: confidence = hasData ? (spatialForce?.confidence ?? 0) * 100 : null;
|
||||
</script>
|
||||
|
||||
<article
|
||||
class="signal-panel spatial-panel side-{side}"
|
||||
class:is-empty={!hasData}
|
||||
aria-hidden={false}
|
||||
style="--panel-index: {panelIndex};"
|
||||
>
|
||||
<header class="panel-head">
|
||||
<div class="head-text">
|
||||
<p class="panel-code">{panelCode}</p>
|
||||
<p class="panel-title">{resolvedTitle}</p>
|
||||
</div>
|
||||
|
||||
<div class="icon-layer" aria-hidden="true">
|
||||
<span class={`icon-chip tone-${badgeTone}`}>{resolvedBadgeLabel}</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="panel-body">
|
||||
<div class="compass-stage">
|
||||
<div class="compass-core">
|
||||
<div class="compass-ring compass-ring-outer"></div>
|
||||
<div class="compass-ring compass-ring-inner"></div>
|
||||
<div class="compass-axis axis-horizontal"></div>
|
||||
<div class="compass-axis axis-vertical"></div>
|
||||
{#if hasData}
|
||||
<div
|
||||
class="compass-vector"
|
||||
class:is-snap={snapVector}
|
||||
style="transform: translateY(-50%) rotate({-visualAngleDeg}deg);"
|
||||
>
|
||||
<span class="vector-shaft"></span>
|
||||
<span class="vector-head"></span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="compass-center"></div>
|
||||
<span class="compass-label label-top">90</span>
|
||||
<span class="compass-label label-right">0</span>
|
||||
<span class="compass-label label-bottom">270</span>
|
||||
<span class="compass-label label-left">180</span>
|
||||
</div>
|
||||
|
||||
{#if !hasData}
|
||||
<div class="empty-state">
|
||||
<span>{i18n.waiting}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="angle-stage">
|
||||
<p class="angle-label">{i18n.heading}</p>
|
||||
{#if showMetrics}
|
||||
<p class="angle-meta">{i18n.strength}: {formatValue(magnitude, 2)}</p>
|
||||
<p class="angle-meta">{i18n.confidence}: {hasData ? `${formatValue(confidence, 0)}%` : "--"}</p>
|
||||
{:else}
|
||||
<p class="angle-meta">{resolvedCompactMetaText}</p>
|
||||
<p class="angle-meta">{hasData ? (locale === "zh-CN" ? "实时对比中" : "Live comparison") : "--"}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<style>
|
||||
.signal-panel {
|
||||
--offset-x: 12%;
|
||||
--enter-ms: 1800ms;
|
||||
--fade-ms: 1000ms;
|
||||
overflow: hidden;
|
||||
inline-size: min(100%, clamp(34rem, 44vw, 44rem));
|
||||
justify-self: start;
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr;
|
||||
gap: 0.68rem;
|
||||
padding: 0.88rem 0.96rem 1rem;
|
||||
border: 1px solid rgb(var(--hud-border-strong-rgb) / 0.42);
|
||||
border-radius: 0.92rem;
|
||||
background:
|
||||
linear-gradient(160deg, rgb(var(--hud-surface-alt-rgb) / 0.76) 0%, rgb(var(--hud-surface-rgb) / 0.62) 48%, rgb(var(--hud-surface-deep-rgb) / 0.76) 100%),
|
||||
radial-gradient(circle at 12% 0, rgb(var(--hud-glow-rgb) / 0.1), transparent 40%);
|
||||
box-shadow:
|
||||
inset 0 0 0 1px rgb(var(--hud-border-strong-rgb) / 0.08),
|
||||
inset 0 -24px 32px rgb(0 0 0 / 0.48),
|
||||
0 0 14px rgb(var(--hud-glow-rgb) / 0.14);
|
||||
opacity: 1;
|
||||
transform: translateX(0) scale(1) rotate(0);
|
||||
transition:
|
||||
opacity var(--fade-ms) cubic-bezier(0.18, 0.88, 0.3, 1),
|
||||
transform var(--enter-ms) cubic-bezier(0.2, 0.9, 0.28, 1),
|
||||
border-color 460ms ease,
|
||||
filter 760ms ease;
|
||||
transition-delay: calc(var(--panel-index) * 140ms);
|
||||
}
|
||||
|
||||
.signal-panel.side-left {
|
||||
--offset-x: -132%;
|
||||
}
|
||||
|
||||
.signal-panel.side-right {
|
||||
--offset-x: 132%;
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
.spatial-panel.is-empty {
|
||||
opacity: 0.82;
|
||||
}
|
||||
|
||||
.panel-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 0.4rem;
|
||||
margin-block-end: 0;
|
||||
}
|
||||
|
||||
.head-text {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.panel-code {
|
||||
margin: 0;
|
||||
font-size: 0.63rem;
|
||||
color: rgb(var(--hud-text-dim-rgb) / 0.88);
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
margin: 0.12rem 0 0;
|
||||
font-size: 1.08rem;
|
||||
color: rgb(var(--hud-text-main-rgb) / 0.96);
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.icon-layer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 0.26rem;
|
||||
}
|
||||
|
||||
.icon-chip {
|
||||
border: 1px solid rgb(var(--hud-border-strong-rgb) / 0.44);
|
||||
border-radius: 999px;
|
||||
padding: 0.08rem 0.36rem;
|
||||
font-size: 0.58rem;
|
||||
letter-spacing: 0.08em;
|
||||
color: rgb(var(--hud-text-main-rgb) / 0.94);
|
||||
background: rgb(var(--hud-surface-rgb) / 0.66);
|
||||
}
|
||||
|
||||
.icon-chip.tone-cyan {
|
||||
border-color: rgb(var(--hud-cyan-rgb) / 0.54);
|
||||
}
|
||||
|
||||
.icon-chip.tone-lime {
|
||||
border-color: rgb(var(--hud-lime-rgb) / 0.54);
|
||||
}
|
||||
|
||||
.icon-chip.tone-orange {
|
||||
border-color: rgb(var(--hud-orange-rgb) / 0.54);
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.1fr) minmax(10rem, 0.9fr);
|
||||
gap: 0.72rem;
|
||||
block-size: clamp(12rem, 15.5vw, 15rem);
|
||||
min-block-size: clamp(12rem, 15.5vw, 15rem);
|
||||
}
|
||||
|
||||
.compass-stage {
|
||||
position: relative;
|
||||
min-block-size: 0;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgb(var(--hud-border-strong-rgb) / 0.32);
|
||||
border-radius: 0.62rem;
|
||||
background:
|
||||
linear-gradient(180deg, rgb(var(--hud-surface-alt-rgb) / 0.68), rgb(var(--hud-surface-deep-rgb) / 0.78)),
|
||||
radial-gradient(circle at 50% 0, rgb(var(--hud-glow-rgb) / 0.09), transparent 45%);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
.compass-core {
|
||||
position: relative;
|
||||
inline-size: min(72%, 13rem);
|
||||
aspect-ratio: 1;
|
||||
}
|
||||
|
||||
.compass-ring,
|
||||
.compass-axis,
|
||||
.compass-center,
|
||||
.compass-vector {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
.compass-ring {
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.compass-ring-outer {
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
border: 1px solid rgb(var(--hud-cyan-rgb) / 0.28);
|
||||
box-shadow: 0 0 18px rgb(var(--hud-glow-rgb) / 0.08);
|
||||
}
|
||||
|
||||
.compass-ring-inner {
|
||||
inline-size: 62%;
|
||||
block-size: 62%;
|
||||
border: 1px dashed rgb(var(--hud-border-strong-rgb) / 0.3);
|
||||
}
|
||||
|
||||
.compass-axis {
|
||||
background: rgb(var(--hud-border-strong-rgb) / 0.18);
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.axis-horizontal {
|
||||
inline-size: 86%;
|
||||
block-size: 1px;
|
||||
}
|
||||
|
||||
.axis-vertical {
|
||||
inline-size: 1px;
|
||||
block-size: 86%;
|
||||
}
|
||||
|
||||
.compass-vector {
|
||||
inline-size: 42%;
|
||||
block-size: 0.9rem;
|
||||
transform-origin: 0 50%;
|
||||
transition: transform 220ms ease;
|
||||
}
|
||||
|
||||
.compass-vector.is-snap {
|
||||
transition-duration: 0ms;
|
||||
}
|
||||
|
||||
.vector-shaft {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
right: 0.7rem;
|
||||
block-size: 2px;
|
||||
transform: translateY(-50%);
|
||||
border-radius: 999px;
|
||||
background: linear-gradient(90deg, rgb(var(--hud-cyan-rgb) / 0.18), rgb(var(--hud-cyan-rgb) / 0.96));
|
||||
box-shadow: 0 0 14px rgb(var(--hud-cyan-rgb) / 0.2);
|
||||
}
|
||||
|
||||
.vector-head {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
inline-size: 0;
|
||||
block-size: 0;
|
||||
transform: translateY(-50%);
|
||||
border-top: 0.36rem solid transparent;
|
||||
border-bottom: 0.36rem solid transparent;
|
||||
border-left: 0.7rem solid rgb(var(--hud-lime-rgb) / 0.96);
|
||||
filter: drop-shadow(0 0 8px rgb(var(--hud-lime-rgb) / 0.24));
|
||||
}
|
||||
|
||||
.compass-center {
|
||||
inline-size: 0.56rem;
|
||||
block-size: 0.56rem;
|
||||
transform: translate(-50%, -50%);
|
||||
border-radius: 50%;
|
||||
background: rgb(var(--hud-text-main-rgb) / 0.92);
|
||||
box-shadow: 0 0 10px rgb(var(--hud-text-main-rgb) / 0.12);
|
||||
}
|
||||
|
||||
.compass-label {
|
||||
position: absolute;
|
||||
font-size: 0.58rem;
|
||||
color: rgb(var(--hud-text-dim-rgb) / 0.8);
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.label-top {
|
||||
top: -0.9rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.label-right {
|
||||
top: 50%;
|
||||
right: -1rem;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.label-bottom {
|
||||
bottom: -0.9rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.label-left {
|
||||
top: 50%;
|
||||
left: -1.35rem;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: rgb(var(--hud-text-dim-rgb) / 0.76);
|
||||
font-size: 0.66rem;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
background: linear-gradient(180deg, rgb(var(--hud-surface-deep-rgb) / 0.06), rgb(var(--hud-surface-deep-rgb) / 0.18));
|
||||
}
|
||||
|
||||
.angle-stage {
|
||||
border: 1px solid rgb(var(--hud-border-rgb) / 0.26);
|
||||
border-radius: 0.62rem;
|
||||
padding: 0.9rem 0.85rem;
|
||||
block-size: 100%;
|
||||
min-block-size: 0;
|
||||
overflow: hidden;
|
||||
background:
|
||||
linear-gradient(180deg, rgb(var(--hud-surface-rgb) / 0.72), rgb(var(--hud-surface-deep-rgb) / 0.84)),
|
||||
radial-gradient(circle at 50% 0, rgb(var(--hud-glow-rgb) / 0.05), transparent 58%);
|
||||
display: grid;
|
||||
grid-template-rows: auto auto auto;
|
||||
align-content: center;
|
||||
justify-items: start;
|
||||
gap: 0.36rem;
|
||||
}
|
||||
|
||||
.angle-label {
|
||||
margin: 0;
|
||||
color: rgb(var(--hud-text-dim-rgb) / 0.82);
|
||||
font-size: 0.68rem;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.angle-meta {
|
||||
margin: 0;
|
||||
inline-size: 10rem;
|
||||
min-block-size: 1rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: rgb(var(--hud-text-dim-rgb) / 0.84);
|
||||
font-size: 0.68rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.signal-panel {
|
||||
inline-size: min(100%, clamp(28rem, 40vw, 38rem));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-height: 900px) {
|
||||
.signal-panel {
|
||||
inline-size: min(100%, clamp(28rem, 38vw, 36rem));
|
||||
padding: 0.7rem 0.76rem 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-height: 760px) {
|
||||
.signal-panel {
|
||||
inline-size: min(100%, clamp(24rem, 34vw, 30rem));
|
||||
padding: 0.62rem 0.68rem 0.72rem;
|
||||
gap: 0.48rem;
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
block-size: clamp(9rem, 10vw, 10.8rem);
|
||||
min-block-size: clamp(9rem, 10vw, 10.8rem);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-height: 680px) {
|
||||
.signal-panel {
|
||||
inline-size: min(100%, clamp(20rem, 28vw, 26rem));
|
||||
padding: 0.52rem 0.58rem 0.6rem;
|
||||
gap: 0.36rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.signal-panel {
|
||||
inline-size: 100%;
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
grid-template-columns: 1fr;
|
||||
block-size: auto;
|
||||
min-block-size: auto;
|
||||
}
|
||||
|
||||
.compass-core {
|
||||
inline-size: min(58vw, 12rem);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -11,6 +11,22 @@
|
||||
export let sessionStartedAt: number = Date.now();
|
||||
export let isRealtime = false;
|
||||
|
||||
let currentTimeSeconds = 0;
|
||||
let timerId: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
onMount(() => {
|
||||
timerId = setInterval(() => {
|
||||
currentTimeSeconds = Math.round((Date.now() - sessionStartedAt) / 100) / 10;
|
||||
}, 200);
|
||||
return () => {
|
||||
if (timerId != null) clearInterval(timerId);
|
||||
};
|
||||
});
|
||||
|
||||
$: i18n = locale === "zh-CN"
|
||||
? { now: "当前", min: "最小", max: "最大", waiting: "等待数据" }
|
||||
: { now: "Now", min: "Min", max: "Max", waiting: "Waiting" };
|
||||
|
||||
const viewportWidth = 120;
|
||||
const viewportHeight = 48;
|
||||
const plotInsetLeft = 13;
|
||||
@@ -18,8 +34,6 @@
|
||||
const plotInsetTop = 4;
|
||||
const plotInsetBottom = 9;
|
||||
const fixedYBounds = { min: 0, max: 25 };
|
||||
const maxCanvasDpr = 1.5;
|
||||
const minDrawIntervalMs = 66;
|
||||
|
||||
interface CurveSample {
|
||||
x: number;
|
||||
@@ -31,25 +45,23 @@
|
||||
y: number;
|
||||
}
|
||||
|
||||
let canvasEl: HTMLCanvasElement | undefined;
|
||||
let chartStageEl: HTMLDivElement | undefined;
|
||||
let currentTimeSeconds = 0;
|
||||
let timerId: ReturnType<typeof setInterval> | null = null;
|
||||
let resizeObserver: ResizeObserver | null = null;
|
||||
let drawRequestId: number | null = null;
|
||||
let lastDrawAt = 0;
|
||||
let mounted = false;
|
||||
|
||||
$: i18n = locale === "zh-CN"
|
||||
? { now: "当前", min: "最小", max: "最大", waiting: "等待数据" }
|
||||
: { now: "Now", min: "Min", max: "Max", waiting: "Waiting" };
|
||||
interface AxisTick {
|
||||
value: number;
|
||||
label: string;
|
||||
plotX: number;
|
||||
plotY: number;
|
||||
}
|
||||
|
||||
function clamp(value: number, min: number, max: number): number {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
function formatValue(value: number | null): string {
|
||||
return value === null ? "--" : value.toFixed(1);
|
||||
if (value === null) {
|
||||
return "--";
|
||||
}
|
||||
|
||||
return value.toFixed(1);
|
||||
}
|
||||
|
||||
function formatAxisValue(value: number, axis: "x" | "y"): string {
|
||||
@@ -61,7 +73,6 @@
|
||||
if (value < 60) {
|
||||
return `${value.toFixed(1)}s`;
|
||||
}
|
||||
|
||||
const mins = Math.floor(value / 60);
|
||||
const secs = value - mins * 60;
|
||||
return `${mins}:${secs.toFixed(0).padStart(2, "0")}`;
|
||||
@@ -70,6 +81,17 @@
|
||||
return `${Math.round(value)} N`;
|
||||
}
|
||||
|
||||
function resolveDataBounds(values: number[]): { min: number; max: number } {
|
||||
if (values.length === 0) {
|
||||
return { min: 0, max: 1 };
|
||||
}
|
||||
|
||||
return {
|
||||
min: Math.min(...values),
|
||||
max: Math.max(...values)
|
||||
};
|
||||
}
|
||||
|
||||
function resolveBounds(values: number[]): { min: number; max: number } {
|
||||
if (values.length === 0) {
|
||||
return { min: 0, max: 1 };
|
||||
@@ -86,23 +108,34 @@
|
||||
return { min, max };
|
||||
}
|
||||
|
||||
function buildSamples(rawYValues: number[], rawXValues: number[], currentSeconds: number): CurveSample[] {
|
||||
function mapXToViewport(value: number, bounds: { min: number; max: number }): number {
|
||||
const span = bounds.max - bounds.min;
|
||||
const chartWidth = viewportWidth - plotInsetLeft - plotInsetRight;
|
||||
const ratio = span <= 0 ? 0.5 : (value - bounds.min) / span;
|
||||
const mappedX = plotInsetLeft + ratio * chartWidth;
|
||||
return Math.round(clamp(mappedX, plotInsetLeft, viewportWidth - plotInsetRight) * 100) / 100;
|
||||
}
|
||||
|
||||
function mapYToViewport(value: number, bounds: { min: number; max: number }): number {
|
||||
const span = bounds.max - bounds.min;
|
||||
const chartHeight = viewportHeight - plotInsetTop - plotInsetBottom;
|
||||
const ratio = span <= 0 ? 0.5 : (value - bounds.min) / span;
|
||||
const mappedY = viewportHeight - plotInsetBottom - ratio * chartHeight;
|
||||
return Math.round(clamp(mappedY, plotInsetTop, viewportHeight - plotInsetBottom) * 100) / 100;
|
||||
}
|
||||
|
||||
function buildSamples(rawYValues: number[], rawXValues: number[]): CurveSample[] {
|
||||
if (!rawYValues.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const hasUsableXValues = rawXValues.length === rawYValues.length;
|
||||
const realtimeSpacing = isRealtime
|
||||
? Math.max(currentSeconds / Math.max(rawYValues.length - 1, 1), 0.1)
|
||||
: 1;
|
||||
const realtimeStart = isRealtime ? Math.max(0, currentSeconds - realtimeSpacing * (rawYValues.length - 1)) : 0;
|
||||
let previousX = realtimeStart;
|
||||
let previousX = 0;
|
||||
|
||||
return rawYValues.map((rawY, index) => {
|
||||
const x = rawXValues[index];
|
||||
const y = Number.isFinite(rawY) ? Number(rawY) : 0;
|
||||
const rawX = rawXValues[index];
|
||||
const fallbackX = isRealtime ? realtimeStart + index * realtimeSpacing : index + 1;
|
||||
const resolvedX = hasUsableXValues && Number.isFinite(rawX) ? Number(rawX) : fallbackX;
|
||||
const fallbackX = index === 0 ? 0 : previousX + 1;
|
||||
const resolvedX = Number.isFinite(x) ? Number(x) : fallbackX;
|
||||
const normalizedX = index === 0 ? resolvedX : Math.max(resolvedX, previousX);
|
||||
previousX = normalizedX;
|
||||
return { x: normalizedX, y };
|
||||
@@ -110,274 +143,132 @@
|
||||
}
|
||||
|
||||
function resolveXScaleBounds(
|
||||
samplesValue: CurveSample[],
|
||||
samples: CurveSample[],
|
||||
currentSeconds: number,
|
||||
realtime: boolean
|
||||
): { min: number; max: number } {
|
||||
if (samplesValue.length === 0) {
|
||||
if (samples.length === 0) {
|
||||
return { min: 0, max: 1 };
|
||||
}
|
||||
|
||||
const values = samples.map((sample) => sample.x);
|
||||
const dataBounds = resolveBounds(values);
|
||||
|
||||
if (!realtime) {
|
||||
return resolveBounds(samplesValue.map((sample) => sample.x));
|
||||
return dataBounds;
|
||||
}
|
||||
|
||||
const firstX = samplesValue[0].x;
|
||||
const lastX = samplesValue[samplesValue.length - 1].x;
|
||||
const firstX = samples[0].x;
|
||||
const lastX = samples[samples.length - 1].x;
|
||||
const axisMax = Math.max(lastX, currentSeconds);
|
||||
const dataSpan = Math.max(lastX - firstX, 1);
|
||||
const axisMin = Math.max(0, axisMax - dataSpan);
|
||||
const positiveDiffs = samples
|
||||
.slice(1)
|
||||
.map((sample, index) => sample.x - samples[index].x)
|
||||
.filter((diff) => diff > 0);
|
||||
const averageSpacing =
|
||||
positiveDiffs.length > 0 ? positiveDiffs.reduce((sum, diff) => sum + diff, 0) / positiveDiffs.length : 1;
|
||||
const dataSpan = Math.max(lastX - firstX, 0);
|
||||
const windowSpan = Math.max(dataSpan, averageSpacing * Math.max(samples.length - 1, 1), 1);
|
||||
const axisMin = Math.max(0, axisMax - windowSpan);
|
||||
|
||||
return resolveBounds([axisMin, axisMax]);
|
||||
}
|
||||
|
||||
function mapXToViewport(value: number, bounds: { min: number; max: number }): number {
|
||||
const span = bounds.max - bounds.min;
|
||||
const chartWidth = viewportWidth - plotInsetLeft - plotInsetRight;
|
||||
const ratio = span <= 0 ? 0.5 : (value - bounds.min) / span;
|
||||
return clamp(plotInsetLeft + ratio * chartWidth, plotInsetLeft, viewportWidth - plotInsetRight);
|
||||
}
|
||||
|
||||
function mapYToViewport(value: number, bounds: { min: number; max: number }): number {
|
||||
const span = bounds.max - bounds.min;
|
||||
const chartHeight = viewportHeight - plotInsetTop - plotInsetBottom;
|
||||
const ratio = span <= 0 ? 0.5 : (value - bounds.min) / span;
|
||||
return clamp(viewportHeight - plotInsetBottom - ratio * chartHeight, plotInsetTop, viewportHeight - plotInsetBottom);
|
||||
}
|
||||
|
||||
function convertPoints(
|
||||
samplesValue: CurveSample[],
|
||||
samples: CurveSample[],
|
||||
xBounds: { min: number; max: number },
|
||||
yBounds: { min: number; max: number }
|
||||
): PlotPoint[] {
|
||||
if (samplesValue.length === 0) {
|
||||
if (samples.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (samplesValue.length === 1) {
|
||||
if (samples.length === 1) {
|
||||
return [{ x: viewportWidth / 2, y: viewportHeight / 2 }];
|
||||
}
|
||||
|
||||
return samplesValue.map((sample) => ({
|
||||
x: mapXToViewport(sample.x, xBounds),
|
||||
y: mapYToViewport(sample.y, yBounds)
|
||||
return samples.map((sample) => {
|
||||
return {
|
||||
x: mapXToViewport(sample.x, xBounds),
|
||||
y: mapYToViewport(sample.y, yBounds)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function buildYAxisTicks(
|
||||
yScaleBounds: { min: number; max: number },
|
||||
_yDataBounds: { min: number; max: number }
|
||||
): AxisTick[] {
|
||||
const tickValues = [25, 20, 15, 10, 5, 0];
|
||||
return tickValues.map((value) => ({
|
||||
value,
|
||||
label: formatAxisValue(value, "y"),
|
||||
plotX: plotInsetLeft - 1.8,
|
||||
plotY: mapYToViewport(value, yScaleBounds)
|
||||
}));
|
||||
}
|
||||
|
||||
function scaleCanvas(context: CanvasRenderingContext2D): { width: number; height: number; dpr: number } | null {
|
||||
if (!canvasEl || !chartStageEl) {
|
||||
return null;
|
||||
function buildXAxisTicks(xScaleBounds: { min: number; max: number }): AxisTick[] {
|
||||
if (!Number.isFinite(xScaleBounds.min) || !Number.isFinite(xScaleBounds.max)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const width = chartStageEl.clientWidth;
|
||||
const height = chartStageEl.clientHeight;
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, maxCanvasDpr);
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const nextWidth = Math.round(width * dpr);
|
||||
const nextHeight = Math.round(height * dpr);
|
||||
if (canvasEl.width !== nextWidth || canvasEl.height !== nextHeight) {
|
||||
canvasEl.width = nextWidth;
|
||||
canvasEl.height = nextHeight;
|
||||
canvasEl.style.width = `${width}px`;
|
||||
canvasEl.style.height = `${height}px`;
|
||||
}
|
||||
|
||||
context.setTransform((width * dpr) / viewportWidth, 0, 0, (height * dpr) / viewportHeight, 0, 0);
|
||||
return { width, height, dpr };
|
||||
const first = xScaleBounds.min;
|
||||
const middle = xScaleBounds.min + (xScaleBounds.max - xScaleBounds.min) / 2;
|
||||
const last = xScaleBounds.max;
|
||||
const tickValues = [first, middle, last];
|
||||
return tickValues.map((value) => ({
|
||||
value,
|
||||
label: formatAxisValue(value, "x"),
|
||||
plotX: mapXToViewport(value, xScaleBounds),
|
||||
plotY: viewportHeight - 0.9
|
||||
}));
|
||||
}
|
||||
|
||||
function drawGrid(context: CanvasRenderingContext2D, yBounds: { min: number; max: number }): void {
|
||||
const tickValues = [25, 20, 15, 10, 5, 0];
|
||||
|
||||
context.save();
|
||||
context.lineWidth = 0.45;
|
||||
context.strokeStyle = "rgb(128 170 180 / 0.18)";
|
||||
context.fillStyle = "rgb(190 216 220 / 0.78)";
|
||||
context.font = "600 3.2px system-ui, sans-serif";
|
||||
context.textBaseline = "middle";
|
||||
|
||||
for (const tick of tickValues) {
|
||||
const y = mapYToViewport(tick, yBounds);
|
||||
context.beginPath();
|
||||
context.moveTo(plotInsetLeft, y);
|
||||
context.lineTo(viewportWidth - plotInsetRight, y);
|
||||
context.stroke();
|
||||
|
||||
context.textAlign = "right";
|
||||
context.fillText(formatAxisValue(tick, "y"), plotInsetLeft - 1.8, y + 0.6);
|
||||
function createLinePath(points: PlotPoint[]): string {
|
||||
if (points.length === 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
context.restore();
|
||||
return points.map((point, index) => `${index === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" ");
|
||||
}
|
||||
|
||||
function drawXAxis(context: CanvasRenderingContext2D, xBounds: { min: number; max: number }): void {
|
||||
const first = xBounds.min;
|
||||
const middle = xBounds.min + (xBounds.max - xBounds.min) / 2;
|
||||
const last = xBounds.max;
|
||||
const ticks = [first, middle, last];
|
||||
|
||||
context.save();
|
||||
context.fillStyle = "rgb(190 216 220 / 0.82)";
|
||||
context.font = "600 3.2px system-ui, sans-serif";
|
||||
context.textBaseline = "alphabetic";
|
||||
|
||||
ticks.forEach((tick, index) => {
|
||||
const x = mapXToViewport(tick, xBounds);
|
||||
context.textAlign = index === 0 ? "left" : index === ticks.length - 1 ? "right" : "center";
|
||||
context.fillText(formatAxisValue(tick, "x"), x, viewportHeight - 0.9);
|
||||
});
|
||||
|
||||
context.restore();
|
||||
}
|
||||
|
||||
function drawArea(context: CanvasRenderingContext2D, points: PlotPoint[]): void {
|
||||
function createAreaPath(points: PlotPoint[]): string {
|
||||
if (points.length < 2) {
|
||||
return;
|
||||
return "";
|
||||
}
|
||||
|
||||
const linePath = createLinePath(points);
|
||||
const firstPoint = points[0];
|
||||
const lastPoint = points[points.length - 1];
|
||||
const gradient = context.createLinearGradient(0, plotInsetTop, 0, viewportHeight - plotInsetBottom);
|
||||
gradient.addColorStop(0, "rgb(62 232 255 / 0.28)");
|
||||
gradient.addColorStop(1, "rgb(62 232 255 / 0.02)");
|
||||
|
||||
context.save();
|
||||
context.beginPath();
|
||||
context.moveTo(firstPoint.x, firstPoint.y);
|
||||
for (let index = 1; index < points.length; index += 1) {
|
||||
context.lineTo(points[index].x, points[index].y);
|
||||
}
|
||||
context.lineTo(lastPoint.x, viewportHeight - plotInsetBottom);
|
||||
context.lineTo(firstPoint.x, viewportHeight - plotInsetBottom);
|
||||
context.closePath();
|
||||
context.fillStyle = gradient;
|
||||
context.fill();
|
||||
context.restore();
|
||||
}
|
||||
|
||||
function drawLine(context: CanvasRenderingContext2D, points: PlotPoint[]): void {
|
||||
if (!points.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.save();
|
||||
context.lineWidth = 1.35;
|
||||
context.lineCap = "round";
|
||||
context.lineJoin = "round";
|
||||
context.strokeStyle = "rgb(62 232 255 / 0.96)";
|
||||
context.beginPath();
|
||||
context.moveTo(points[0].x, points[0].y);
|
||||
for (let index = 1; index < points.length; index += 1) {
|
||||
context.lineTo(points[index].x, points[index].y);
|
||||
}
|
||||
context.stroke();
|
||||
|
||||
const lastPoint = points[points.length - 1];
|
||||
context.fillStyle = "rgb(133 255 68 / 0.98)";
|
||||
context.beginPath();
|
||||
context.arc(lastPoint.x, lastPoint.y, 1.7, 0, Math.PI * 2);
|
||||
context.fill();
|
||||
context.restore();
|
||||
}
|
||||
|
||||
function drawCanvas(): void {
|
||||
if (!canvasEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const context = canvasEl.getContext("2d", { alpha: true });
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scaled = scaleCanvas(context);
|
||||
if (!scaled) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.clearRect(0, 0, viewportWidth, viewportHeight);
|
||||
|
||||
if (sampleCount === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawGrid(context, yScaleBounds);
|
||||
drawArea(context, plotPoints);
|
||||
drawLine(context, plotPoints);
|
||||
drawXAxis(context, xScaleBounds);
|
||||
}
|
||||
|
||||
function scheduleDraw(): void {
|
||||
if (!mounted || typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (drawRequestId != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawRequestId = window.requestAnimationFrame((timestamp) => {
|
||||
drawRequestId = null;
|
||||
|
||||
if (lastDrawAt > 0 && timestamp - lastDrawAt < minDrawIntervalMs) {
|
||||
scheduleDraw();
|
||||
return;
|
||||
}
|
||||
|
||||
lastDrawAt = timestamp;
|
||||
drawCanvas();
|
||||
});
|
||||
return `${linePath} L ${lastPoint.x} ${viewportHeight - plotInsetBottom} L ${firstPoint.x} ${viewportHeight - plotInsetBottom} Z`;
|
||||
}
|
||||
|
||||
$: sourceYValues = yValues && yValues.length ? yValues : summary.points;
|
||||
$: sourceXValues = xValues && xValues.length ? xValues : summary.xValues ?? [];
|
||||
$: samples = buildSamples(sourceYValues, sourceXValues, currentTimeSeconds);
|
||||
$: samples = (() => {
|
||||
const base = buildSamples(sourceYValues, sourceXValues);
|
||||
if (isRealtime && base.length > 0 && currentTimeSeconds > 0) {
|
||||
const lastSample = base[base.length - 1];
|
||||
base[base.length - 1] = { ...lastSample, x: Math.max(lastSample.x, currentTimeSeconds) };
|
||||
}
|
||||
return base;
|
||||
})();
|
||||
$: sampleCount = samples.length;
|
||||
$: xScaleBounds = resolveXScaleBounds(samples, currentTimeSeconds, isRealtime);
|
||||
$: yScaleBounds = fixedYBounds;
|
||||
$: xDataBounds = resolveDataBounds(samples.map((sample) => sample.x));
|
||||
$: yDataBounds = resolveDataBounds(samples.map((sample) => sample.y));
|
||||
$: plotPoints = convertPoints(samples, xScaleBounds, yScaleBounds);
|
||||
$: linePath = createLinePath(plotPoints);
|
||||
$: areaPath = createAreaPath(plotPoints);
|
||||
$: lastPoint = plotPoints.length > 0 ? plotPoints[plotPoints.length - 1] : null;
|
||||
$: yAxisTicks = sampleCount > 0 ? buildYAxisTicks(yScaleBounds, yDataBounds) : [];
|
||||
$: xAxisTicks = sampleCount > 0 ? buildXAxisTicks(xScaleBounds) : [];
|
||||
$: latestValue = formatValue(summary.latest);
|
||||
$: minValue = formatValue(summary.min);
|
||||
$: maxValue = formatValue(summary.max);
|
||||
$: {
|
||||
sampleCount;
|
||||
plotPoints;
|
||||
xScaleBounds;
|
||||
locale;
|
||||
scheduleDraw();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
mounted = true;
|
||||
currentTimeSeconds = Math.round((Date.now() - sessionStartedAt) / 100) / 10;
|
||||
scheduleDraw();
|
||||
|
||||
timerId = setInterval(() => {
|
||||
if (!isRealtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentTimeSeconds = Math.round((Date.now() - sessionStartedAt) / 100) / 10;
|
||||
}, 500);
|
||||
|
||||
if (chartStageEl) {
|
||||
resizeObserver = new ResizeObserver(() => scheduleDraw());
|
||||
resizeObserver.observe(chartStageEl);
|
||||
}
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
if (timerId != null) clearInterval(timerId);
|
||||
if (drawRequestId != null) window.cancelAnimationFrame(drawRequestId);
|
||||
resizeObserver?.disconnect();
|
||||
timerId = null;
|
||||
drawRequestId = null;
|
||||
resizeObserver = null;
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<article
|
||||
@@ -399,8 +290,52 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="chart-stage" bind:this={chartStageEl}>
|
||||
<canvas class="summary-canvas" bind:this={canvasEl} aria-label={summary.label}></canvas>
|
||||
<div class="chart-stage">
|
||||
<svg viewBox="0 0 {viewportWidth} {viewportHeight}" preserveAspectRatio="none" role="img" aria-label={summary.label}>
|
||||
<defs>
|
||||
<linearGradient id="summary-fill" x1="0%" y1="0%" x2="0%" y2="100%">
|
||||
<stop offset="0%" stop-color="rgb(62 232 255 / 0.28)" />
|
||||
<stop offset="100%" stop-color="rgb(62 232 255 / 0.02)" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<g class="grid-lines" aria-hidden="true">
|
||||
{#each yAxisTicks as tick (`grid-${tick.value}`)}
|
||||
<line x1={plotInsetLeft} y1={tick.plotY} x2={viewportWidth - plotInsetRight} y2={tick.plotY}></line>
|
||||
{/each}
|
||||
</g>
|
||||
|
||||
{#if areaPath}
|
||||
<path d={areaPath} class="summary-area"></path>
|
||||
{/if}
|
||||
|
||||
{#if linePath}
|
||||
<path d={linePath} class="summary-line"></path>
|
||||
{/if}
|
||||
|
||||
{#if lastPoint}
|
||||
<circle cx={lastPoint.x} cy={lastPoint.y} r="1.7" class="summary-dot"></circle>
|
||||
{/if}
|
||||
|
||||
<g class="axis-labels" aria-hidden="true">
|
||||
{#each yAxisTicks as tick, index (`y-${index}`)}
|
||||
<text class="axis-label y-axis-label" x={tick.plotX} y={tick.plotY + 1.1} text-anchor="end">
|
||||
{tick.label}
|
||||
</text>
|
||||
{/each}
|
||||
|
||||
{#each xAxisTicks as tick, index (`x-${index}`)}
|
||||
<text
|
||||
class="axis-label x-axis-label"
|
||||
x={tick.plotX}
|
||||
y={tick.plotY}
|
||||
text-anchor={index === 0 ? "start" : index === xAxisTicks.length - 1 ? "end" : "middle"}
|
||||
>
|
||||
{tick.label}
|
||||
</text>
|
||||
{/each}
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
{#if sampleCount === 0}
|
||||
<div class="empty-state">
|
||||
@@ -454,7 +389,8 @@
|
||||
transition:
|
||||
opacity var(--fade-ms) cubic-bezier(0.18, 0.88, 0.3, 1),
|
||||
transform var(--enter-ms) cubic-bezier(0.2, 0.9, 0.28, 1),
|
||||
border-color 460ms ease;
|
||||
border-color 460ms ease,
|
||||
filter 760ms ease;
|
||||
transition-delay: calc(var(--panel-index) * 140ms);
|
||||
}
|
||||
|
||||
@@ -544,12 +480,53 @@
|
||||
radial-gradient(circle at 50% 0, rgb(var(--hud-glow-rgb) / 0.09), transparent 45%);
|
||||
}
|
||||
|
||||
.summary-canvas {
|
||||
svg {
|
||||
display: block;
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
}
|
||||
|
||||
.grid-lines line {
|
||||
stroke: rgb(var(--hud-border-strong-rgb) / 0.16);
|
||||
stroke-width: 0.45;
|
||||
}
|
||||
|
||||
.summary-area {
|
||||
fill: url(#summary-fill);
|
||||
}
|
||||
|
||||
.summary-line {
|
||||
fill: none;
|
||||
stroke: rgb(var(--hud-cyan-rgb) / 0.96);
|
||||
stroke-width: 1.35;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
filter: drop-shadow(0 0 4px rgb(var(--hud-cyan-rgb) / 0.22));
|
||||
}
|
||||
|
||||
.summary-dot {
|
||||
fill: rgb(var(--hud-lime-rgb) / 0.98);
|
||||
filter: drop-shadow(0 0 6px rgb(var(--hud-lime-rgb) / 0.3));
|
||||
}
|
||||
|
||||
.axis-label {
|
||||
fill: rgb(var(--hud-text-main-rgb) / 0.88);
|
||||
font-size: 3.2px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
text-shadow:
|
||||
0 1px 0 rgb(0 0 0 / 0.46),
|
||||
0 0 4px rgb(0 0 0 / 0.3);
|
||||
}
|
||||
|
||||
.y-axis-label {
|
||||
fill: rgb(var(--hud-text-dim-rgb) / 0.84);
|
||||
}
|
||||
|
||||
.x-axis-label {
|
||||
fill: rgb(var(--hud-text-dim-rgb) / 0.9);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
@@ -660,12 +637,6 @@
|
||||
@media (max-width: 900px) {
|
||||
.signal-panel {
|
||||
inline-size: 100%;
|
||||
background: linear-gradient(160deg, rgb(var(--hud-surface-alt-rgb) / 0.86) 0%, rgb(var(--hud-surface-deep-rgb) / 0.9) 100%);
|
||||
box-shadow: inset 0 0 0 1px rgb(var(--hud-border-strong-rgb) / 0.08), 0 0 8px rgb(var(--hud-glow-rgb) / 0.1);
|
||||
}
|
||||
|
||||
.chart-stage {
|
||||
background: linear-gradient(180deg, rgb(var(--hud-surface-alt-rgb) / 0.78), rgb(var(--hud-surface-deep-rgb) / 0.88));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,6 +3,7 @@ export type LocaleCode = "zh-CN" | "en-US";
|
||||
export type WindowControlAction = "minimize" | "toggle-maximize" | "close";
|
||||
|
||||
export type ConnectionState = "online" | "connecting" | "offline";
|
||||
export type StageViewMode = "webgl" | "model3d";
|
||||
|
||||
export type StageStatusTone = "ok" | "warn" | "idle";
|
||||
export type HudNoticeTone = "ok" | "warn" | "info";
|
||||
@@ -40,11 +41,18 @@ export interface HudSignalPanel {
|
||||
max: number | null;
|
||||
}
|
||||
|
||||
export interface HudSpatialForce {
|
||||
angleDeg: number;
|
||||
magnitude: number;
|
||||
confidence: number;
|
||||
}
|
||||
|
||||
export interface HudPacket {
|
||||
ts: number;
|
||||
panels: HudSignalPanel[];
|
||||
summary: HudSummary;
|
||||
pressureMatrix: number[] | null;
|
||||
spatialForce: HudSpatialForce | null;
|
||||
}
|
||||
|
||||
export interface HudSummary {
|
||||
@@ -86,6 +94,9 @@ export interface HudCopy {
|
||||
matrixViewLabel: string;
|
||||
matrixViewNumericLabel: string;
|
||||
matrixViewDotsLabel: string;
|
||||
stageModeLabel: string;
|
||||
stageModeWebglLabel: string;
|
||||
stageModeModelLabel: string;
|
||||
resetConfigLabel: string;
|
||||
applyLiveHint: string;
|
||||
runtimeReady: string;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
HudConfigLink,
|
||||
HudNoticeTone,
|
||||
HudPacket,
|
||||
HudSpatialForce,
|
||||
PressureColorMapPreset,
|
||||
HudSignalPanel,
|
||||
HudSignalSeries,
|
||||
@@ -33,6 +34,7 @@
|
||||
SerialRecordStateResult,
|
||||
SerialImportResult,
|
||||
SignalTone,
|
||||
StageViewMode,
|
||||
WindowControlAction
|
||||
} from "$lib/types/hud";
|
||||
|
||||
@@ -44,29 +46,13 @@
|
||||
dtsMs: number;
|
||||
}
|
||||
|
||||
interface AndroidUsbSerialDevice {
|
||||
name: string;
|
||||
vendorId: number;
|
||||
productId: number;
|
||||
manufacturer: string;
|
||||
product: string;
|
||||
serial: string;
|
||||
hasPermission: boolean;
|
||||
interface DevKitPztAngleEvent {
|
||||
seq: number;
|
||||
timestampMs: number;
|
||||
dtsMs: number;
|
||||
angle: number;
|
||||
}
|
||||
|
||||
interface AndroidUsbSerialListResult {
|
||||
devices: AndroidUsbSerialDevice[];
|
||||
}
|
||||
|
||||
interface AndroidUsbSerialOpenResult {
|
||||
fd: number;
|
||||
name: string;
|
||||
vendorId: number;
|
||||
productId: number;
|
||||
}
|
||||
|
||||
type AndroidUsbSerialCommand = "list" | "open" | "close";
|
||||
|
||||
const copyByLocale: Record<LocaleCode, HudCopy> = {
|
||||
"zh-CN": {
|
||||
appName: "JE-Skin",
|
||||
@@ -85,6 +71,9 @@
|
||||
matrixViewLabel: "矩阵模式",
|
||||
matrixViewNumericLabel: "数字矩阵",
|
||||
matrixViewDotsLabel: "点矩阵",
|
||||
stageModeLabel: "渲染模式",
|
||||
stageModeWebglLabel: "WebGL",
|
||||
stageModeModelLabel: "3D 模型",
|
||||
resetConfigLabel: "恢复默认",
|
||||
applyLiveHint: "实时生效 / 矩阵尺寸变更将重建 viewer",
|
||||
runtimeReady: "WEBGL2 READY",
|
||||
@@ -144,6 +133,9 @@
|
||||
matrixViewLabel: "Matrix Mode",
|
||||
matrixViewNumericLabel: "Numeric",
|
||||
matrixViewDotsLabel: "Dots",
|
||||
stageModeLabel: "Render Mode",
|
||||
stageModeWebglLabel: "WebGL",
|
||||
stageModeModelLabel: "3D Model",
|
||||
resetConfigLabel: "Reset",
|
||||
applyLiveHint: "Live apply / size changes recreate the viewer",
|
||||
runtimeReady: "WEBGL2 READY",
|
||||
@@ -191,7 +183,6 @@
|
||||
const pointsPerSeries = 28;
|
||||
const summaryPointsPerSeries = 42;
|
||||
const signalRenderTickMs = 1200;
|
||||
const hudRealtimeRenderMs = 33;
|
||||
const replayDefaultFrameMs = 40;
|
||||
const showSignalPanels = false;
|
||||
const mockToneCycle: SignalTone[] = ["cyan", "lime", "orange", "violet", "gold", "rose"];
|
||||
@@ -227,7 +218,6 @@
|
||||
let connectionState: ConnectionState = "offline";
|
||||
let serialPortValue = "COM14";
|
||||
let serialPortOptions = ["COM4", "COM9", "COM14", "COM16"];
|
||||
let androidUsbSerialDevices: AndroidUsbSerialDevice[] = [];
|
||||
let isRefreshingPorts = false;
|
||||
let connectionNotice = "";
|
||||
let connectionNoticeTone: HudNoticeTone = "info";
|
||||
@@ -246,12 +236,15 @@
|
||||
let signalPanels: HudSignalPanel[] = buildInactivePanels();
|
||||
let summary: HudSummary = buildEmptySummary();
|
||||
let pressureMatrix: number[] | null = null;
|
||||
let spatialForce: HudSpatialForce | null = null;
|
||||
let devkitSpatialForce: HudSpatialForce | null = null;
|
||||
let matrixRows = 12;
|
||||
let matrixCols = 7;
|
||||
let rangeMin = DEFAULT_PRESSURE_RANGE_MIN;
|
||||
let rangeMax = DEFAULT_PRESSURE_RANGE_MAX;
|
||||
let colorMapPreset: PressureColorMapPreset = "emerald";
|
||||
let matrixDisplayMode: MatrixDisplayMode = "dots";
|
||||
let stageViewMode: StageViewMode = "webgl";
|
||||
let replayFrames: ReplayFrame[] = [];
|
||||
let replayCurrentIndex = 0;
|
||||
let replayHasDisplayedFrame = false;
|
||||
@@ -285,10 +278,8 @@
|
||||
rowsKept: number;
|
||||
} | null = null;
|
||||
let devkitStatusTimer: number | null = null;
|
||||
let devkitSpatialForceClearTimer: number | null = null;
|
||||
let sessionStartedAt: number = Date.now();
|
||||
let pendingHudPacket: HudPacket | null = null;
|
||||
let hudFrameRequestId: number | null = null;
|
||||
let lastHudRenderAt = 0;
|
||||
|
||||
$: uiCopy = copyByLocale[locale];
|
||||
$: configLinks = buildConfigLinks(
|
||||
@@ -315,64 +306,29 @@
|
||||
return typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
|
||||
}
|
||||
|
||||
function isAndroidRuntime(): boolean {
|
||||
if (!isTauriRuntime() || typeof navigator === "undefined") {
|
||||
return false;
|
||||
function clearDevkitSpatialForce(): void {
|
||||
devkitSpatialForce = null;
|
||||
if (devkitSpatialForceClearTimer != null && typeof window !== "undefined") {
|
||||
window.clearTimeout(devkitSpatialForceClearTimer);
|
||||
devkitSpatialForceClearTimer = null;
|
||||
}
|
||||
|
||||
return /Android/i.test(navigator.userAgent);
|
||||
hasSignalData = signalPanels.length > 0 || summary.points.length > 0 || spatialForce !== null;
|
||||
}
|
||||
|
||||
function formatAndroidUsbSerialLabel(device: AndroidUsbSerialDevice): string {
|
||||
const product = device.product || device.manufacturer || "USB Serial";
|
||||
const ids = `${device.vendorId.toString(16).padStart(4, "0")}:${device.productId
|
||||
.toString(16)
|
||||
.padStart(4, "0")}`;
|
||||
return `${product} (${ids})`;
|
||||
}
|
||||
|
||||
function findAndroidUsbSerialDevice(name: string): AndroidUsbSerialDevice | null {
|
||||
return androidUsbSerialDevices.find((device) => device.name === name) ?? null;
|
||||
}
|
||||
|
||||
function normalizeAndroidUsbSerialDevices(value: unknown): AndroidUsbSerialDevice[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.filter((device): device is AndroidUsbSerialDevice => {
|
||||
return typeof device === "object" && device !== null && typeof (device as AndroidUsbSerialDevice).name === "string";
|
||||
});
|
||||
function scheduleDevkitSpatialForceClear(): void {
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === "object" && value !== null) {
|
||||
return Object.values(value).filter((device): device is AndroidUsbSerialDevice => {
|
||||
return typeof device === "object" && device !== null && typeof (device as AndroidUsbSerialDevice).name === "string";
|
||||
});
|
||||
if (devkitSpatialForceClearTimer != null) {
|
||||
window.clearTimeout(devkitSpatialForceClearTimer);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
async function invokeAndroidUsbSerial<T>(
|
||||
command: AndroidUsbSerialCommand,
|
||||
args?: Record<string, unknown>
|
||||
): Promise<T> {
|
||||
const commandNames: Record<AndroidUsbSerialCommand, [string, string]> = {
|
||||
list: ["usb_serial_list", "usbSerialList"],
|
||||
open: ["usb_serial_open", "usbSerialOpen"],
|
||||
close: ["usb_serial_close", "usbSerialClose"]
|
||||
};
|
||||
|
||||
const [primary, fallback] = commandNames[command];
|
||||
|
||||
try {
|
||||
return await invoke<T>(`plugin:usb-serial|${primary}`, args);
|
||||
} catch (error) {
|
||||
const message = String(error);
|
||||
if (!message.includes("No command")) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return await invoke<T>(`plugin:usb-serial|${fallback}`, args);
|
||||
}
|
||||
devkitSpatialForceClearTimer = window.setTimeout(() => {
|
||||
devkitSpatialForce = null;
|
||||
devkitSpatialForceClearTimer = null;
|
||||
hasSignalData = signalPanels.length > 0 || summary.points.length > 0 || spatialForce !== null;
|
||||
}, 420);
|
||||
}
|
||||
|
||||
function clamp(value: number, min: number, max: number): number {
|
||||
@@ -797,6 +753,8 @@
|
||||
|
||||
function resetReplayVisualState(): void {
|
||||
pressureMatrix = buildZeroMatrix();
|
||||
spatialForce = null;
|
||||
clearDevkitSpatialForce();
|
||||
signalPanels = buildInactivePanels();
|
||||
summary = buildEmptySummary();
|
||||
hasSignalData = false;
|
||||
@@ -814,10 +772,12 @@
|
||||
const safeIndex = clamp(index, 0, replayFrames.length - 1);
|
||||
const startIndex = Math.max(0, safeIndex - summaryPointsPerSeries + 1);
|
||||
const points: number[] = [];
|
||||
const xSeconds: number[] = [];
|
||||
for (let cursor = startIndex; cursor <= safeIndex; cursor += 1) {
|
||||
points.push(replayFrameTotal(replayFrames[cursor]));
|
||||
xSeconds.push(replayFrames[cursor].dtsMs / 1000);
|
||||
}
|
||||
return buildSummary(points);
|
||||
return buildSummary(points, xSeconds);
|
||||
}
|
||||
|
||||
function applyReplayFrame(index: number): void {
|
||||
@@ -830,9 +790,9 @@
|
||||
replayHasDisplayedFrame = true;
|
||||
replayProgress = replayFrames.length > 1 ? safeIndex / (replayFrames.length - 1) : 1;
|
||||
pressureMatrix = frameValuesToMatrix(replayFrames[safeIndex].values);
|
||||
if (signalPanels.length > 0) {
|
||||
signalPanels = buildInactivePanels();
|
||||
}
|
||||
spatialForce = null;
|
||||
clearDevkitSpatialForce();
|
||||
signalPanels = buildInactivePanels();
|
||||
summary = buildReplaySummaryAt(safeIndex);
|
||||
hasSignalData = true;
|
||||
}
|
||||
@@ -991,6 +951,7 @@
|
||||
function buildEmptySummary(): HudSummary {
|
||||
return {
|
||||
label: "Resultant Force",
|
||||
xValues: [],
|
||||
points: [],
|
||||
latest: null,
|
||||
min: null,
|
||||
@@ -1010,13 +971,19 @@
|
||||
return shouldHideSummary(summaryValue.points) ? buildEmptySummary() : summaryValue;
|
||||
}
|
||||
|
||||
function buildSummary(points: number[]): HudSummary {
|
||||
function buildSummary(points: number[], xValues: number[] = []): HudSummary {
|
||||
if (points.length === 0) {
|
||||
return buildEmptySummary();
|
||||
}
|
||||
|
||||
const resolvedXValues = points.map((_, index) => {
|
||||
const x = xValues[index];
|
||||
return Number.isFinite(x) ? Number(x) : index + 1;
|
||||
});
|
||||
|
||||
return {
|
||||
label: "Resultant Force",
|
||||
xValues: resolvedXValues,
|
||||
points,
|
||||
latest: points[points.length - 1],
|
||||
min: Math.min(...points),
|
||||
@@ -1041,13 +1008,21 @@
|
||||
? summaryValue.points[summaryValue.points.length - 1]
|
||||
: randomBetween(280, 1600);
|
||||
const next = Math.round(clamp(previous + randomBetween(-160, 160), 120, 2400) * 10) / 10;
|
||||
const nowSeconds = Math.round((Date.now() - sessionStartedAt) / 100) / 10;
|
||||
const previousXValues =
|
||||
summaryValue.xValues && summaryValue.xValues.length === summaryValue.points.length
|
||||
? summaryValue.xValues
|
||||
: summaryValue.points.map((_, index) => nowSeconds);
|
||||
const points =
|
||||
summaryValue.points.length >= summaryPointsPerSeries
|
||||
? summaryValue.points.slice(1)
|
||||
: summaryValue.points.slice();
|
||||
const xValues =
|
||||
previousXValues.length >= summaryPointsPerSeries ? previousXValues.slice(1) : previousXValues.slice();
|
||||
|
||||
points.push(next);
|
||||
return buildSummary(points);
|
||||
xValues.push(nowSeconds);
|
||||
return buildSummary(points, xValues);
|
||||
}
|
||||
|
||||
function buildInactivePanels(): HudSignalPanel[] {
|
||||
@@ -1058,81 +1033,45 @@
|
||||
if (replayHasData) {
|
||||
return;
|
||||
}
|
||||
if (showSignalPanels) {
|
||||
signalPanels = packet.panels;
|
||||
} else if (signalPanels.length > 0) {
|
||||
signalPanels = buildInactivePanels();
|
||||
signalPanels = showSignalPanels ? packet.panels : buildInactivePanels();
|
||||
if (packet.summary.points.length > 0) {
|
||||
const nowSeconds = Math.round((Date.now() - sessionStartedAt) / 100) / 10;
|
||||
const pointCount = packet.summary.points.length;
|
||||
const spacing =
|
||||
pointCount > 1 ? Math.min(1.2, nowSeconds / Math.max(pointCount - 1, 1)) : 0;
|
||||
const startX = Math.max(0, nowSeconds - spacing * Math.max(pointCount - 1, 0));
|
||||
const xValues = packet.summary.points.map((_, index) => Math.round((startX + index * spacing) * 10) / 10);
|
||||
summary = { ...packet.summary, xValues };
|
||||
} else {
|
||||
summary = packet.summary;
|
||||
}
|
||||
summary = packet.summary;
|
||||
pressureMatrix = packet.pressureMatrix;
|
||||
hasSignalData = signalPanels.length > 0 || packet.summary.points.length > 0;
|
||||
}
|
||||
|
||||
function getFrameClock(): number {
|
||||
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
||||
}
|
||||
|
||||
function cancelPendingHudPacket(): void {
|
||||
pendingHudPacket = null;
|
||||
if (hudFrameRequestId != null && typeof window !== "undefined") {
|
||||
window.cancelAnimationFrame(hudFrameRequestId);
|
||||
hudFrameRequestId = null;
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleHudPacketFlush(): void {
|
||||
if (hudFrameRequestId != null || typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
hudFrameRequestId = window.requestAnimationFrame(flushPendingHudPacket);
|
||||
}
|
||||
|
||||
function flushPendingHudPacket(timestamp: number = getFrameClock()): void {
|
||||
hudFrameRequestId = null;
|
||||
|
||||
if (!pendingHudPacket) {
|
||||
return;
|
||||
}
|
||||
|
||||
const elapsed = timestamp - lastHudRenderAt;
|
||||
if (lastHudRenderAt > 0 && elapsed < hudRealtimeRenderMs) {
|
||||
scheduleHudPacketFlush();
|
||||
return;
|
||||
}
|
||||
|
||||
const packet = pendingHudPacket;
|
||||
pendingHudPacket = null;
|
||||
lastHudRenderAt = timestamp;
|
||||
applyPacket(packet);
|
||||
}
|
||||
|
||||
function enqueueHudPacket(packet: HudPacket): void {
|
||||
if (replayHasData) {
|
||||
return;
|
||||
}
|
||||
|
||||
pendingHudPacket = packet;
|
||||
scheduleHudPacketFlush();
|
||||
spatialForce = packet.spatialForce ?? null;
|
||||
hasSignalData =
|
||||
signalPanels.length > 0 ||
|
||||
packet.summary.points.length > 0 ||
|
||||
spatialForce !== null ||
|
||||
devkitSpatialForce !== null;
|
||||
}
|
||||
|
||||
function clearHudPanels(): void {
|
||||
cancelPendingHudPacket();
|
||||
hasSignalData = false;
|
||||
signalPanels = buildInactivePanels();
|
||||
summary = buildEmptySummary();
|
||||
pressureMatrix = null;
|
||||
spatialForce = null;
|
||||
clearDevkitSpatialForce();
|
||||
}
|
||||
|
||||
function startMockFeed(push: (packet: HudPacket) => void): () => void {
|
||||
let panels = buildInactivePanels();
|
||||
let summaryValue = buildSummary(createSummaryPoints(randomBetween(480, 1440)));
|
||||
push({ ts: Date.now(), panels, summary: summaryValue, pressureMatrix: null });
|
||||
push({ ts: Date.now(), panels, summary: summaryValue, pressureMatrix: null, spatialForce: null });
|
||||
|
||||
const timerId = window.setInterval(() => {
|
||||
summaryValue = evolveSummary(summaryValue);
|
||||
|
||||
push({ ts: Date.now(), panels, summary: summaryValue, pressureMatrix: null });
|
||||
push({ ts: Date.now(), panels, summary: summaryValue, pressureMatrix: null, spatialForce: null });
|
||||
}, signalRenderTickMs);
|
||||
|
||||
return () => {
|
||||
@@ -1337,10 +1276,6 @@
|
||||
|
||||
function handlePortChange(event: CustomEvent<string>): void {
|
||||
serialPortValue = event.detail;
|
||||
if (isAndroidRuntime()) {
|
||||
const selectedDevice = findAndroidUsbSerialDevice(serialPortValue);
|
||||
deviceValue = selectedDevice ? formatAndroidUsbSerialLabel(selectedDevice) : "Android USB Serial";
|
||||
}
|
||||
connectionState = "offline";
|
||||
connectionNotice = "";
|
||||
clearHudPanels();
|
||||
@@ -1376,7 +1311,7 @@
|
||||
case "InvalidConfig":
|
||||
return "当前串口配置无效,请重新选择端口。";
|
||||
default:
|
||||
return `串口连接失败:${errorCode}`;
|
||||
return "串口连接失败,请稍后重试。";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1397,7 +1332,7 @@
|
||||
case "InvalidConfig":
|
||||
return "The selected serial port is invalid. Choose another port.";
|
||||
default:
|
||||
return `Connection failed: ${errorCode}`;
|
||||
return "Connection failed. Please try again.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1408,16 +1343,14 @@
|
||||
const errorCode = normalizeInvokeError(error);
|
||||
|
||||
if (locale === "zh-CN") {
|
||||
if (errorCode === "ScanError") {
|
||||
return "串口列表刷新失败,请确认系统串口服务正常。";
|
||||
}
|
||||
|
||||
return `刷新串口列表失败:${errorCode}`;
|
||||
return errorCode === "ScanError"
|
||||
? "串口列表刷新失败,请确认系统串口服务正常。"
|
||||
: "刷新串口列表失败,请稍后重试。";
|
||||
}
|
||||
|
||||
return errorCode === "ScanError"
|
||||
? "Refreshing serial ports failed. Check whether the OS serial service is available."
|
||||
: `Refreshing serial ports failed: ${errorCode}`;
|
||||
: "Refreshing serial ports failed. Please try again.";
|
||||
}
|
||||
|
||||
function resolveExportNotice(error: unknown): string {
|
||||
@@ -1472,33 +1405,6 @@
|
||||
isRefreshingPorts = true;
|
||||
|
||||
try {
|
||||
try {
|
||||
const result = await invokeAndroidUsbSerial<AndroidUsbSerialListResult>("list");
|
||||
androidUsbSerialDevices = normalizeAndroidUsbSerialDevices(result.devices);
|
||||
serialPortOptions = androidUsbSerialDevices.map((device) => device.name);
|
||||
|
||||
if (serialPortOptions.includes(serialPortValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
serialPortValue = serialPortOptions[0] ?? "";
|
||||
const selectedDevice = findAndroidUsbSerialDevice(serialPortValue);
|
||||
deviceValue = selectedDevice ? formatAndroidUsbSerialLabel(selectedDevice) : "Android USB Serial";
|
||||
|
||||
if (!serialPortValue) {
|
||||
connectionState = "offline";
|
||||
clearHudPanels();
|
||||
connectionNotice =
|
||||
locale === "zh-CN" ? "未发现 USB 串口设备,请确认已通过 OTG 接入设备。" : "No USB serial device found.";
|
||||
connectionNoticeTone = "warn";
|
||||
}
|
||||
return;
|
||||
} catch (androidError) {
|
||||
if (isAndroidRuntime()) {
|
||||
throw androidError;
|
||||
}
|
||||
}
|
||||
|
||||
const ports = await invoke<string[]>("serial_enum");
|
||||
serialPortOptions = ports;
|
||||
|
||||
@@ -1539,28 +1445,7 @@
|
||||
connectionNotice = "";
|
||||
|
||||
try {
|
||||
let result: SerialConnectResult;
|
||||
|
||||
if (isAndroidRuntime()) {
|
||||
const selectedDevice = findAndroidUsbSerialDevice(event.detail);
|
||||
const opened = await invokeAndroidUsbSerial<AndroidUsbSerialOpenResult>("open", {
|
||||
name: event.detail,
|
||||
vendorId: selectedDevice?.vendorId,
|
||||
productId: selectedDevice?.productId
|
||||
});
|
||||
result = await invoke<SerialConnectResult>("serial_connect_fd", {
|
||||
fd: opened.fd,
|
||||
deviceName: opened.name,
|
||||
device_name: opened.name
|
||||
});
|
||||
const openedDevice = findAndroidUsbSerialDevice(opened.name) ?? selectedDevice;
|
||||
deviceValue = openedDevice
|
||||
? formatAndroidUsbSerialLabel(openedDevice)
|
||||
: `USB Serial (${opened.vendorId.toString(16)}:${opened.productId.toString(16)})`;
|
||||
} else {
|
||||
result = await invoke<SerialConnectResult>("serial_connect", { port: event.detail });
|
||||
}
|
||||
|
||||
const result = await invoke<SerialConnectResult>("serial_connect", { port: event.detail });
|
||||
connectionState = result.connected ? "online" : "offline";
|
||||
serialPortValue = result.port;
|
||||
connectionNotice = "";
|
||||
@@ -1568,13 +1453,6 @@
|
||||
clearHudPanels();
|
||||
console.info("[serial] connect result:", result.message);
|
||||
} catch (error) {
|
||||
if (isAndroidRuntime()) {
|
||||
try {
|
||||
await invokeAndroidUsbSerial("close");
|
||||
} catch (closeError) {
|
||||
console.warn("USB serial close after failed connect failed:", closeError);
|
||||
}
|
||||
}
|
||||
connectionState = "offline";
|
||||
connectionNotice = resolveSerialNotice(error, "connect");
|
||||
connectionNoticeTone = "warn";
|
||||
@@ -1586,9 +1464,6 @@
|
||||
async function handleSerialDisconnect(): Promise<void> {
|
||||
try {
|
||||
const result = await invoke<SerialConnectResult>("serial_disconnect");
|
||||
if (isAndroidRuntime()) {
|
||||
await invokeAndroidUsbSerial("close");
|
||||
}
|
||||
connectionState = result.connected ? "online" : "offline";
|
||||
connectionNotice = "";
|
||||
connectionNoticeTone = "info";
|
||||
@@ -1824,6 +1699,7 @@
|
||||
|
||||
function handleConfigLink(event: CustomEvent<string>): void {
|
||||
if (event.detail === "precision-test") {
|
||||
stageViewMode = "webgl";
|
||||
isPrecisionTestOpen = !isPrecisionTestOpen;
|
||||
isConfigPanelOpen = false;
|
||||
isDevKitConfigOpen = false;
|
||||
@@ -1831,6 +1707,7 @@
|
||||
}
|
||||
|
||||
if (event.detail === "settings") {
|
||||
stageViewMode = "webgl";
|
||||
isPrecisionTestOpen = false;
|
||||
isConfigPanelOpen = !isConfigPanelOpen;
|
||||
isDevKitConfigOpen = false;
|
||||
@@ -1923,6 +1800,14 @@
|
||||
matrixDisplayMode = event.detail ? "dots" : "numeric";
|
||||
}
|
||||
|
||||
function handleStageModeChange(event: CustomEvent<StageViewMode>): void {
|
||||
stageViewMode = event.detail;
|
||||
if (stageViewMode === "model3d") {
|
||||
isPrecisionTestOpen = false;
|
||||
isConfigPanelOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
let disposed = false;
|
||||
let unlistenHudStream: UnlistenFn | null = null;
|
||||
@@ -1938,7 +1823,7 @@
|
||||
void checkForAppUpdate();
|
||||
void pollDevKitStatus();
|
||||
devkitStatusTimer = window.setInterval(() => void pollDevKitStatus(), 3000);
|
||||
void startTauriHudStream(enqueueHudPacket)
|
||||
void startTauriHudStream(applyPacket)
|
||||
.then((unlisten) => {
|
||||
if (disposed) {
|
||||
unlisten();
|
||||
@@ -1950,12 +1835,25 @@
|
||||
.catch((error) => {
|
||||
console.error("Failed to listen for hud_stream:", error);
|
||||
});
|
||||
void listen<{ seq: number; timestampMs: number; dtsMs: number; angle: number }>(
|
||||
"devkit_pzt_angle",
|
||||
(event) => {
|
||||
console.log("[devkit_pzt_angle]", event.payload);
|
||||
void listen<DevKitPztAngleEvent>("devkit_pzt_angle", (event) => {
|
||||
const angleDeg = Number(event.payload.angle);
|
||||
if (!Number.isFinite(angleDeg)) {
|
||||
clearDevkitSpatialForce();
|
||||
return;
|
||||
}
|
||||
)
|
||||
|
||||
devkitSpatialForce = {
|
||||
angleDeg,
|
||||
magnitude: 0,
|
||||
confidence: 0
|
||||
};
|
||||
scheduleDevkitSpatialForceClear();
|
||||
hasSignalData =
|
||||
signalPanels.length > 0 ||
|
||||
summary.points.length > 0 ||
|
||||
spatialForce !== null ||
|
||||
devkitSpatialForce !== null;
|
||||
})
|
||||
.then((unlisten) => {
|
||||
if (disposed) {
|
||||
unlisten();
|
||||
@@ -1968,13 +1866,13 @@
|
||||
console.error("Failed to listen for devkit_pzt_angle:", error);
|
||||
});
|
||||
} else {
|
||||
stopMockFeed = startMockFeed(enqueueHudPacket);
|
||||
stopMockFeed = startMockFeed(applyPacket);
|
||||
}
|
||||
|
||||
return () => {
|
||||
disposed = true;
|
||||
cancelPendingHudPacket();
|
||||
pauseReplayPlayback();
|
||||
clearDevkitSpatialForce();
|
||||
stopMockFeed?.();
|
||||
unlistenHudStream?.();
|
||||
unlistenDevkitPztAngle?.();
|
||||
@@ -2019,6 +1917,10 @@
|
||||
matrixViewNumericLabel={uiCopy.matrixViewNumericLabel}
|
||||
matrixViewDotsLabel={uiCopy.matrixViewDotsLabel}
|
||||
{matrixDisplayMode}
|
||||
stageModeLabel={uiCopy.stageModeLabel}
|
||||
stageModeWebglLabel={uiCopy.stageModeWebglLabel}
|
||||
stageModeModelLabel={uiCopy.stageModeModelLabel}
|
||||
{stageViewMode}
|
||||
connectActionLabel={uiCopy.connectActionLabel}
|
||||
disconnectActionLabel={uiCopy.disconnectActionLabel}
|
||||
exportActionLabel={uiCopy.exportActionLabel}
|
||||
@@ -2041,6 +1943,7 @@
|
||||
on:portchange={handlePortChange}
|
||||
on:configlink={handleConfigLink}
|
||||
on:matrixdisplaytoggle={handleMatrixDisplayToggle}
|
||||
on:stagemodechange={handleStageModeChange}
|
||||
on:serialrefresh={handleSerialRefresh}
|
||||
on:serialconnect={handleSerialConnect}
|
||||
on:serialexport={handleSerialExportRequest}
|
||||
@@ -2061,6 +1964,7 @@
|
||||
bind:rangeMax
|
||||
bind:colorMapPreset
|
||||
bind:matrixDisplayMode
|
||||
{stageViewMode}
|
||||
configPanelTitle={uiCopy.configPanelTitle}
|
||||
configPanelHint={uiCopy.configPanelHint}
|
||||
matrixSizeLabel={uiCopy.matrixSizeLabel}
|
||||
@@ -2087,6 +1991,8 @@
|
||||
leftPanels={leftSignalPanels}
|
||||
rightPanels={rightSignalPanels}
|
||||
{pressureMatrix}
|
||||
{spatialForce}
|
||||
{devkitSpatialForce}
|
||||
showConfigPanel={isConfigPanelOpen}
|
||||
showPrecisionTestPanel={isPrecisionTestOpen}
|
||||
{summary}
|
||||
@@ -2097,7 +2003,7 @@
|
||||
on:replayclose={handleReplayClose}
|
||||
on:configclose={() => (isConfigPanelOpen = false)}
|
||||
>
|
||||
{#if !isPrecisionTestOpen}
|
||||
{#if !isPrecisionTestOpen && stageViewMode === "webgl"}
|
||||
<section class="range-scale" aria-label="Signal Range">
|
||||
<p class="range-label">{locale === "zh-CN" ? "范围" : "Range"}</p>
|
||||
<div class="range-track">
|
||||
@@ -2195,27 +2101,6 @@
|
||||
mix-blend-mode: soft-light;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.hud-noise {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hud-vignette {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.hud-gradient {
|
||||
background:
|
||||
linear-gradient(170deg, var(--hud-bg-20) 0%, var(--hud-bg-10) 56%, var(--hud-bg-30) 100%);
|
||||
}
|
||||
|
||||
.hud-layout {
|
||||
gap: clamp(0.3rem, 1vw, 0.6rem);
|
||||
padding: clamp(0.4rem, 1.2vw, 0.8rem);
|
||||
box-shadow: inset 0 -12px 24px rgb(0 0 0 / 0.24);
|
||||
}
|
||||
}
|
||||
|
||||
.hud-layout {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
|
||||
14
static/models/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# 3D model assets
|
||||
|
||||
Put the first pipeline model here:
|
||||
|
||||
- Preferred: `static/models/je-skin-model.glb`
|
||||
- Format: glTF 2.0 `.glb`
|
||||
- Also supported after changing `modelUrl`: glTF 2.0 `.gltf` with its `.bin` and texture files in the same folder
|
||||
- Not supported directly: older glTF 1.0 assets. Convert them to glTF 2.0 first.
|
||||
|
||||
Runtime URL used by the app:
|
||||
|
||||
```text
|
||||
/models/je-skin-model.glb
|
||||
```
|
||||