init
No files matched your search
@@ -0,0 +1,25 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
.workbuddy
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"Vue.volar",
|
||||||
|
"tauri-apps.tauri-vscode",
|
||||||
|
"rust-lang.rust-analyzer"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1 +1,97 @@
|
|||||||
LFMusic
|
# LFMusic
|
||||||
|
|
||||||
|
一款基于 **Tauri 2 + Vue 3 + TypeScript** 的跨端音乐播放器,主打 **Android 本地播放**与 **USB DAC bit-perfect 直出**,同时支持飞牛 fnOS NAS 曲库与手机遥控。
|
||||||
|
|
||||||
|
## 功能概览
|
||||||
|
|
||||||
|
应用包含四个主 Tab:
|
||||||
|
|
||||||
|
| 模块 | 说明 |
|
||||||
|
| --- | --- |
|
||||||
|
| **曲库**(LibraryView) | 本地音乐库:扫描共享存储 Music/Download 目录,`lofty` 提取元数据/内嵌封面,SQLite 索引;支持歌曲/专辑/歌手三种视图、封面墙、扫描进度实时推送 |
|
||||||
|
| **飞牛**(FeiniuView) | 飞牛 fnOS 音乐曲库接入:登录、曲库浏览(含 DSD 格式徽标)、歌词、封面;曲目经本机 axum 流代理(支持 Range 透传)播放,DSD 系列/加密格式正确标记 |
|
||||||
|
| **遥控**(RemoteView) | 手机遥控客户端:UDP beacon 自动发现(`:26123`)、Rust 侧配对(绕开 WebView CORS)、WebSocket 双向控制(播放/暂停/切歌/进度) |
|
||||||
|
| **输出**(UacView) | USB DAC bit-perfect 直出:UsbManager 授权 → fd 桥接 libusb → UAC 描述符解析与能力枚举 → iso 传输引擎 + symphonia 解码(PCM 直喂 DAC),支持音量控制 |
|
||||||
|
|
||||||
|
播放层为**编排式设计**:`tauri-plugin-native-audio`(Media3 ExoPlayer / AVPlayer)只提供原语,队列与播放模式(顺序/随机)由 Rust 侧 `player.rs` 统一决策,所有命令返回最新队列状态。
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
|
||||||
|
- **前端**:Vue 3(`<script setup>`)+ TypeScript + Pinia + Tailwind CSS v4 + Vite + lucide-vue-next + vue-sonner
|
||||||
|
- **后端**:Tauri 2(Rust)——axum、reqwest、lofty、walkdir、rusqlite(bundled)、symphonia、rusb/libusb1-sys
|
||||||
|
- **移动端**:Android(Media3 ExoPlayer 原生播放、Kotlin 桥接插件);桌面端同步支持
|
||||||
|
- **包管理**:bun(`bun.lock`)
|
||||||
|
|
||||||
|
## 项目结构
|
||||||
|
|
||||||
|
```
|
||||||
|
src/ # 前端(Vue + TS)
|
||||||
|
├── views/ # 四大页面:LibraryView / FeiniuView / UacView
|
||||||
|
├── components/ # MiniBar(迷你播放条)、player/(全屏播放器、队列)
|
||||||
|
├── stores/ # Pinia:playerStore(播放状态真源镜像)、feiniuStore
|
||||||
|
└── lib/ # audio 初始化、uac、remote-proto(遥控协议类型)、
|
||||||
|
# format / img / permissions 等工具层
|
||||||
|
|
||||||
|
src-tauri/
|
||||||
|
├── src/
|
||||||
|
│ ├── library.rs # 本地曲库:扫描 + 元数据 + SQLite 索引
|
||||||
|
│ ├── player.rs # 播放编排:队列 + 播放模式决策(真源)
|
||||||
|
│ ├── feiniu/ # 飞牛 fnOS:登录签名、曲库 API、axum 流代理
|
||||||
|
│ ├── remote.rs # 遥控:beacon 监听 + 配对(Rust 侧 POST)
|
||||||
|
│ └── uac/ # UAC:描述符解析、iso 传输引擎、播放控制
|
||||||
|
├── media-plugin/ # 自研「media」插件壳:Android 媒体权限 ACL 载体
|
||||||
|
├── usb-plugin/ # 自研「usb」插件壳:Kotlin UsbPlugin 桥(fd 桥接)
|
||||||
|
├── capabilities/ # Tauri ACL 权限清单
|
||||||
|
└── tauri.conf.json # asset 协议 scope(封面)、bundle 配置
|
||||||
|
```
|
||||||
|
|
||||||
|
关键设计约定:
|
||||||
|
|
||||||
|
- **协议类型双端对齐**:`src/lib/remote-proto.ts` 与 Rust `remote.rs` 手写镜像,字段变更须同步两处。
|
||||||
|
- **飞牛模块字段级对齐**:与参考项目 Thing 的 `music/feiniu/` 保持同一套 NAS API 口径,双端不得私自漂移。
|
||||||
|
- **播放 URL 同字段语义**:NAS 曲目 `path` 即本机代理 URL,与本地曲库绝对路径一致,编排层零分支。
|
||||||
|
- **凭证存储**:token 存应用私有目录(`feiniu_tokens.json` / `remote_device.json`),keyring 升级留待后续。
|
||||||
|
|
||||||
|
## 开发
|
||||||
|
|
||||||
|
### 环境要求
|
||||||
|
|
||||||
|
- [bun](https://bun.sh)(或 Node.js ≥ 22)
|
||||||
|
- [Rust](https://rustup.dev)(stable)
|
||||||
|
- Android:Android Studio + SDK/NDK(Tauri 2 移动端开发环境,参考 [Tauri Android 文档](https://tauri.app/start/prerequisites/))
|
||||||
|
|
||||||
|
### 常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装依赖
|
||||||
|
bun install
|
||||||
|
|
||||||
|
# 前端开发服务器(Vite,端口 1420)
|
||||||
|
bun run dev
|
||||||
|
|
||||||
|
# 类型检查 + 前端构建
|
||||||
|
bun run build
|
||||||
|
|
||||||
|
# 桌面端开发(自动拉起 Vite)
|
||||||
|
bun tauri dev
|
||||||
|
|
||||||
|
# 桌面端打包
|
||||||
|
bun tauri build
|
||||||
|
|
||||||
|
# Android 开发 / 打包
|
||||||
|
bun tauri android init # 首次
|
||||||
|
bun tauri android dev
|
||||||
|
bun tauri android build
|
||||||
|
```
|
||||||
|
|
||||||
|
### 注意事项
|
||||||
|
|
||||||
|
- **Android 媒体权限**:本地曲库扫描需要 `READ_MEDIA_AUDIO` 授权,应用内会引导申请。
|
||||||
|
- **加密格式**:文件名含 `kgm` / `ncm` / `mflac` 等加密标记的文件会被扫描自动跳过(无法解码)。
|
||||||
|
- **封面加载**:走 Tauri asset 协议,scope 限定为 `$APPDATA/covers/**`。
|
||||||
|
- **NAS 自签名证书**:飞牛连接使用 rustls + `danger_accept_invalid_certs`,适配 NAS 自签名 HTTPS。
|
||||||
|
- **UAC 独占**:播放期间 USB 接口被引擎独占 claim,停止后需重新「接入」设备。
|
||||||
|
|
||||||
|
## IDE 推荐
|
||||||
|
|
||||||
|
- [VS Code](https://code.visualstudio.com/) + [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||||
@@ -0,0 +1,302 @@
|
|||||||
|
{
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"configVersion": 1,
|
||||||
|
"workspaces": {
|
||||||
|
"": {
|
||||||
|
"name": "lfmusic",
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^2",
|
||||||
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
|
"lucide-vue-next": "^1.0.0",
|
||||||
|
"pinia": "^4.0.3",
|
||||||
|
"tauri-plugin-native-audio-api": "^1.0.5",
|
||||||
|
"vue": "^3.5.13",
|
||||||
|
"vue-sonner": "^2.0.9",
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/vite": "^4.3.3",
|
||||||
|
"@tauri-apps/cli": "^2",
|
||||||
|
"@vitejs/plugin-vue": "^6.0.7",
|
||||||
|
"tailwindcss": "^4.3.3",
|
||||||
|
"typescript": "~6.0.3",
|
||||||
|
"vite": "^8.0.16",
|
||||||
|
"vue-tsc": "^3.3.5",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"packages": {
|
||||||
|
"@babel/helper-string-parser": ["@babel/helper-string-parser@7.29.7", "https://registry.npmmirror.com/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz", {}, "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw=="],
|
||||||
|
|
||||||
|
"@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.29.7", "https://registry.npmmirror.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", {}, "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg=="],
|
||||||
|
|
||||||
|
"@babel/parser": ["@babel/parser@7.29.9", "https://registry.npmmirror.com/@babel/parser/-/parser-7.29.9.tgz", { "dependencies": { "@babel/types": "^7.29.8" }, "bin": "./bin/babel-parser.js" }, "sha512-CjXrNHTnvqBVqHgdBysY3vk2T8tpJHb5/RMeHJBTyVa9xgugCB0CJTx/3oO8RV2QRQP391RWpB7D6hLjm8V9uA=="],
|
||||||
|
|
||||||
|
"@babel/types": ["@babel/types@7.29.8", "https://registry.npmmirror.com/@babel/types/-/types-7.29.8.tgz", { "dependencies": { "@babel/helper-string-parser": "^7.29.7", "@babel/helper-validator-identifier": "^7.29.7" } }, "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg=="],
|
||||||
|
|
||||||
|
"@jridgewell/gen-mapping": ["@jridgewell/gen-mapping@0.3.13", "https://registry.npmmirror.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA=="],
|
||||||
|
|
||||||
|
"@jridgewell/remapping": ["@jridgewell/remapping@2.3.5", "https://registry.npmmirror.com/@jridgewell/remapping/-/remapping-2.3.5.tgz", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ=="],
|
||||||
|
|
||||||
|
"@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.2", "https://registry.npmmirror.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", {}, "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw=="],
|
||||||
|
|
||||||
|
"@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "https://registry.npmmirror.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="],
|
||||||
|
|
||||||
|
"@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "https://registry.npmmirror.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="],
|
||||||
|
|
||||||
|
"@oxc-project/types": ["@oxc-project/types@0.151.0", "https://registry.npmmirror.com/@oxc-project/types/-/types-0.151.0.tgz", {}, "sha512-J1yXrIlNDZVzE3ada310xeAw7nH8yCAyLPuUIsjKatFPmfn5bS1oW+cM+QsGOtVWd5nhSpbwZWx/rue+r5Z+PA=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.11.tgz", { "os": "android", "cpu": "arm" }, "sha512-A5kXfGKvKWWZE0TtPrfsvT+q4Y5d1QG8gGUzpYjGydM+fARM9MuX90PrXYXe0XbsDVgyxxNzHo6giCj90bsFNw=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.11.tgz", { "os": "android", "cpu": "arm64" }, "sha512-z6cTycz+iJ4PVkuL4HHW4DfTfoeU/2nqYYuSOrTmH7yHK5Y0LCOnA03V4ZNxavyVaU1oOqUgIg2klN/s+USGOA=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-darwin-arm64": ["@rolldown/binding-darwin-arm64@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.11.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-jShvqNtP6vDC6/A5JOAzbVV+DkgHqhl/ScVCJEbt+TUY6QYz7YnXcrg3sLtFBniro0f/Ld50ZwCWA6f7KYD1nQ=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-darwin-x64": ["@rolldown/binding-darwin-x64@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.11.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-f2i2xiNWq1Z1l2++q2fuhZRdLAT3aqxD6vRNm1RAxpUoBcdqNB3C0s1Bt+K+PbEx2F5F4gQp6hqKkphCY/xF9w=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-freebsd-x64": ["@rolldown/binding-freebsd-x64@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.11.tgz", { "os": "freebsd", "cpu": "x64" }, "sha512-4Ir5FSOKIAMr4r0kExpt1s3bMgzJU3rA45AYOHtQpls0oNeqcYBKrWMlckrYH4KCfGLfkfn1tN1dmZPMVsdXow=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-linux-arm-gnueabihf": ["@rolldown/binding-linux-arm-gnueabihf@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.11.tgz", { "os": "linux", "cpu": "arm" }, "sha512-/gnRDM+39BROzAN/k1OZjDPnDMcZxB/0EUxKjONO5yVkNEvlsoMDrxGNKgZi/ttFriS2gwlDNzB65pvNbFOXIQ=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-linux-arm64-gnu": ["@rolldown/binding-linux-arm64-gnu@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.11.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-PFaK8HwvAHbaKbBcDNQihjMKYvFnA5hiENx/l5tphTDz1E0WFp32l0A7aq7lyUwGsRw/xSrNIy/gIK4thrSCrw=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-linux-arm64-musl": ["@rolldown/binding-linux-arm64-musl@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.11.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-AskzJUIKRLPxkruR1wLKewGbOw+EYfU/9lOrBFj4AFrEA8hPpKFnODWNu2WLaNs0QNkEb9QIJufmVZZIL/bJlg=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-linux-ppc64-gnu": ["@rolldown/binding-linux-ppc64-gnu@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.11.tgz", { "os": "linux", "cpu": "ppc64" }, "sha512-qlUGAheh2yh8afH7QBgx0PrRHN85hKnNd78x8MeMhXivuevgd8vgf6/CstOzmNKY/lLTHvNTrPy98cLnAugzJw=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-linux-s390x-gnu": ["@rolldown/binding-linux-s390x-gnu@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.11.tgz", { "os": "linux", "cpu": "s390x" }, "sha512-secpEad+0vCbSfn8upFySkDskv+bGPk3THSDS9Y89yc4rb4kzqHp8Dmyd9BkQW4SnhNXBZCl/6CrO//hZahNJQ=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-linux-x64-gnu": ["@rolldown/binding-linux-x64-gnu@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.11.tgz", { "os": "linux", "cpu": "x64" }, "sha512-mOVBT3dPpkWm8XBWPmU4bf+U6dYDLeMo/9ojUmis4N0L5uu10qra5vOyngZ7/PSdoE4G9KvRt4bloRxNjLas7A=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-linux-x64-musl": ["@rolldown/binding-linux-x64-musl@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.11.tgz", { "os": "linux", "cpu": "x64" }, "sha512-Is78i9A8Ui4SqcxUwFJ9uMmjDn58IbVTjFWYdQestFEgeuEmHMLGNriXnVJKkwG2YiZjw8cP0zCTyDMdDGtOOg=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-openharmony-arm64": ["@rolldown/binding-openharmony-arm64@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.11.tgz", { "os": "none", "cpu": "arm64" }, "sha512-dUCXneZ87INUMyQ0D+C0HrEBNUPNXHaPmU5GTjyKTJEiussw9Kaj5Ln8UztPe4epV/ffvgNBEadksdYhmW6xJA=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-win32-arm64-msvc": ["@rolldown/binding-win32-arm64-msvc@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.11.tgz", { "os": "win32", "cpu": "arm64" }, "sha512-jByxb6qfd+bH1xUd0qnfFnb17i9sWBPY2tOavJ0l3tdr3OTu+Kvtm8cd/JV5nFt657b1VqGltxg9olOEfofXWw=="],
|
||||||
|
|
||||||
|
"@rolldown/binding-win32-x64-msvc": ["@rolldown/binding-win32-x64-msvc@1.2.11", "https://registry.npmmirror.com/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.11.tgz", { "os": "win32", "cpu": "x64" }, "sha512-/PzKqzAJ03i19oy2ItPvyvaVjOjBCNnfaJs8yvUdGBKmiESgnrJSQ2awd81QzFbbnAmu7YO9ZnJrDCb9VSJPRA=="],
|
||||||
|
|
||||||
|
"@rolldown/pluginutils": ["@rolldown/pluginutils@1.0.1", "https://registry.npmmirror.com/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", {}, "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node": ["@tailwindcss/node@4.3.3", "https://registry.npmmirror.com/@tailwindcss/node/-/node-4.3.3.tgz", { "dependencies": { "@jridgewell/remapping": "^2.3.5", "enhanced-resolve": "^5.24.1", "jiti": "^2.7.0", "lightningcss": "1.32.0", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.3.3" } }, "sha512-/T8IKEsf9VTU6tLjgC7+sv2mOPtQxzE2jMw7u4Tt40Tx+QSZxpzh95/H6cMKoja9XuW7iMdLJYBB0o9G1CaAgg=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide": ["@tailwindcss/oxide@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide/-/oxide-4.3.3.tgz", { "optionalDependencies": { "@tailwindcss/oxide-android-arm64": "4.3.3", "@tailwindcss/oxide-darwin-arm64": "4.3.3", "@tailwindcss/oxide-darwin-x64": "4.3.3", "@tailwindcss/oxide-freebsd-x64": "4.3.3", "@tailwindcss/oxide-linux-arm-gnueabihf": "4.3.3", "@tailwindcss/oxide-linux-arm64-gnu": "4.3.3", "@tailwindcss/oxide-linux-arm64-musl": "4.3.3", "@tailwindcss/oxide-linux-x64-gnu": "4.3.3", "@tailwindcss/oxide-linux-x64-musl": "4.3.3", "@tailwindcss/oxide-wasm32-wasi": "4.3.3", "@tailwindcss/oxide-win32-arm64-msvc": "4.3.3", "@tailwindcss/oxide-win32-x64-msvc": "4.3.3" } }, "sha512-krXjAikiaFSPaK/FkAQT5UTx3VormQaiZ5hBFlJZ9UFQGB/rwg1MZIhHAG9smMQRTdyJxP6Qt5MwMtdyU5FWrA=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-android-arm64": ["@tailwindcss/oxide-android-arm64@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.3.3.tgz", { "os": "android", "cpu": "arm64" }, "sha512-Y85A2gmPSkl5Ve5qR86GL4HT509cFqQh1aes9p3sSkyTPwt0Pppf3GkwGe4JPACcRYjgJIEhQgM6dBClnr0NYw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-darwin-arm64": ["@tailwindcss/oxide-darwin-arm64@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.3.3.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-BiaWatpBcERQFDlOjRDpIVXuFK5PJez5SA4JMg6VYZdBYU+qKfV/vqjcIs+IYmtitf1xYQZTwXvU/8y4lfZUGw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-darwin-x64": ["@tailwindcss/oxide-darwin-x64@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.3.3.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-fAeUqfV5ndhxRwai8cXGzdLvul9utWOmeTkv69unv4ZXixjn61Z+p9lCWdwOwA3TYboG3BwdVuN/RDjhBRl0mw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-freebsd-x64": ["@tailwindcss/oxide-freebsd-x64@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.3.3.tgz", { "os": "freebsd", "cpu": "x64" }, "sha512-iyf5bV6+wnAlflVeEy7R25dupxTNECZN5QMI0qNT6eT+EgaGdZcKhGkr5SdoaWiLJ3spLqIY9VCeSGrwmtg4kw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-linux-arm-gnueabihf": ["@tailwindcss/oxide-linux-arm-gnueabihf@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.3.3.tgz", { "os": "linux", "cpu": "arm" }, "sha512-aAYUprJAJQWWbRrPvtjdroZ56Md+JM8pMiopS6xGEwDfLhqj+2ver2p4nU4Mb3CRqcMmNBjo8KkUgcxhkzVQGQ=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-linux-arm64-gnu": ["@tailwindcss/oxide-linux-arm64-gnu@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.3.3.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-nDxldcEENOxZRzC2uu9jrutZdAAQtb+8WWDCSnWL1zvBk1+FN+x6MtDViPB5AJMfttVCUhehGWus3XBPgatM/w=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-linux-arm64-musl": ["@tailwindcss/oxide-linux-arm64-musl@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.3.3.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-Md44bD6veX/PC5iyF8cDVnw4HBIANZepRZZ7a8DQOvkfo5WUBwcp6iAuCUz23u+4SUkhJlD3eL7hNdW8ezd/kA=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-linux-x64-gnu": ["@tailwindcss/oxide-linux-x64-gnu@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.3.3.tgz", { "os": "linux", "cpu": "x64" }, "sha512-tx7us1muwOKAKWao2v/GaafFeQboE6aj88vC6ziN2NCGcRm8gWUhwjzg+YdVB1e4boAtdtma4L43onunI6NS4w=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-linux-x64-musl": ["@tailwindcss/oxide-linux-x64-musl@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.3.3.tgz", { "os": "linux", "cpu": "x64" }, "sha512-SJxX60smvHgasZoBy11dX6YRjXJFovwWBoedhbQPOBzgFWBHGB+TVPWB9BxzR7TTxU8FQZAI2AyiNCMzFm8Img=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-wasm32-wasi": ["@tailwindcss/oxide-wasm32-wasi@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.3.3.tgz", { "dependencies": { "@emnapi/core": "^1.11.1", "@emnapi/runtime": "^1.11.1", "@emnapi/wasi-threads": "^1.2.2", "@napi-rs/wasm-runtime": "^1.1.4", "@tybys/wasm-util": "^0.10.2", "tslib": "^2.8.1" }, "cpu": "none" }, "sha512-jx1+rPhY/5Ympkktd656HBWEBLxP7dH06losBLjjf5vgCODXvi9KhtftWcMIwTFIDqBr7cRnQkdLnAG+IOlGvQ=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-win32-arm64-msvc": ["@tailwindcss/oxide-win32-arm64-msvc@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.3.3.tgz", { "os": "win32", "cpu": "arm64" }, "sha512-3rc292Ca2ceK6Ulcc/bAVnTs/3nDtoPhyEKlgPv+yQJQi/JS/AMJlqzxvlDacL1nekbrcf6bTqp/jV4qgnPxNQ=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-win32-x64-msvc": ["@tailwindcss/oxide-win32-x64-msvc@4.3.3", "https://registry.npmmirror.com/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.3.3.tgz", { "os": "win32", "cpu": "x64" }, "sha512-yJ0pwIVc/nYeGoV02WtsN8KYyLQv7kyI2wDnkezyJlGGjkd4QLwDGAwl47YpPJeuI0M0ObaXGSPjvWDPeTPggw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/vite": ["@tailwindcss/vite@4.3.3", "https://registry.npmmirror.com/@tailwindcss/vite/-/vite-4.3.3.tgz", { "dependencies": { "@tailwindcss/node": "4.3.3", "@tailwindcss/oxide": "4.3.3", "tailwindcss": "4.3.3" }, "peerDependencies": { "vite": "^5.2.0 || ^6 || ^7 || ^8" } }, "sha512-yYU8cogLeSh/ms2jh8Fj7jaba/EWa7Ja6GoUqYZaraEuCI5YS6ms6ObZgjjedm+jm6XZjdNRWBpPP6Z86oOxcw=="],
|
||||||
|
|
||||||
|
"@tauri-apps/api": ["@tauri-apps/api@2.11.1", "https://registry.npmmirror.com/@tauri-apps/api/-/api-2.11.1.tgz", {}, "sha512-M2FPuYND2m+wh5hfW9ZpSdxMPdEJovPBWwoHJmwUpysTYNHaOkVFN419m/K0LIgjb/7KU2vBgsUepJWugQCvAA=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli": ["@tauri-apps/cli@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli/-/cli-2.11.5.tgz", { "optionalDependencies": { "@tauri-apps/cli-darwin-arm64": "2.11.5", "@tauri-apps/cli-darwin-x64": "2.11.5", "@tauri-apps/cli-linux-arm-gnueabihf": "2.11.5", "@tauri-apps/cli-linux-arm64-gnu": "2.11.5", "@tauri-apps/cli-linux-arm64-musl": "2.11.5", "@tauri-apps/cli-linux-riscv64-gnu": "2.11.5", "@tauri-apps/cli-linux-x64-gnu": "2.11.5", "@tauri-apps/cli-linux-x64-musl": "2.11.5", "@tauri-apps/cli-win32-arm64-msvc": "2.11.5", "@tauri-apps/cli-win32-ia32-msvc": "2.11.5", "@tauri-apps/cli-win32-x64-msvc": "2.11.5" }, "bin": { "tauri": "tauri.js" } }, "sha512-YbeJ6tctNoo40purO4u3Eeo3RVqmsjJr0NoKQRu+4pvO4gMLzkjta7x0k96SxSLmx+rQ+8um1ThOlw+HLpgFug=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-darwin-arm64": ["@tauri-apps/cli-darwin-arm64@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.11.5.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-tggOiVOohjIHdiElbjeBfB41s6cmfsq+ZQ0PX0fEtCdsDdZ9cCi54e5gNK7tdPbR6JbdDe7RA4kbQdyyBUUk/Q=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-darwin-x64": ["@tauri-apps/cli-darwin-x64@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.11.5.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-SrO+KCbqvG1IvVPdlzQX4GEGZRQDISrmDY9bGcW68DLVFBCC06H+Loz6oyUZETUxsSMR6B4oDfvbQVgD4hxsqQ=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-linux-arm-gnueabihf": ["@tauri-apps/cli-linux-arm-gnueabihf@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.11.5.tgz", { "os": "linux", "cpu": "arm" }, "sha512-qLrOaCa8hLD5QVPQRjAgOXvhlTFKXmTliVF773GgvADYcWZSdmncnF5zBFAkdu1uQK8KfQbDlBUwqQYZqBfBRQ=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-linux-arm64-gnu": ["@tauri-apps/cli-linux-arm64-gnu@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.11.5.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-Tq32xpQjiQEdIrvwDq7lwHhXemn070CXWdbCvr9rdi9rsv9NFTbQ6izVSIfNE+59QaerxuwtUtZ5IxDNWaoYBw=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-linux-arm64-musl": ["@tauri-apps/cli-linux-arm64-musl@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.11.5.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-+OdWKj5Aq+C8HXypQ4t926V8cpVnc0ZcJIdhTXWjVAJHkaNuo8EuQR6KRZKHWIbJJgKdMPCDosvwzIFaBBqHKQ=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-linux-riscv64-gnu": ["@tauri-apps/cli-linux-riscv64-gnu@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-linux-riscv64-gnu/-/cli-linux-riscv64-gnu-2.11.5.tgz", { "os": "linux", "cpu": "none" }, "sha512-Q0V2hjpllyDW8dWQZSsITuQDfcY9BpBZuhXkMa2T5AFLZAn+FJPXQSyvnxWNVxRowdQ59Xn0QVtGm6HEHNUEvw=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-linux-x64-gnu": ["@tauri-apps/cli-linux-x64-gnu@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.11.5.tgz", { "os": "linux", "cpu": "x64" }, "sha512-Xz1s87gFjZJZMQKAhLa77YeiCJM6yVog3f9OxDgVd/KxDIoB1dA5V2xOnMM+SRkOGk9juwIBqesVAjV0kUB0DA=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-linux-x64-musl": ["@tauri-apps/cli-linux-x64-musl@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.11.5.tgz", { "os": "linux", "cpu": "x64" }, "sha512-6A88wqAZXZHgMaBrGiy/Bpa4GgUnftXM7uquKOeOXCuK78/XdBxEECicK/1oHgrT179XBFOaA6lQEHysjRmGig=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-win32-arm64-msvc": ["@tauri-apps/cli-win32-arm64-msvc@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-2.11.5.tgz", { "os": "win32", "cpu": "arm64" }, "sha512-sRGgF/ObRfLcS3PtUdyTbJtkGq3E+PNZTknvAURwMNUtHw9DU/BF6S5si43y9lS5yEO9bWJCA+GGYvnn6cphQw=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-win32-ia32-msvc": ["@tauri-apps/cli-win32-ia32-msvc@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.11.5.tgz", { "os": "win32", "cpu": "ia32" }, "sha512-bHOv/yxqfKpI7ioIFQi5wOfZ7jkbPzJD/UhXY52I/hrmE3qNh71cohIPyqZB5GQn3LZeJWdCUOqmIg/w6XX+Wg=="],
|
||||||
|
|
||||||
|
"@tauri-apps/cli-win32-x64-msvc": ["@tauri-apps/cli-win32-x64-msvc@2.11.5", "https://registry.npmmirror.com/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.11.5.tgz", { "os": "win32", "cpu": "x64" }, "sha512-vaaOmavqdCeS7oMib2banBZemgrC5v54tSkwoBV+bxrXQZhQZrOwE2EO2i4x+CHNtvQUM/6bSs3iymZMAsycWg=="],
|
||||||
|
|
||||||
|
"@tauri-apps/plugin-opener": ["@tauri-apps/plugin-opener@2.5.5", "https://registry.npmmirror.com/@tauri-apps/plugin-opener/-/plugin-opener-2.5.5.tgz", { "dependencies": { "@tauri-apps/api": "^2.11.0" } }, "sha512-xvzGai5aQds8j8R8RsUK/lW6pGG50YgOYIPLzvkqmkwAj7dfySOD7sGtejRzvVdMmv1EQfKVEFh1MvmDp8QR0g=="],
|
||||||
|
|
||||||
|
"@vitejs/plugin-vue": ["@vitejs/plugin-vue@6.0.9", "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-6.0.9.tgz", { "dependencies": { "@rolldown/pluginutils": "^1.0.1" }, "peerDependencies": { "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0", "vue": "^3.2.25" } }, "sha512-rD/MORlhaZMlXWW0rEn4FB4wMinWC0z/D7Ye160S5+Rs1mC8ZDAdcDp4SjKfUhG5t8q1ktcPVw4xuTkPRlzrSA=="],
|
||||||
|
|
||||||
|
"@volar/language-core": ["@volar/language-core@2.4.28", "https://registry.npmmirror.com/@volar/language-core/-/language-core-2.4.28.tgz", { "dependencies": { "@volar/source-map": "2.4.28" } }, "sha512-w4qhIJ8ZSitgLAkVay6AbcnC7gP3glYM3fYwKV3srj8m494E3xtrCv6E+bWviiK/8hs6e6t1ij1s2Endql7vzQ=="],
|
||||||
|
|
||||||
|
"@volar/source-map": ["@volar/source-map@2.4.28", "https://registry.npmmirror.com/@volar/source-map/-/source-map-2.4.28.tgz", {}, "sha512-yX2BDBqJkRXfKw8my8VarTyjv48QwxdJtvRgUpNE5erCsgEUdI2DsLbpa+rOQVAJYshY99szEcRDmyHbF10ggQ=="],
|
||||||
|
|
||||||
|
"@volar/typescript": ["@volar/typescript@2.4.28", "https://registry.npmmirror.com/@volar/typescript/-/typescript-2.4.28.tgz", { "dependencies": { "@volar/language-core": "2.4.28", "path-browserify": "^1.0.1", "vscode-uri": "^3.0.8" } }, "sha512-Ja6yvWrbis2QtN4ClAKreeUZPVYMARDYZl9LMEv1iQ1QdepB6wn0jTRxA9MftYmYa4DQ4k/DaSZpFPUfxl8giw=="],
|
||||||
|
|
||||||
|
"@vue/compiler-core": ["@vue/compiler-core@3.5.43", "https://registry.npmmirror.com/@vue/compiler-core/-/compiler-core-3.5.43.tgz", { "dependencies": { "@babel/parser": "^7.29.8", "@vue/shared": "3.5.43", "entities": "^7.0.1", "estree-walker": "^2.0.2", "source-map-js": "^1.2.1" } }, "sha512-zdiLhnbe1QQqgDT8xZMpNmyqZ3qlI+/Q/FHQco57Kwl/b05HhCzN6eVGN9QU9rbga4CrS0H5SYY8VGHZCt/1Hg=="],
|
||||||
|
|
||||||
|
"@vue/compiler-dom": ["@vue/compiler-dom@3.5.43", "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.5.43.tgz", { "dependencies": { "@vue/compiler-core": "3.5.43", "@vue/shared": "3.5.43" } }, "sha512-PEZoAk3NQmsn/ejMzSOCyTYqwGqczrWm70PuhBKjjv1+TCoQAaO/zOqNwjV+honlNstT5ILxtc+8r8UUfj+iEQ=="],
|
||||||
|
|
||||||
|
"@vue/compiler-sfc": ["@vue/compiler-sfc@3.5.43", "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.5.43.tgz", { "dependencies": { "@babel/parser": "^7.29.8", "@vue/compiler-core": "3.5.43", "@vue/compiler-dom": "3.5.43", "@vue/compiler-ssr": "3.5.43", "@vue/shared": "3.5.43", "estree-walker": "^2.0.2", "magic-string": "^0.30.21", "postcss": "^8.5.28", "source-map-js": "^1.2.1" } }, "sha512-FCbrG3XNCRl+js3huuKx4IVHBLTvMkJhVepjbxSPu1gn4yWLaYtGNQdjJGZaMytXB6qb76qQDDmDSLy/vkmleQ=="],
|
||||||
|
|
||||||
|
"@vue/compiler-ssr": ["@vue/compiler-ssr@3.5.43", "https://registry.npmmirror.com/@vue/compiler-ssr/-/compiler-ssr-3.5.43.tgz", { "dependencies": { "@vue/compiler-dom": "3.5.43", "@vue/shared": "3.5.43" } }, "sha512-GF62orf7KiJX9RqrHNGrYBudsQGD0OhJ5nDs90O8UiDuS40+YMYomiXu6w6EuvtXuRDc3MSNis3EaaSKAVSWpg=="],
|
||||||
|
|
||||||
|
"@vue/devtools-api": ["@vue/devtools-api@8.2.1", "https://registry.npmmirror.com/@vue/devtools-api/-/devtools-api-8.2.1.tgz", { "dependencies": { "@vue/devtools-kit": "^8.2.1" } }, "sha512-6u4vXBlIBAC1wMplIZgpyPn7uh/s4Bf6F5bMzvLv+EdJ0aHs/+4B7Ygv864EStQSjRbsRzTko/kUG1A1IejQ3A=="],
|
||||||
|
|
||||||
|
"@vue/devtools-kit": ["@vue/devtools-kit@8.2.1", "https://registry.npmmirror.com/@vue/devtools-kit/-/devtools-kit-8.2.1.tgz", { "dependencies": { "@vue/devtools-shared": "^8.2.1", "birpc": "^2.6.1", "hookable": "^5.5.3", "perfect-debounce": "^2.0.0" } }, "sha512-FIGIuq3AWReEpbAHY/cRGeHDfI0qOb8OCQ3YjbEAX04uaxIDbGc9rhkbVcG7rnfHPXE3RsU5KrWOu9V/okd8AQ=="],
|
||||||
|
|
||||||
|
"@vue/devtools-shared": ["@vue/devtools-shared@8.2.1", "https://registry.npmmirror.com/@vue/devtools-shared/-/devtools-shared-8.2.1.tgz", {}, "sha512-Fkac7lUdGReh6pVOi3AYPRGe82LQqRmAfThW7RRligOAP0ZA/Z1z9XLHDM9dv34pV2HRc79DK8uKPeG2fLnA/g=="],
|
||||||
|
|
||||||
|
"@vue/language-core": ["@vue/language-core@3.3.11", "https://registry.npmmirror.com/@vue/language-core/-/language-core-3.3.11.tgz", { "dependencies": { "@volar/language-core": "2.4.28", "@vue/compiler-dom": "^3.5.0", "@vue/shared": "^3.5.0", "alien-signals": "^3.2.1", "muggle-string": "^0.4.1", "path-browserify": "^1.0.1", "picomatch": "^4.0.4" } }, "sha512-QJmpliwAVpC/OxubIByPAhNzsQPRc8/gxlN2qnVzVfIMjMDz/9RnXRFoetjz5yEgXVXyp4LqhXq3V53PjmNzFw=="],
|
||||||
|
|
||||||
|
"@vue/reactivity": ["@vue/reactivity@3.5.43", "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.5.43.tgz", { "dependencies": { "@vue/shared": "3.5.43" } }, "sha512-G/c9GyOZNI2jVaaS6OX1EF1SSFSv7H0ERqNTl4+DTFMlZmB5eVAB53aLQNam/7NL2NPtaDD7RdVrzf8uJzMuOA=="],
|
||||||
|
|
||||||
|
"@vue/runtime-core": ["@vue/runtime-core@3.5.43", "https://registry.npmmirror.com/@vue/runtime-core/-/runtime-core-3.5.43.tgz", { "dependencies": { "@vue/reactivity": "3.5.43", "@vue/shared": "3.5.43" } }, "sha512-hU6U6VnVhBGQDpvlnnDlIB8ZGJBiOcgk2lh/0InltHiz3D8oSkluvuvY+do1G2H3+udeKFsmaBlgVYP7gXQzEw=="],
|
||||||
|
|
||||||
|
"@vue/runtime-dom": ["@vue/runtime-dom@3.5.43", "https://registry.npmmirror.com/@vue/runtime-dom/-/runtime-dom-3.5.43.tgz", { "dependencies": { "@vue/reactivity": "3.5.43", "@vue/runtime-core": "3.5.43", "@vue/shared": "3.5.43", "csstype": "^3.2.3" } }, "sha512-Bb2Jc0YjjJdMt1SJmb9b2L/IWd3I8lIT9x9eS/xvvP9CiVgna0ffua74xKRmt4/uSJ+0r4iN8ex1jrqkhQGWQw=="],
|
||||||
|
|
||||||
|
"@vue/server-renderer": ["@vue/server-renderer@3.5.43", "https://registry.npmmirror.com/@vue/server-renderer/-/server-renderer-3.5.43.tgz", { "dependencies": { "@vue/compiler-ssr": "3.5.43", "@vue/runtime-dom": "3.5.43", "@vue/shared": "3.5.43" } }, "sha512-l2Ygjv9NehV94PSBxNWsAHC0j/eIIKbn92mBuWXAPGLnn6HfJ6MH5ubsd+Nk0YoZ5FRuxWI1P2VSoh+dbPQhCQ=="],
|
||||||
|
|
||||||
|
"@vue/shared": ["@vue/shared@3.5.43", "https://registry.npmmirror.com/@vue/shared/-/shared-3.5.43.tgz", {}, "sha512-uksS7YGMR5NZyr4JNq0Rp+QyLns0ueaz20KwzIPW9R0LH1Vnt4E+XUM29PNseEbf1www2gOuhuDi5AKOIXag9Q=="],
|
||||||
|
|
||||||
|
"alien-signals": ["alien-signals@3.2.1", "https://registry.npmmirror.com/alien-signals/-/alien-signals-3.2.1.tgz", {}, "sha512-I8FjmltrfnDFoZedi5CG8DghVYNhzb/Ijluz7tCSJH0xpd0484Kowhbb1XDYOxfJpU1p5wnM2X54dA+IfGyD1g=="],
|
||||||
|
|
||||||
|
"birpc": ["birpc@2.9.0", "https://registry.npmmirror.com/birpc/-/birpc-2.9.0.tgz", {}, "sha512-KrayHS5pBi69Xi9JmvoqrIgYGDkD6mcSe/i6YKi3w5kekCLzrX4+nawcXqrj2tIp50Kw/mT/s3p+GVK0A0sKxw=="],
|
||||||
|
|
||||||
|
"csstype": ["csstype@3.2.3", "https://registry.npmmirror.com/csstype/-/csstype-3.2.3.tgz", {}, "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ=="],
|
||||||
|
|
||||||
|
"detect-libc": ["detect-libc@2.1.2", "https://registry.npmmirror.com/detect-libc/-/detect-libc-2.1.2.tgz", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
|
||||||
|
|
||||||
|
"enhanced-resolve": ["enhanced-resolve@5.25.1", "https://registry.npmmirror.com/enhanced-resolve/-/enhanced-resolve-5.25.1.tgz", { "dependencies": { "graceful-fs": "^4.2.4", "tapable": "^2.3.3" } }, "sha512-nGXts5znJzmWPu+mIE9izCOzdg63oJca2mDzGWWTth7sr4aCToKcoyFVBQwN75Ij5Pf6p510EwkTqViTRzDV+w=="],
|
||||||
|
|
||||||
|
"entities": ["entities@7.0.1", "https://registry.npmmirror.com/entities/-/entities-7.0.1.tgz", {}, "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA=="],
|
||||||
|
|
||||||
|
"estree-walker": ["estree-walker@2.0.2", "https://registry.npmmirror.com/estree-walker/-/estree-walker-2.0.2.tgz", {}, "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="],
|
||||||
|
|
||||||
|
"fdir": ["fdir@6.5.0", "https://registry.npmmirror.com/fdir/-/fdir-6.5.0.tgz", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="],
|
||||||
|
|
||||||
|
"fsevents": ["fsevents@2.3.3", "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="],
|
||||||
|
|
||||||
|
"graceful-fs": ["graceful-fs@4.2.11", "https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.11.tgz", {}, "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="],
|
||||||
|
|
||||||
|
"hookable": ["hookable@5.5.3", "https://registry.npmmirror.com/hookable/-/hookable-5.5.3.tgz", {}, "sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ=="],
|
||||||
|
|
||||||
|
"jiti": ["jiti@2.7.0", "https://registry.npmmirror.com/jiti/-/jiti-2.7.0.tgz", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="],
|
||||||
|
|
||||||
|
"lightningcss": ["lightningcss@1.33.0", "https://registry.npmmirror.com/lightningcss/-/lightningcss-1.33.0.tgz", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.33.0", "lightningcss-darwin-arm64": "1.33.0", "lightningcss-darwin-x64": "1.33.0", "lightningcss-freebsd-x64": "1.33.0", "lightningcss-linux-arm-gnueabihf": "1.33.0", "lightningcss-linux-arm64-gnu": "1.33.0", "lightningcss-linux-arm64-musl": "1.33.0", "lightningcss-linux-x64-gnu": "1.33.0", "lightningcss-linux-x64-musl": "1.33.0", "lightningcss-win32-arm64-msvc": "1.33.0", "lightningcss-win32-x64-msvc": "1.33.0" } }, "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA=="],
|
||||||
|
|
||||||
|
"lightningcss-android-arm64": ["lightningcss-android-arm64@1.33.0", "https://registry.npmmirror.com/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", { "os": "android", "cpu": "arm64" }, "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg=="],
|
||||||
|
|
||||||
|
"lightningcss-darwin-arm64": ["lightningcss-darwin-arm64@1.33.0", "https://registry.npmmirror.com/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg=="],
|
||||||
|
|
||||||
|
"lightningcss-darwin-x64": ["lightningcss-darwin-x64@1.33.0", "https://registry.npmmirror.com/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ=="],
|
||||||
|
|
||||||
|
"lightningcss-freebsd-x64": ["lightningcss-freebsd-x64@1.33.0", "https://registry.npmmirror.com/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", { "os": "freebsd", "cpu": "x64" }, "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg=="],
|
||||||
|
|
||||||
|
"lightningcss-linux-arm-gnueabihf": ["lightningcss-linux-arm-gnueabihf@1.33.0", "https://registry.npmmirror.com/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", { "os": "linux", "cpu": "arm" }, "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ=="],
|
||||||
|
|
||||||
|
"lightningcss-linux-arm64-gnu": ["lightningcss-linux-arm64-gnu@1.33.0", "https://registry.npmmirror.com/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg=="],
|
||||||
|
|
||||||
|
"lightningcss-linux-arm64-musl": ["lightningcss-linux-arm64-musl@1.33.0", "https://registry.npmmirror.com/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ=="],
|
||||||
|
|
||||||
|
"lightningcss-linux-x64-gnu": ["lightningcss-linux-x64-gnu@1.33.0", "https://registry.npmmirror.com/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", { "os": "linux", "cpu": "x64" }, "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg=="],
|
||||||
|
|
||||||
|
"lightningcss-linux-x64-musl": ["lightningcss-linux-x64-musl@1.33.0", "https://registry.npmmirror.com/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", { "os": "linux", "cpu": "x64" }, "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw=="],
|
||||||
|
|
||||||
|
"lightningcss-win32-arm64-msvc": ["lightningcss-win32-arm64-msvc@1.33.0", "https://registry.npmmirror.com/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", { "os": "win32", "cpu": "arm64" }, "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA=="],
|
||||||
|
|
||||||
|
"lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.33.0", "https://registry.npmmirror.com/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", { "os": "win32", "cpu": "x64" }, "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA=="],
|
||||||
|
|
||||||
|
"lucide-vue-next": ["lucide-vue-next@1.0.0", "https://registry.npmmirror.com/lucide-vue-next/-/lucide-vue-next-1.0.0.tgz", { "peerDependencies": { "vue": ">=3.0.1" } }, "sha512-V6SPvx1IHTj/UY+FrIYWV5faISsPSb8BnWSFDxAtezWKvWc9ZZ40PDrdu1/Qb5vg4lHWr1hs1BAMGVGm6V1Xdg=="],
|
||||||
|
|
||||||
|
"magic-string": ["magic-string@0.30.21", "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.21.tgz", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],
|
||||||
|
|
||||||
|
"muggle-string": ["muggle-string@0.4.1", "https://registry.npmmirror.com/muggle-string/-/muggle-string-0.4.1.tgz", {}, "sha512-VNTrAak/KhO2i8dqqnqnAHOa3cYBwXEZe9h+D5h/1ZqFSTEFHdM65lR7RoIqq3tBBYavsOXV84NoHXZ0AkPyqQ=="],
|
||||||
|
|
||||||
|
"nanoid": ["nanoid@3.3.19", "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.19.tgz", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-Y2tUNy4ouw6tq5oDSKeQYGOyhkUBhNOcGV/02KC+6kd9eDGqdZd++mjMiIDilrBYvjEnCYvVtsuHCuP+okSfug=="],
|
||||||
|
|
||||||
|
"nostics": ["nostics@1.3.0", "https://registry.npmmirror.com/nostics/-/nostics-1.3.0.tgz", {}, "sha512-wzRsrJwNlFbqIRQt8aCeL2WE8USip/uuvGSOZV1D02CxX8ABTMbw8IywKjH7yWHETMXbWJI4OBpihg9rmz2Vyg=="],
|
||||||
|
|
||||||
|
"path-browserify": ["path-browserify@1.0.1", "https://registry.npmmirror.com/path-browserify/-/path-browserify-1.0.1.tgz", {}, "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g=="],
|
||||||
|
|
||||||
|
"perfect-debounce": ["perfect-debounce@2.1.0", "https://registry.npmmirror.com/perfect-debounce/-/perfect-debounce-2.1.0.tgz", {}, "sha512-LjgdTytVFXeUgtHZr9WYViYSM/g8MkcTPYDlPa3cDqMirHjKiSZPYd6DoL7pK8AJQr+uWkQvCjHNdiMqsrJs+g=="],
|
||||||
|
|
||||||
|
"picocolors": ["picocolors@1.1.1", "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="],
|
||||||
|
|
||||||
|
"picomatch": ["picomatch@4.0.7", "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.7.tgz", {}, "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA=="],
|
||||||
|
|
||||||
|
"pinia": ["pinia@4.0.3", "https://registry.npmmirror.com/pinia/-/pinia-4.0.3.tgz", { "dependencies": { "nostics": "^1.1.4" }, "peerDependencies": { "@vue/devtools-api": "^8.1.5", "typescript": ">=5.6.0", "vue": "^3.5.11" }, "optionalPeers": ["typescript"] }, "sha512-XMQqpvjgG7LMqVhhFUzKLT4KEbsYbfZZ0CZU9PgdFm1O2VKBmIkykL8+SfNhOaT7sR0wT6BEgKT0YNDYWgmVRA=="],
|
||||||
|
|
||||||
|
"postcss": ["postcss@8.5.28", "https://registry.npmmirror.com/postcss/-/postcss-8.5.28.tgz", { "dependencies": { "nanoid": "^3.3.18", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A=="],
|
||||||
|
|
||||||
|
"rolldown": ["rolldown@1.2.11", "https://registry.npmmirror.com/rolldown/-/rolldown-1.2.11.tgz", { "dependencies": { "@oxc-project/types": "=0.151.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm-eabi": "1.2.11", "@rolldown/binding-android-arm64": "1.2.11", "@rolldown/binding-darwin-arm64": "1.2.11", "@rolldown/binding-darwin-x64": "1.2.11", "@rolldown/binding-freebsd-x64": "1.2.11", "@rolldown/binding-linux-arm-gnueabihf": "1.2.11", "@rolldown/binding-linux-arm64-gnu": "1.2.11", "@rolldown/binding-linux-arm64-musl": "1.2.11", "@rolldown/binding-linux-ppc64-gnu": "1.2.11", "@rolldown/binding-linux-s390x-gnu": "1.2.11", "@rolldown/binding-linux-x64-gnu": "1.2.11", "@rolldown/binding-linux-x64-musl": "1.2.11", "@rolldown/binding-openharmony-arm64": "1.2.11", "@rolldown/binding-win32-arm64-msvc": "1.2.11", "@rolldown/binding-win32-x64-msvc": "1.2.11" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-qpSwIyz0jHQq5qXBTNxFmE6664rJ7O+4TvPFOiOaBSrz8IOHc1koKKSqTM2H6u1UG1+TveuC6vaDHKXFOvb1Kw=="],
|
||||||
|
|
||||||
|
"source-map-js": ["source-map-js@1.2.1", "https://registry.npmmirror.com/source-map-js/-/source-map-js-1.2.1.tgz", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="],
|
||||||
|
|
||||||
|
"tailwindcss": ["tailwindcss@4.3.3", "https://registry.npmmirror.com/tailwindcss/-/tailwindcss-4.3.3.tgz", {}, "sha512-gOhV3P7ufE62QDGg1zVaTgCR+EtPv92k2nIhVcVKcLmxT1sUBsQGhnZj175j+MqRt4zLF7ic+sCYjfhxMxj7YQ=="],
|
||||||
|
|
||||||
|
"tapable": ["tapable@2.3.3", "https://registry.npmmirror.com/tapable/-/tapable-2.3.3.tgz", {}, "sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A=="],
|
||||||
|
|
||||||
|
"tauri-plugin-native-audio-api": ["tauri-plugin-native-audio-api@1.0.5", "https://registry.npmmirror.com/tauri-plugin-native-audio-api/-/tauri-plugin-native-audio-api-1.0.5.tgz", { "peerDependencies": { "@tauri-apps/api": ">=2.10.0" } }, "sha512-G1v9xEhdN0mLbVAIXflhCzqxiqB9gy9Gs1dV/lc2mlZTO0J11PVOhaxPLZgOSvIvXrq0iLT7cvP53dgG6mBGoQ=="],
|
||||||
|
|
||||||
|
"tinyglobby": ["tinyglobby@0.2.17", "https://registry.npmmirror.com/tinyglobby/-/tinyglobby-0.2.17.tgz", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="],
|
||||||
|
|
||||||
|
"typescript": ["typescript@6.0.3", "https://registry.npmmirror.com/typescript/-/typescript-6.0.3.tgz", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw=="],
|
||||||
|
|
||||||
|
"vite": ["vite@8.3.1", "https://registry.npmmirror.com/vite/-/vite-8.3.1.tgz", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", "postcss": "^8.5.28", "rolldown": "~1.2.9", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.7.1", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-/bvH9E9tmCXRGp2uXY3WbOldqpTwFkbha/8ANaEQ6VkxhH60KyqLwgZq6lG2y+4uT55x9+9eUHMpQ7uGnOCKjA=="],
|
||||||
|
|
||||||
|
"vscode-uri": ["vscode-uri@3.2.0", "https://registry.npmmirror.com/vscode-uri/-/vscode-uri-3.2.0.tgz", {}, "sha512-m2gXo3bn0G1kT9InzMf07fTbqMbGtyckj3bH5ktLO+1Ssv+yiATZ4dhwaQv9UZWxJh6E9IFGnQyjgWVDWVBDrg=="],
|
||||||
|
|
||||||
|
"vue": ["vue@3.5.43", "https://registry.npmmirror.com/vue/-/vue-3.5.43.tgz", { "dependencies": { "@vue/compiler-dom": "3.5.43", "@vue/compiler-sfc": "3.5.43", "@vue/runtime-dom": "3.5.43", "@vue/server-renderer": "3.5.43", "@vue/shared": "3.5.43" }, "peerDependencies": { "typescript": "*" }, "optionalPeers": ["typescript"] }, "sha512-o5qZoksdnjIKvW1srZ3ab7pcDNYAerBjRe54D0LBLfRdCYFrSgBHVXokMas35czQc0//lmx4/tuY4ZNQ+Rf2Ng=="],
|
||||||
|
|
||||||
|
"vue-sonner": ["vue-sonner@2.0.9", "https://registry.npmmirror.com/vue-sonner/-/vue-sonner-2.0.9.tgz", { "peerDependencies": { "@nuxt/kit": "^4.0.3", "@nuxt/schema": "^4.0.3", "nuxt": "^4.0.3" }, "optionalPeers": ["@nuxt/kit", "@nuxt/schema", "nuxt"] }, "sha512-i6BokNlNDL93fpzNxN/LZSn6D6MzlO+i3qXt6iVZne3x1k7R46d5HlFB4P8tYydhgqOrRbIZEsnRd3kG7qGXyw=="],
|
||||||
|
|
||||||
|
"vue-tsc": ["vue-tsc@3.3.11", "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-3.3.11.tgz", { "dependencies": { "@volar/typescript": "2.4.28", "@vue/language-core": "3.3.11" }, "peerDependencies": { "typescript": ">=5.0.0" }, "bin": { "vue-tsc": "bin/vue-tsc.js" } }, "sha512-gOb0B9rtU2+f1dszwPqSH5kAieIF9ReeLhD3kSRNHv5WZZUQz/JdVXW0RTdqhNTMlQkqKzrTTviqKr/4FYZraQ=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss": ["lightningcss@1.32.0", "https://registry.npmmirror.com/lightningcss/-/lightningcss-1.32.0.tgz", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.32.0", "lightningcss-darwin-arm64": "1.32.0", "lightningcss-darwin-x64": "1.32.0", "lightningcss-freebsd-x64": "1.32.0", "lightningcss-linux-arm-gnueabihf": "1.32.0", "lightningcss-linux-arm64-gnu": "1.32.0", "lightningcss-linux-arm64-musl": "1.32.0", "lightningcss-linux-x64-gnu": "1.32.0", "lightningcss-linux-x64-musl": "1.32.0", "lightningcss-win32-arm64-msvc": "1.32.0", "lightningcss-win32-x64-msvc": "1.32.0" } }, "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.11.3", "https://registry.npmmirror.com/@emnapi/core/-/core-1.11.3.tgz", { "dependencies": { "@emnapi/wasi-threads": "1.2.3", "tslib": "^2.4.0" }, "bundled": true }, "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/runtime@1.11.3", "https://registry.npmmirror.com/@emnapi/runtime/-/runtime-1.11.3.tgz", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-wasm32-wasi/@emnapi/wasi-threads": ["@emnapi/wasi-threads@1.2.3", "https://registry.npmmirror.com/@emnapi/wasi-threads/-/wasi-threads-1.2.3.tgz", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-wasm32-wasi/@napi-rs/wasm-runtime": ["@napi-rs/wasm-runtime@1.2.4", "https://registry.npmmirror.com/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.4.tgz", { "dependencies": { "@tybys/wasm-util": "^0.10.3" }, "peerDependencies": { "@emnapi/core": "^1.7.1 || ^2.0.0-alpha.4", "@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.4" }, "bundled": true }, "sha512-AJxoUD2/15ESHbvpcyjU274nsAPLuOtPHCk0vKJM5pj//Fg/B1FXNWjPnXTT9PymCYYiHo4zPj0ZomXBKhoy7g=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-wasm32-wasi/@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "https://registry.npmmirror.com/@tybys/wasm-util/-/wasm-util-0.10.4.tgz", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="],
|
||||||
|
|
||||||
|
"@tailwindcss/oxide-wasm32-wasi/tslib": ["tslib@2.8.1", "https://registry.npmmirror.com/tslib/-/tslib-2.8.1.tgz", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-android-arm64": ["lightningcss-android-arm64@1.32.0", "https://registry.npmmirror.com/lightningcss-android-arm64/-/lightningcss-android-arm64-1.32.0.tgz", { "os": "android", "cpu": "arm64" }, "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-darwin-arm64": ["lightningcss-darwin-arm64@1.32.0", "https://registry.npmmirror.com/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.32.0.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-darwin-x64": ["lightningcss-darwin-x64@1.32.0", "https://registry.npmmirror.com/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.32.0.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-freebsd-x64": ["lightningcss-freebsd-x64@1.32.0", "https://registry.npmmirror.com/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.32.0.tgz", { "os": "freebsd", "cpu": "x64" }, "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-linux-arm-gnueabihf": ["lightningcss-linux-arm-gnueabihf@1.32.0", "https://registry.npmmirror.com/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.32.0.tgz", { "os": "linux", "cpu": "arm" }, "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-linux-arm64-gnu": ["lightningcss-linux-arm64-gnu@1.32.0", "https://registry.npmmirror.com/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-linux-arm64-musl": ["lightningcss-linux-arm64-musl@1.32.0", "https://registry.npmmirror.com/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.32.0.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-linux-x64-gnu": ["lightningcss-linux-x64-gnu@1.32.0", "https://registry.npmmirror.com/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz", { "os": "linux", "cpu": "x64" }, "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-linux-x64-musl": ["lightningcss-linux-x64-musl@1.32.0", "https://registry.npmmirror.com/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.32.0.tgz", { "os": "linux", "cpu": "x64" }, "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-win32-arm64-msvc": ["lightningcss-win32-arm64-msvc@1.32.0", "https://registry.npmmirror.com/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz", { "os": "win32", "cpu": "arm64" }, "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw=="],
|
||||||
|
|
||||||
|
"@tailwindcss/node/lightningcss/lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.32.0", "https://registry.npmmirror.com/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz", { "os": "win32", "cpu": "x64" }, "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q=="],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,14 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Tauri + Vue + Typescript App</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "lfmusic",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vue-tsc --noEmit && vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"tauri": "tauri"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^2",
|
||||||
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
|
"lucide-vue-next": "^1.0.0",
|
||||||
|
"pinia": "^4.0.3",
|
||||||
|
"tauri-plugin-native-audio-api": "^1.0.5",
|
||||||
|
"vue": "^3.5.13",
|
||||||
|
"vue-sonner": "^2.0.9"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/vite": "^4.3.3",
|
||||||
|
"@tauri-apps/cli": "^2",
|
||||||
|
"@vitejs/plugin-vue": "^6.0.7",
|
||||||
|
"tailwindcss": "^4.3.3",
|
||||||
|
"typescript": "~6.0.3",
|
||||||
|
"vite": "^8.0.16",
|
||||||
|
"vue-tsc": "^3.3.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
|
||||||
|
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,7 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
|
||||||
|
# Generated by Tauri
|
||||||
|
# will have schema files for capabilities auto-completion
|
||||||
|
/gen/schemas
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
[package]
|
||||||
|
name = "lfmusic"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "A Tauri App"
|
||||||
|
authors = ["you"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
# The `_lib` suffix may seem redundant but it is necessary
|
||||||
|
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||||
|
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||||
|
name = "lfmusic_lib"
|
||||||
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-build = { version = "2", features = [] }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# protocol-asset:assetProtocol(封面走 convertFileSrc,需按 scope 放行本地文件)
|
||||||
|
tauri = { version = "2", features = ["protocol-asset"] }
|
||||||
|
tauri-plugin-opener = "2"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
# M2 手机遥控(M3):/pair 走 Rust 侧 POST,绕开 WebView 的 CORS;
|
||||||
|
# stream=曲库流式转发(proxy bytes_stream);rustls-tls=danger_accept_invalid_certs
|
||||||
|
#(自签名 https NAS)与 Android 可移植 TLS
|
||||||
|
reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "rustls-tls", "blocking"] }
|
||||||
|
# M1 普通播放:移动端原生播放引擎(Media3 ExoPlayer / AVPlayer,PLAN §0 判断 1)
|
||||||
|
# 能力边界见 PLAN M1 清单(无 stop/队列,编排在 src-tauri/src/player)
|
||||||
|
tauri-plugin-native-audio = "1"
|
||||||
|
# M1 曲库:元数据/封面提取 + SQLite 索引 + 目录遍历(与 Thing 同款栈,PLAN §3.3)
|
||||||
|
lofty = "0.22"
|
||||||
|
walkdir = "2"
|
||||||
|
rusqlite = { version = "0.32", features = ["bundled"] }
|
||||||
|
# M1 播放模式:随机播放
|
||||||
|
rand = "0.8"
|
||||||
|
# M1-a:媒体权限插件的 ACL 清单载体(包名即插件名 media;见 media-plugin/)
|
||||||
|
media = { path = "./media-plugin" }
|
||||||
|
# M2 飞牛曲库:本机流代理(axum,移植 Thing feiniu/proxy.rs 的 Range 透传)
|
||||||
|
axum = "0.7"
|
||||||
|
tokio = { version = "1", features = ["rt-multi-thread", "net", "time", "sync", "macros"] }
|
||||||
|
# M2 登录签名(与 Thing feiniu/conn.rs 字段级一致)+ 访问安全码
|
||||||
|
sha2 = "0.10"
|
||||||
|
base64 = "0.22"
|
||||||
|
# M4 UAC:USB DAC bit-perfect(rusb/libusb;Android 上 Kotlin fd 经
|
||||||
|
# open_device_with_fd(wrap_sys_device) 桥接,Flick 同款;vendored=源码编译,
|
||||||
|
# 桌面免 pkg-config/vcpkg,Android 免预编译库)
|
||||||
|
rusb = { version = "0.9", features = ["vendored"] }
|
||||||
|
# M4 UAC:「usb」插件 ACL 清单载体(Kotlin UsbPlugin 桥,见 usb-plugin/)
|
||||||
|
usb = { path = "./usb-plugin" }
|
||||||
|
# M4 UAC 解码(PCM 直喂 DAC;默认 features 覆盖 flac/mp3/aac/ogg/wav/pcm)
|
||||||
|
symphonia = "0.5"
|
||||||
|
# M4 UAC:原生 libusb iso transfer(libusb_fill_iso_transfer 等,rusb 未封装)
|
||||||
|
libusb1-sys = "0.7"
|
||||||
|
|
||||||
|
|
||||||
|
# Read the optimization guideline for more details: https://tauri.app/concept/size/#cargo-configuration
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
lto = true
|
||||||
|
opt-level = 3
|
||||||
|
panic = "abort"
|
||||||
|
strip = true
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
tauri_build::build()
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"$schema": "../gen/schemas/desktop-schema.json",
|
||||||
|
"identifier": "default",
|
||||||
|
"description": "Capability for the main window",
|
||||||
|
"windows": ["main"],
|
||||||
|
"permissions": [
|
||||||
|
"core:default",
|
||||||
|
"opener:default",
|
||||||
|
"native-audio:default",
|
||||||
|
"media:default",
|
||||||
|
"usb:default"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# 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
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
*.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
|
||||||
|
*.keystore
|
||||||
|
*.jks
|
||||||
|
|
||||||
|
/.tauri
|
||||||
|
/tauri.settings.gradle
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/src/main/**/generated
|
||||||
|
/src/main/jniLibs/**/*.so
|
||||||
|
/src/main/assets/tauri.conf.json
|
||||||
|
/tauri.build.gradle.kts
|
||||||
|
/proguard-tauri.pro
|
||||||
|
/tauri.properties
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
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) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 签名信息放在 app/keystore.properties(已被 .gitignore 忽略),缺失时 release 仍输出未签名 APK
|
||||||
|
val signingProperties = Properties().apply {
|
||||||
|
val propFile = file("keystore.properties")
|
||||||
|
if (propFile.exists()) {
|
||||||
|
propFile.inputStream().use { load(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk = 36
|
||||||
|
namespace = "music.lfeng.me"
|
||||||
|
defaultConfig {
|
||||||
|
manifestPlaceholders["usesCleartextTraffic"] = "false"
|
||||||
|
applicationId = "music.lfeng.me"
|
||||||
|
// tauri-plugin-native-audio 要求 API 26+(Android 8.0,插件 README / manifest 声明)
|
||||||
|
minSdk = 26
|
||||||
|
targetSdk = 36
|
||||||
|
versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt()
|
||||||
|
versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0")
|
||||||
|
}
|
||||||
|
signingConfigs {
|
||||||
|
if (signingProperties.containsKey("key.storeFile")) {
|
||||||
|
create("release") {
|
||||||
|
storeFile = file(signingProperties.getProperty("key.storeFile"))
|
||||||
|
storePassword = signingProperties.getProperty("key.storePassword")
|
||||||
|
keyAlias = signingProperties.getProperty("key.alias")
|
||||||
|
keyPassword = signingProperties.getProperty("key.storePassword")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
signingConfig = signingConfigs.findByName("release")
|
||||||
|
?: signingConfigs.getByName("debug")
|
||||||
|
proguardFiles(
|
||||||
|
*fileTree(".") { include("**/*.pro") }
|
||||||
|
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
|
||||||
|
.toList().toTypedArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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")
|
||||||
|
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")
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# 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
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<!-- 存储选型 spike / M1 曲库扫描(PLAN.md §2 权限清单)
|
||||||
|
注意:READ_EXTERNAL_STORAGE **不能**加 maxSdkVersion=32——requestPermissions
|
||||||
|
要求所请求的权限已在清单声明,缺声明会让整批申请静默失败(M1-a 真机踩点);
|
||||||
|
API 33+ 上该旧权限由系统自动拒绝,不影响 READ_MEDIA_AUDIO 授予。 -->
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
|
<!-- M4 UAC:前台服务保活(锁屏/后台继续 iso 传输)+ wake lock 防 CPU 休眠断流 -->
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
|
||||||
|
<!-- AndroidTV support -->
|
||||||
|
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||||
|
|
||||||
|
<!-- M4 UAC:USB Host(外接 DAC bit-perfect,PLAN §3.4)。
|
||||||
|
USB 设备访问权限不走 manifest 危险权限,由 UsbManager.requestPermission 系统弹窗授予。 -->
|
||||||
|
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:theme="@style/Theme.lfmusic"
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
|
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>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<!-- M4 UAC 播放保活前台服务 -->
|
||||||
|
<service
|
||||||
|
android:name=".UacPlaybackService"
|
||||||
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="mediaPlayback" />
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package music.lfeng.me
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.webkit.JavascriptInterface
|
||||||
|
import android.webkit.WebView
|
||||||
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
|
||||||
|
class MainActivity : TauriActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
enableEdgeToEdge()
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** JS 桥:主界面按系统返回时最小化到桌面(音乐继续播),而非退出应用 */
|
||||||
|
override fun onWebViewCreate(webView: WebView) {
|
||||||
|
super.onWebViewCreate(webView)
|
||||||
|
webView.addJavascriptInterface(object {
|
||||||
|
@JavascriptInterface
|
||||||
|
fun minimize() {
|
||||||
|
runOnUiThread { moveTaskToBack(true) }
|
||||||
|
}
|
||||||
|
}, "LFAndroid")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package music.lfeng.me
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.app.Activity
|
||||||
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
|
import app.tauri.PermissionState
|
||||||
|
import app.tauri.annotation.Command
|
||||||
|
import app.tauri.annotation.Permission
|
||||||
|
import app.tauri.annotation.PermissionCallback
|
||||||
|
import app.tauri.annotation.TauriPlugin
|
||||||
|
import app.tauri.plugin.Invoke
|
||||||
|
import app.tauri.plugin.JSObject
|
||||||
|
import app.tauri.plugin.Plugin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 曲库媒体权限桥(LFMusic PLAN M1-a:应用内运行时申请)。
|
||||||
|
*
|
||||||
|
* 注册链:lib.rs::media_plugin → register_android_plugin("music.lfeng.me", "MediaPlugin")
|
||||||
|
* JS:checkPermissions('media') / requestPermissions('media') → { audio: "GRANTED"|... }
|
||||||
|
*
|
||||||
|
* **双别名按 API 分流(M1-a 真机踩点)**:
|
||||||
|
* - API 33+:只用 `audio`(READ_MEDIA_AUDIO)。READ_EXTERNAL_STORAGE 对 targetSdk33+
|
||||||
|
* 应用是"声明即永久拒绝、连弹窗都不出"的废弃权限——**绝不能与现代权限捆在同一
|
||||||
|
* 别名**,否则组合状态永远 denied、request 秒回拒绝(35ms 无弹窗死循环)。
|
||||||
|
* - API ≤32:用 `legacyStorage`(READ_EXTERNAL_STORAGE),旧系统唯一有效路径。
|
||||||
|
*/
|
||||||
|
const val AUDIO_MODERN = "audio"
|
||||||
|
const val AUDIO_LEGACY = "legacyStorage"
|
||||||
|
|
||||||
|
@TauriPlugin(
|
||||||
|
permissions = [
|
||||||
|
Permission(strings = [Manifest.permission.READ_MEDIA_AUDIO], alias = AUDIO_MODERN),
|
||||||
|
Permission(strings = [Manifest.permission.READ_EXTERNAL_STORAGE], alias = AUDIO_LEGACY)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
class MediaPlugin(private val activity: Activity) : Plugin(activity) {
|
||||||
|
|
||||||
|
private fun activeAlias(): String =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) AUDIO_MODERN else AUDIO_LEGACY
|
||||||
|
|
||||||
|
@Command
|
||||||
|
override fun checkPermissions(invoke: Invoke) {
|
||||||
|
Log.d(TAG, "checkPermissions called alias=${activeAlias()}")
|
||||||
|
try {
|
||||||
|
resolveState(invoke)
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Log.e(TAG, "checkPermissions failed", ex)
|
||||||
|
invoke.reject("checkPermissions: ${ex.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
override fun requestPermissions(invoke: Invoke) {
|
||||||
|
val alias = activeAlias()
|
||||||
|
Log.d(TAG, "requestPermissions called alias=$alias state=${getPermissionState(alias)}")
|
||||||
|
try {
|
||||||
|
if (getPermissionState(alias) == PermissionState.GRANTED) {
|
||||||
|
resolveState(invoke)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
requestPermissionForAlias(alias, invoke, "audioPermissionCallback")
|
||||||
|
Log.d(TAG, "requestPermissionForAlias dispatched for $alias")
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Log.e(TAG, "requestPermissions failed", ex)
|
||||||
|
invoke.reject("requestPermissions: ${ex.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PermissionCallback
|
||||||
|
private fun audioPermissionCallback(invoke: Invoke) {
|
||||||
|
Log.d(TAG, "permission callback, state=${getPermissionState(activeAlias())}")
|
||||||
|
resolveState(invoke)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resolveState(invoke: Invoke) {
|
||||||
|
val json = JSObject()
|
||||||
|
json.put("audio", getPermissionState(activeAlias()).toString())
|
||||||
|
Log.d(TAG, "resolve state=$json")
|
||||||
|
invoke.resolve(json)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "MediaPlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package music.lfeng.me
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.os.PowerManager
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UAC 播放前台服务(M4:锁屏/后台保活)。
|
||||||
|
*
|
||||||
|
* 为什么需要:UAC iso 传输走应用进程,ColorOS 等激进省电策略会把后台应用冻结,
|
||||||
|
* USB 传输停摆 → DAC 断流。前台服务 + partial wake lock 保住进程优先级与 CPU。
|
||||||
|
*
|
||||||
|
* 生命周期(由 UsbPlugin.setPlaybackActive 驱动):
|
||||||
|
* - uac 播放启动 → startPlaybackActive(true) → startForegroundService
|
||||||
|
* - 停止/结束/出错 → setPlaybackActive(false) → stopSelf
|
||||||
|
*
|
||||||
|
* foregroundServiceType="mediaPlayback"(API 29+ 必须;API 34+ 需
|
||||||
|
* FOREGROUND_SERVICE_MEDIA_PLAYBACK 权限,已在 manifest 声明)。
|
||||||
|
*/
|
||||||
|
class UacPlaybackService : Service() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "UacPlaybackService"
|
||||||
|
const val CHANNEL_ID = "uac_playback"
|
||||||
|
const val NOTIFICATION_ID = 40001
|
||||||
|
|
||||||
|
const val ACTION_START = "music.lfeng.me.uac.PLAYBACK_START"
|
||||||
|
const val ACTION_STOP = "music.lfeng.me.uac.PLAYBACK_STOP"
|
||||||
|
|
||||||
|
fun start(context: Context) {
|
||||||
|
val intent = Intent(context, UacPlaybackService::class.java).setAction(ACTION_START)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
} else {
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
context.startService(
|
||||||
|
Intent(context, UacPlaybackService::class.java).setAction(ACTION_STOP)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
when (intent?.action) {
|
||||||
|
ACTION_STOP -> {
|
||||||
|
Log.i(TAG, "stop")
|
||||||
|
releaseWakeLock()
|
||||||
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
|
stopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Log.i(TAG, "start (UAC 播放保活)")
|
||||||
|
startInForeground()
|
||||||
|
acquireWakeLock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return START_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startInForeground() {
|
||||||
|
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
manager.createNotificationChannel(
|
||||||
|
NotificationChannel(
|
||||||
|
CHANNEL_ID,
|
||||||
|
"USB DAC 播放",
|
||||||
|
NotificationManager.IMPORTANCE_LOW
|
||||||
|
).apply { setShowBadge(false) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val contentIntent = PendingIntent.getActivity(
|
||||||
|
this, 0,
|
||||||
|
packageManager.getLaunchIntentForPackage(packageName)
|
||||||
|
?: Intent().setPackage(packageName),
|
||||||
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
val notification: Notification =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
Notification.Builder(this, CHANNEL_ID)
|
||||||
|
.setContentTitle("USB DAC 直出中")
|
||||||
|
.setContentText("bit-perfect 输出 · 点击返回应用")
|
||||||
|
.setSmallIcon(android.R.drawable.stat_sys_headset)
|
||||||
|
.setContentIntent(contentIntent)
|
||||||
|
.setOngoing(true)
|
||||||
|
.build()
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
Notification.Builder(this)
|
||||||
|
.setContentTitle("USB DAC 直出中")
|
||||||
|
.setContentText("bit-perfect 输出 · 点击返回应用")
|
||||||
|
.setSmallIcon(android.R.drawable.stat_sys_headset)
|
||||||
|
.setContentIntent(contentIntent)
|
||||||
|
.setOngoing(true)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
startForeground(
|
||||||
|
NOTIFICATION_ID,
|
||||||
|
notification,
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
startForeground(NOTIFICATION_ID, notification)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun acquireWakeLock() {
|
||||||
|
if (wakeLock?.isHeld == true) return
|
||||||
|
val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lfmusic:uac_playback").apply {
|
||||||
|
setReferenceCounted(false)
|
||||||
|
acquire(4 * 60 * 60 * 1000L) // 上限 4h,正常由 stop 释放
|
||||||
|
}
|
||||||
|
Log.i(TAG, "partial wake lock acquired")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun releaseWakeLock() {
|
||||||
|
wakeLock?.let {
|
||||||
|
if (it.isHeld) it.release()
|
||||||
|
}
|
||||||
|
wakeLock = null
|
||||||
|
Log.i(TAG, "wake lock released")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
releaseWakeLock()
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
package music.lfeng.me
|
||||||
|
|
||||||
|
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.UsbConstants
|
||||||
|
import android.hardware.usb.UsbDevice
|
||||||
|
import android.hardware.usb.UsbDeviceConnection
|
||||||
|
import android.hardware.usb.UsbManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
|
import app.tauri.annotation.Command
|
||||||
|
import app.tauri.annotation.TauriPlugin
|
||||||
|
import app.tauri.plugin.Invoke
|
||||||
|
import app.tauri.plugin.JSArray
|
||||||
|
import app.tauri.plugin.JSObject
|
||||||
|
import app.tauri.plugin.Plugin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* USB Host 桥(LFMusic PLAN M4:UAC 播放的 Kotlin 侧)。
|
||||||
|
*
|
||||||
|
* 职责(Flick MainActivity.kt 同款模式,flutter→tauri 适配):
|
||||||
|
* 1. listDevices —— UsbManager.deviceList 枚举 + UAC 识别(class 0x01)
|
||||||
|
* 2. requestPermission —— UsbManager.requestPermission 系统弹窗(广播回调,非
|
||||||
|
* Tauri Permission 注解体系——USB host 权限是 intent 流程,不是 manifest 危险权限)
|
||||||
|
* 3. openDevice —— openDevice() 返回 UsbDeviceConnection,**保存在本插件内
|
||||||
|
* 保活**,把 fileDescriptor 交给 JS → Rust `uac_open`(dup + libusb wrap_sys_device)
|
||||||
|
* 4. closeDevice —— 关闭保活连接(Rust 侧已 dup,不影响其句柄存活)
|
||||||
|
* 5. 热插拔 —— ATTACH/DETACH 广播 → trigger("usb-attach"/"usb-detach")
|
||||||
|
*
|
||||||
|
* **踩点(照抄 Flick 2026 现役实现)**:
|
||||||
|
* - PendingIntent 必须 FLAG_MUTABLE(系统要往里塞 EXTRA_PERMISSION_GRANTED 等 extras)
|
||||||
|
* - API 33+ 注册 receiver 必须 RECEIVER_NOT_EXPORTED
|
||||||
|
* - UsbDeviceConnection 必须保活(与 Flick 一致)
|
||||||
|
* - Invoke 取参用 parseArgs + @InvocationArg 数据类(Invoke 无 getString 方法)
|
||||||
|
*/
|
||||||
|
@TauriPlugin
|
||||||
|
class UsbPlugin(private val activity: Activity) : Plugin(activity) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "UsbPlugin"
|
||||||
|
const val ACTION_USB_PERMISSION = "music.lfeng.me.USB_PERMISSION"
|
||||||
|
}
|
||||||
|
|
||||||
|
/** invoke 取参:getArgs() 返回 JSObject(JSONObject 子类) */
|
||||||
|
private fun Invoke.argDeviceName(): String =
|
||||||
|
try {
|
||||||
|
this.getArgs().getString("deviceName") ?: ""
|
||||||
|
} catch (_: Exception) {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
private val connections = LinkedHashMap<String, UsbDeviceConnection>()
|
||||||
|
private val pendingPermission = HashMap<String, Invoke>()
|
||||||
|
|
||||||
|
private val receiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
when (intent.action) {
|
||||||
|
ACTION_USB_PERMISSION -> {
|
||||||
|
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) as? UsbDevice
|
||||||
|
}
|
||||||
|
val granted = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)
|
||||||
|
val name = device?.deviceName ?: "unknown"
|
||||||
|
Log.i(TAG, "USB permission result: device=$name granted=$granted")
|
||||||
|
pendingPermission.remove(name)?.let { invoke ->
|
||||||
|
val ret = JSObject()
|
||||||
|
ret.put("granted", granted as Any)
|
||||||
|
ret.put("deviceName", name)
|
||||||
|
if (!granted) ret.put("error", "用户拒绝了 USB 访问授权")
|
||||||
|
invoke.resolve(ret)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UsbManager.ACTION_USB_DEVICE_ATTACHED -> {
|
||||||
|
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) as? UsbDevice
|
||||||
|
}
|
||||||
|
Log.i(TAG, "USB attached: ${device?.deviceName}")
|
||||||
|
device?.let { trigger("usb-attach", deviceToJs(it)) }
|
||||||
|
}
|
||||||
|
UsbManager.ACTION_USB_DEVICE_DETACHED -> {
|
||||||
|
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) as? UsbDevice
|
||||||
|
}
|
||||||
|
Log.i(TAG, "USB detached: ${device?.deviceName}")
|
||||||
|
device?.let {
|
||||||
|
connections.remove(it.deviceName)?.close()
|
||||||
|
trigger("usb-detach", deviceToJs(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val filter = IntentFilter().apply {
|
||||||
|
addAction(ACTION_USB_PERMISSION)
|
||||||
|
addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
|
||||||
|
addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
activity.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED)
|
||||||
|
} else {
|
||||||
|
activity.registerReceiver(receiver, filter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun usbManager(): UsbManager =
|
||||||
|
activity.getSystemService(Context.USB_SERVICE) as UsbManager
|
||||||
|
|
||||||
|
private fun deviceToJs(device: UsbDevice): JSObject {
|
||||||
|
val o = JSObject()
|
||||||
|
o.put("deviceName", device.deviceName)
|
||||||
|
o.put("vendorId", device.vendorId as Any)
|
||||||
|
o.put("productId", device.productId as Any)
|
||||||
|
o.put("productName", device.productName ?: "")
|
||||||
|
o.put("manufacturerName", device.manufacturerName ?: "")
|
||||||
|
// 未授权时读 serialNumber 会被 UsbSerialReader 拒绝(SecurityException),
|
||||||
|
// 授权后 openDevice 时再取
|
||||||
|
o.put("serialNumber", try { device.serialNumber ?: "" } catch (_: Exception) { "" })
|
||||||
|
o.put("hasPermission", usbManager().hasPermission(device) as Any)
|
||||||
|
// UAC 识别:任一接口 class == AUDIO(0x01);protocol 0x20 = UAC 2.0
|
||||||
|
var isUac = false
|
||||||
|
var isUac2 = false
|
||||||
|
for (i in 0 until device.interfaceCount) {
|
||||||
|
val iface = device.getInterface(i)
|
||||||
|
if (iface.interfaceClass == UsbConstants.USB_CLASS_AUDIO) {
|
||||||
|
isUac = true
|
||||||
|
if (iface.interfaceProtocol == 0x20) isUac2 = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.put("isUac", isUac as Any)
|
||||||
|
o.put("isUac2", isUac2 as Any)
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
fun listDevices(invoke: Invoke) {
|
||||||
|
try {
|
||||||
|
val manager = usbManager()
|
||||||
|
val arr = JSArray()
|
||||||
|
for ((_, device) in manager.deviceList) {
|
||||||
|
arr.put(deviceToJs(device))
|
||||||
|
}
|
||||||
|
val ret = JSObject()
|
||||||
|
ret.put("devices", arr)
|
||||||
|
invoke.resolve(ret)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "listDevices failed", e)
|
||||||
|
invoke.reject("listDevices: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
fun requestPermission(invoke: Invoke) {
|
||||||
|
try {
|
||||||
|
val name = invoke.argDeviceName()
|
||||||
|
if (name.isEmpty()) return invoke.reject("缺少 deviceName")
|
||||||
|
val manager = usbManager()
|
||||||
|
val device = manager.deviceList[name]
|
||||||
|
?: return invoke.reject("USB 设备不存在: $name")
|
||||||
|
if (manager.hasPermission(device)) {
|
||||||
|
val ret = JSObject()
|
||||||
|
ret.put("granted", true as Any)
|
||||||
|
ret.put("deviceName", name)
|
||||||
|
invoke.resolve(ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 同名请求进行中:换 invoke(后到者赢)
|
||||||
|
pendingPermission[name] = invoke
|
||||||
|
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
PendingIntent.FLAG_MUTABLE
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
val intent = Intent(ACTION_USB_PERMISSION).setPackage(activity.packageName)
|
||||||
|
val pendingIntent = PendingIntent.getBroadcast(activity, 0, intent, flags)
|
||||||
|
manager.requestPermission(device, pendingIntent)
|
||||||
|
Log.i(TAG, "requestPermission dispatched for $name")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "requestPermission failed", e)
|
||||||
|
invoke.reject("requestPermission: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
fun openDevice(invoke: Invoke) {
|
||||||
|
try {
|
||||||
|
val name = invoke.argDeviceName()
|
||||||
|
if (name.isEmpty()) return invoke.reject("缺少 deviceName")
|
||||||
|
val manager = usbManager()
|
||||||
|
val device = manager.deviceList[name]
|
||||||
|
?: return invoke.reject("USB 设备不存在: $name")
|
||||||
|
if (!manager.hasPermission(device)) {
|
||||||
|
return invoke.reject("USB 设备未授权,请先 requestPermission: $name")
|
||||||
|
}
|
||||||
|
val connection = connections[name] ?: manager.openDevice(device)
|
||||||
|
if (connection == null) {
|
||||||
|
return invoke.reject("openDevice 失败(设备可能已被占用): $name")
|
||||||
|
}
|
||||||
|
connections[name] = connection
|
||||||
|
val fd = connection.fileDescriptor
|
||||||
|
if (fd < 0) {
|
||||||
|
return invoke.reject("fileDescriptor 无效: $name")
|
||||||
|
}
|
||||||
|
Log.i(TAG, "openDevice ok: $name fd=$fd vid=0x%04x pid=0x%04x"
|
||||||
|
.format(device.vendorId, device.productId))
|
||||||
|
val ret = deviceToJs(device)
|
||||||
|
ret.put("fd", fd as Any)
|
||||||
|
invoke.resolve(ret)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "openDevice failed", e)
|
||||||
|
invoke.reject("openDevice: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
fun closeDevice(invoke: Invoke) {
|
||||||
|
try {
|
||||||
|
val name = invoke.argDeviceName()
|
||||||
|
if (name.isEmpty()) return invoke.reject("缺少 deviceName")
|
||||||
|
val conn = connections.remove(name)
|
||||||
|
conn?.close()
|
||||||
|
Log.i(TAG, "closeDevice: $name (had=${conn != null})")
|
||||||
|
invoke.resolve()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "closeDevice failed", e)
|
||||||
|
invoke.reject("closeDevice: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UAC 播放前台服务开关(M4 锁屏/后台保活)。
|
||||||
|
* active=true 启动前台服务(通知+wake lock),false 停止。
|
||||||
|
*/
|
||||||
|
@Command
|
||||||
|
fun setPlaybackActive(invoke: Invoke) {
|
||||||
|
try {
|
||||||
|
val args = invoke.getArgs()
|
||||||
|
val active = args.optBoolean("active", false)
|
||||||
|
if (active) {
|
||||||
|
UacPlaybackService.start(activity)
|
||||||
|
} else {
|
||||||
|
UacPlaybackService.stop(activity)
|
||||||
|
}
|
||||||
|
Log.i(TAG, "setPlaybackActive: $active")
|
||||||
|
invoke.resolve()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "setPlaybackActive failed", e)
|
||||||
|
invoke.reject("setPlaybackActive: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
try {
|
||||||
|
activity.unregisterReceiver(receiver)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
for ((_, conn) in connections) {
|
||||||
|
try {
|
||||||
|
conn.close()
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connections.clear()
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<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>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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="#FFFFFFFF"
|
||||||
|
android:pathData="M0,0h108v108h-108z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
|
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
|
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1008 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
@@ -0,0 +1,6 @@
|
|||||||
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="Theme.lfmusic" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">LFMusic</string>
|
||||||
|
<string name="main_activity_title">LFMusic</string>
|
||||||
|
</resources>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="Theme.lfmusic" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
LFMusic PLAN §2 明文清单:飞牛 LAN(http://)、遥控通道(ws://)、
|
||||||
|
本机流代理(http://127.0.0.1)全部依赖明文放行。
|
||||||
|
LAN 地址随 DHCP 变化、无法用 domain-config 精确圈定,故 base-config 放行;
|
||||||
|
与计划接受的「局域网明文传输」威胁模型一致(MUSIC_REMOTE_PLAN §3.4 P0 结论)。
|
||||||
|
-->
|
||||||
|
<network-security-config>
|
||||||
|
<base-config cleartextTrafficPermitted="true" />
|
||||||
|
</network-security-config>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("https://maven.aliyun.com/repository/google") }
|
||||||
|
maven { url = uri("https://maven.aliyun.com/repository/central") }
|
||||||
|
maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath("com.android.tools.build:gradle:8.11.0")
|
||||||
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.25")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("https://maven.aliyun.com/repository/google") }
|
||||||
|
maven { url = uri("https://maven.aliyun.com/repository/central") }
|
||||||
|
maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("clean").configure {
|
||||||
|
delete("build")
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
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 = """bun""";
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# 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
|
||||||
|
# 消除 Kotlin daemon 跨盘路径 bug(C: 对 F: 的 relativeTo 崩溃 → 回退非增量编译)
|
||||||
|
kotlin.incremental=false
|
||||||
|
# 隐藏 Java source/target 8 过时警告(AGP 默认 target 8)
|
||||||
|
android.javaCompile.suppressSourceTargetDeprecationWarning=true
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#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
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
#!/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" "$@"
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
@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
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
include ':app'
|
||||||
|
|
||||||
|
apply from: 'tauri.settings.gradle'
|
||||||
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 567 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 536 B |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 777 B |
|
After Width: | Height: | Size: 1020 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 848 B |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
# 包名 = Tauri 插件名(JS: plugin:media|...;与 Kotlin MediaPlugin 通过
|
||||||
|
# lib.rs 的 register_android_plugin("music.lfeng.me", "MediaPlugin") 关联)
|
||||||
|
name = "media"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
# tauri-plugin build 约定:links 必须设置且与包名一致(tauri-plugin 2.x try_build 强制)
|
||||||
|
links = "media"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-plugin = "2"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
//! ACL 清单生成(M1-a):本 crate 只承载 Tauri 插件的**构建期权限清单**,
|
||||||
|
//! 无运行时代码。`CARGO_PKG_NAME = media` 决定插件名;命令列表对应
|
||||||
|
//! Kotlin `MediaPlugin` 的 checkPermissions / requestPermissions 覆写方法。
|
||||||
|
fn main() {
|
||||||
|
tauri_plugin::Builder::new(&["check_permissions", "request_permissions"]).build();
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Automatically generated - DO NOT EDIT!
|
||||||
|
|
||||||
|
"$schema" = "../../schemas/schema.json"
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "allow-check-permissions"
|
||||||
|
description = "Enables the check_permissions command without any pre-configured scope."
|
||||||
|
commands.allow = ["check_permissions"]
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "deny-check-permissions"
|
||||||
|
description = "Denies the check_permissions command without any pre-configured scope."
|
||||||
|
commands.deny = ["check_permissions"]
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Automatically generated - DO NOT EDIT!
|
||||||
|
|
||||||
|
"$schema" = "../../schemas/schema.json"
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "allow-request-permissions"
|
||||||
|
description = "Enables the request_permissions command without any pre-configured scope."
|
||||||
|
commands.allow = ["request_permissions"]
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "deny-request-permissions"
|
||||||
|
description = "Denies the request_permissions command without any pre-configured scope."
|
||||||
|
commands.deny = ["request_permissions"]
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
## Default Permission
|
||||||
|
|
||||||
|
Allows checking and requesting the audio media permission (READ_MEDIA_AUDIO)
|
||||||
|
needed for local music library scanning.
|
||||||
|
|
||||||
|
#### This default permission set includes the following:
|
||||||
|
|
||||||
|
- `allow-check-permissions`
|
||||||
|
- `allow-request-permissions`
|
||||||
|
|
||||||
|
## Permission Table
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Identifier</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`media:allow-check-permissions`
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Enables the check_permissions command without any pre-configured scope.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`media:deny-check-permissions`
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Denies the check_permissions command without any pre-configured scope.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`media:allow-request-permissions`
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Enables the request_permissions command without any pre-configured scope.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`media:deny-request-permissions`
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Denies the request_permissions command without any pre-configured scope.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[default]
|
||||||
|
description = """Allows checking and requesting the audio media permission (READ_MEDIA_AUDIO)
|
||||||
|
needed for local music library scanning."""
|
||||||
|
permissions = [
|
||||||
|
"allow-check-permissions",
|
||||||
|
"allow-request-permissions",
|
||||||
|
]
|
||||||
@@ -0,0 +1,330 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"title": "PermissionFile",
|
||||||
|
"description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"default": {
|
||||||
|
"description": "The default permission set for the plugin",
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/DefaultPermission"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"set": {
|
||||||
|
"description": "A list of permissions sets defined",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/PermissionSet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"permission": {
|
||||||
|
"description": "A list of inlined permissions",
|
||||||
|
"default": [],
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Permission"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"DefaultPermission": {
|
||||||
|
"description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"permissions"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"description": "The version of the permission.",
|
||||||
|
"type": [
|
||||||
|
"integer",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"format": "uint64",
|
||||||
|
"minimum": 1.0
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"description": "Human-readable description of what the permission does. Tauri convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
||||||
|
"type": [
|
||||||
|
"string",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"description": "All permissions this set contains.",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"PermissionSet": {
|
||||||
|
"description": "A set of direct permissions grouped together under a new name.",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"description",
|
||||||
|
"identifier",
|
||||||
|
"permissions"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"identifier": {
|
||||||
|
"description": "A unique identifier for the permission.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"description": "Human-readable description of what the permission does.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"description": "All permissions this set contains.",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/PermissionKind"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Permission": {
|
||||||
|
"description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"identifier"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"description": "The version of the permission.",
|
||||||
|
"type": [
|
||||||
|
"integer",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"format": "uint64",
|
||||||
|
"minimum": 1.0
|
||||||
|
},
|
||||||
|
"identifier": {
|
||||||
|
"description": "A unique identifier for the permission.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"description": "Human-readable description of what the permission does. Tauri internal convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
||||||
|
"type": [
|
||||||
|
"string",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"commands": {
|
||||||
|
"description": "Allowed or denied commands when using this permission.",
|
||||||
|
"default": {
|
||||||
|
"allow": [],
|
||||||
|
"deny": []
|
||||||
|
},
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/Commands"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"description": "Allowed or denied scoped when using this permission.",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/Scopes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"platforms": {
|
||||||
|
"description": "Target platforms this permission applies. By default all platforms are affected by this permission.",
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Target"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Commands": {
|
||||||
|
"description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"allow": {
|
||||||
|
"description": "Allowed command.",
|
||||||
|
"default": [],
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deny": {
|
||||||
|
"description": "Denied command, which takes priority.",
|
||||||
|
"default": [],
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Scopes": {
|
||||||
|
"description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"allow": {
|
||||||
|
"description": "Data that defines what is allowed by the scope.",
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deny": {
|
||||||
|
"description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.",
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Value": {
|
||||||
|
"description": "All supported ACL values.",
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"description": "Represents a null JSON value.",
|
||||||
|
"type": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a [`bool`].",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a valid ACL [`Number`].",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/Number"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a [`String`].",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a list of other [`Value`]s.",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a map of [`String`] keys to [`Value`]s.",
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Number": {
|
||||||
|
"description": "A valid ACL number.",
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"description": "Represents an [`i64`].",
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a [`f64`].",
|
||||||
|
"type": "number",
|
||||||
|
"format": "double"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Target": {
|
||||||
|
"description": "Platform target.",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"description": "MacOS.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"macOS"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Windows.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"windows"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Linux.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Android.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"android"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "iOS.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"iOS"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"PermissionKind": {
|
||||||
|
"type": "string",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"description": "Enables the check_permissions command without any pre-configured scope.",
|
||||||
|
"type": "string",
|
||||||
|
"const": "allow-check-permissions",
|
||||||
|
"markdownDescription": "Enables the check_permissions command without any pre-configured scope."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Denies the check_permissions command without any pre-configured scope.",
|
||||||
|
"type": "string",
|
||||||
|
"const": "deny-check-permissions",
|
||||||
|
"markdownDescription": "Denies the check_permissions command without any pre-configured scope."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Enables the request_permissions command without any pre-configured scope.",
|
||||||
|
"type": "string",
|
||||||
|
"const": "allow-request-permissions",
|
||||||
|
"markdownDescription": "Enables the request_permissions command without any pre-configured scope."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Denies the request_permissions command without any pre-configured scope.",
|
||||||
|
"type": "string",
|
||||||
|
"const": "deny-request-permissions",
|
||||||
|
"markdownDescription": "Denies the request_permissions command without any pre-configured scope."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Allows checking and requesting the audio media permission (READ_MEDIA_AUDIO)\nneeded for local music library scanning.\n#### This default permission set includes:\n\n- `allow-check-permissions`\n- `allow-request-permissions`",
|
||||||
|
"type": "string",
|
||||||
|
"const": "default",
|
||||||
|
"markdownDescription": "Allows checking and requesting the audio media permission (READ_MEDIA_AUDIO)\nneeded for local music library scanning.\n#### This default permission set includes:\n\n- `allow-check-permissions`\n- `allow-request-permissions`"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
//! `media` 插件 ACL 载体 crate(M1-a)。
|
||||||
|
//!
|
||||||
|
//! 运行时逻辑分布:
|
||||||
|
//! - JS:`checkPermissions('media')` / `requestPermissions('media')`(@tauri-apps/api/core 约定)
|
||||||
|
//! - 注册:LFMusic `lib.rs::media_plugin` → JNI 实例化 Kotlin `music.lfeng.me.MediaPlugin`
|
||||||
|
//! - 实现:`gen/android/.../MediaPlugin.kt`(READ_MEDIA_AUDIO 运行时申请)
|
||||||
|
//!
|
||||||
|
//! 本 crate 仅为了让 tauri-plugin build 系统生成 `media:*` 权限清单
|
||||||
|
//! (name 取 CARGO_PKG_NAME,故包名必须是 `media`)。
|
||||||
@@ -0,0 +1,820 @@
|
|||||||
|
//! 飞牛 fnOS 音乐曲库(M2)——登录/曲库/歌词/封面/流,与 Thing `music/feiniu/`
|
||||||
|
//! **字段级对齐**(同一套 NAS API:`/music/api/v1/*`,登录签名、Cookie 鉴权、
|
||||||
|
//! 安全码头与 Thing conn.rs / mod.rs 逐字段一致;LFMusic PLAN §4 行动项口径:
|
||||||
|
//! 本端为裁剪移植版,改动需回看 Thing 源,双端不得私自漂移)。
|
||||||
|
//!
|
||||||
|
//! 裁剪自 Thing 的部分(本端不需要):WebDAV 上传、FnConnect 解析(P2)、
|
||||||
|
//! 播放缓存(P1)、本地目录扫描(本地曲库在 `library.rs`)。
|
||||||
|
//!
|
||||||
|
//! 存储(app_data 目录):
|
||||||
|
//! - `feiniu.json`:连接列表 + 激活 id + deviceId(设备 id 登录签名用,一次生成复用)
|
||||||
|
//! - `feiniu_tokens.json`:`{ connId: userToken }`——**token 不进连接结构**,
|
||||||
|
//! 独立文件保存(应用私有目录;keyring 3.6.3 无 Android 支持,实测结论见 PLAN §4,
|
||||||
|
//! Keystore/stronghold 升级留待后续,威胁模型与 remote token 同级)
|
||||||
|
//!
|
||||||
|
//! 播放:曲目 `path` 直接是本机代理 URL(`http://127.0.0.1:{port}/feiniu/stream?guid=…`),
|
||||||
|
//! 与本地曲库的绝对路径**同字段语义**——player 编排层零改动(PLAN §3.1 PlaySource)。
|
||||||
|
|
||||||
|
mod proxy;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tauri::{AppHandle, Manager};
|
||||||
|
|
||||||
|
use crate::library::Track;
|
||||||
|
use proxy::{ProxyCfg, ProxyShared};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 连接与设置(字段对齐 Thing FeiniuConnection;token 独立存放)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// 一条 NAS 连接(serde camelCase ↔ TS)。`token` 故意不在结构里(见模块注释)。
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct FeiniuConnection {
|
||||||
|
pub id: String,
|
||||||
|
pub name: String,
|
||||||
|
/// "lan"(局域网/内网转发) | "fnconnect"(P2 预留)
|
||||||
|
pub kind: String,
|
||||||
|
pub base_url: String,
|
||||||
|
pub username: String,
|
||||||
|
/// 访问安全码(可选;仅需访问码的库填写,LAN 通常为空)
|
||||||
|
#[serde(default)]
|
||||||
|
pub access_code: String,
|
||||||
|
/// 自签名证书(https NAS)跳过校验
|
||||||
|
#[serde(default)]
|
||||||
|
pub insecure: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub fn_id: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub relay: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct FeiniuSettings {
|
||||||
|
/// 32 位 hex 设备 ID(登录签名 deviceId,一次生成复用;对齐 Thing generate_device_id)
|
||||||
|
#[serde(default)]
|
||||||
|
device_id: String,
|
||||||
|
#[serde(default)]
|
||||||
|
active_id: String,
|
||||||
|
#[serde(default)]
|
||||||
|
connections: Vec<FeiniuConnection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 命令返回的连接视图(附登录态)。
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct ConnectionView {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub conn: FeiniuConnection,
|
||||||
|
pub logged_in: bool,
|
||||||
|
pub active: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 曲库列表响应(items 已归一化为 `Track`,path = 本机代理 URL)
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct TrackListResult {
|
||||||
|
pub items: Vec<Track>,
|
||||||
|
pub total: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 整体状态(连接列表/激活/登录态/代理前缀)
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct FeiniuState {
|
||||||
|
pub connections: Vec<ConnectionView>,
|
||||||
|
pub active_id: String,
|
||||||
|
pub username: String,
|
||||||
|
pub logged_in: bool,
|
||||||
|
/// `http://127.0.0.1:{port}/feiniu`(未登录/代理未启为 null)
|
||||||
|
pub media_prefix: Option<String>,
|
||||||
|
pub device_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 运行期
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
struct RuntimeConn {
|
||||||
|
base_url: String,
|
||||||
|
token: String,
|
||||||
|
username: String,
|
||||||
|
access_code: String,
|
||||||
|
insecure: bool,
|
||||||
|
relay: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ClientSlot {
|
||||||
|
insecure: bool,
|
||||||
|
client: reqwest::Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构造请求客户端:`streaming` 决定是否免总超时(流式播放不能有 10s 掐断)。
|
||||||
|
fn build_client(insecure: bool, streaming: bool) -> reqwest::Client {
|
||||||
|
let mut b = reqwest::Client::builder()
|
||||||
|
.no_proxy()
|
||||||
|
.connect_timeout(Duration::from_secs(10))
|
||||||
|
.danger_accept_invalid_certs(insecure);
|
||||||
|
if !streaming {
|
||||||
|
b = b.timeout(Duration::from_secs(10));
|
||||||
|
}
|
||||||
|
b.build().unwrap_or_else(|_| reqwest::Client::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FeiniuManager {
|
||||||
|
settings_path: PathBuf,
|
||||||
|
token_path: PathBuf,
|
||||||
|
settings: Mutex<FeiniuSettings>,
|
||||||
|
runtime: Mutex<RuntimeConn>,
|
||||||
|
client: Mutex<Option<ClientSlot>>,
|
||||||
|
#[allow(dead_code)] // 预留:流式播放独立客户端
|
||||||
|
stream_client: Mutex<Option<ClientSlot>>,
|
||||||
|
proxy: Mutex<Option<(u16, ProxyShared)>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// SHA-256 十六进制(登录密码签名,与 Thing conn.rs `sha256_hex` 逐字节一致)。
|
||||||
|
fn sha256_hex(input: &str) -> String {
|
||||||
|
let mut hasher = Sha256::new();
|
||||||
|
hasher.update(input.as_bytes());
|
||||||
|
format!("{:x}", hasher.finalize())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 规范化服务器地址(对齐 Thing conn.rs `normalize_base_url`)。
|
||||||
|
pub fn normalize_base_url(input: &str) -> String {
|
||||||
|
let mut u = input.trim().trim_end_matches('/').to_string();
|
||||||
|
let lower = u.to_lowercase();
|
||||||
|
if lower.ends_with("/music/api/v1") {
|
||||||
|
u = u[..u.len() - "/music/api/v1".len()].to_string();
|
||||||
|
}
|
||||||
|
u.trim_end_matches('/').to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 32 位 hex 设备 ID(与 Thing conn.rs 同法:时间戳+进程号哈希,不依赖 rand)。
|
||||||
|
fn generate_device_id() -> String {
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
let nanos = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_nanos())
|
||||||
|
.unwrap_or(0);
|
||||||
|
let mut hasher = Sha256::new();
|
||||||
|
hasher.update(format!("{nanos}-{}", std::process::id()).as_bytes());
|
||||||
|
format!("{:x}", hasher.finalize())[..32].to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FeiniuManager {
|
||||||
|
pub fn new(app_data: &PathBuf) -> Self {
|
||||||
|
let settings_path = app_data.join("feiniu.json");
|
||||||
|
let token_path = app_data.join("feiniu_tokens.json");
|
||||||
|
let settings = std::fs::read_to_string(&settings_path)
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| serde_json::from_str::<FeiniuSettings>(&s).ok())
|
||||||
|
.unwrap_or_default();
|
||||||
|
Self {
|
||||||
|
settings_path,
|
||||||
|
token_path,
|
||||||
|
settings: Mutex::new(settings),
|
||||||
|
runtime: Mutex::new(RuntimeConn::default()),
|
||||||
|
client: Mutex::new(None),
|
||||||
|
stream_client: Mutex::new(None),
|
||||||
|
proxy: Mutex::new(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save_settings(&self) -> Result<(), String> {
|
||||||
|
let s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let json = serde_json::to_string_pretty(&*s).map_err(|e| e.to_string())?;
|
||||||
|
std::fs::write(&self.settings_path, json).map_err(|e| format!("写入设置失败: {e}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_tokens(&self) -> HashMap<String, String> {
|
||||||
|
std::fs::read_to_string(&self.token_path)
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| serde_json::from_str(&s).ok())
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save_tokens(&self, map: &HashMap<String, String>) -> Result<(), String> {
|
||||||
|
let json = serde_json::to_string(map).map_err(|e| e.to_string())?;
|
||||||
|
std::fs::write(&self.token_path, json).map_err(|e| format!("写入 token 失败: {e}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn slot_client(slot: &Mutex<Option<ClientSlot>>, insecure: bool, streaming: bool) -> reqwest::Client {
|
||||||
|
let mut g = slot.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let hit = g.as_ref().map(|s| s.insecure == insecure).unwrap_or(false);
|
||||||
|
if !hit {
|
||||||
|
*g = Some(ClientSlot {
|
||||||
|
insecure,
|
||||||
|
client: build_client(insecure, streaming),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
g.as_ref().unwrap().client.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn client(&self, insecure: bool) -> reqwest::Client {
|
||||||
|
Self::slot_client(&self.client, insecure, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn stream_client(&self, insecure: bool) -> reqwest::Client {
|
||||||
|
Self::slot_client(&self.stream_client, insecure, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 把激活连接 + 其 token 同步到运行期(登录/切换/启动时调用;幂等)。
|
||||||
|
pub fn sync_runtime(&self) {
|
||||||
|
let (base, token, username, access_code, insecure, relay) = {
|
||||||
|
let s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
match s.connections.iter().find(|c| c.id == s.active_id) {
|
||||||
|
Some(c) => (
|
||||||
|
c.base_url.clone(),
|
||||||
|
self.load_tokens().get(&c.id).cloned().unwrap_or_default(),
|
||||||
|
c.username.clone(),
|
||||||
|
c.access_code.clone(),
|
||||||
|
c.insecure,
|
||||||
|
c.relay,
|
||||||
|
),
|
||||||
|
None => Default::default(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if let Ok(mut r) = self.runtime.lock() {
|
||||||
|
r.base_url = base;
|
||||||
|
r.token = token;
|
||||||
|
r.username = username;
|
||||||
|
r.access_code = access_code;
|
||||||
|
r.insecure = insecure;
|
||||||
|
r.relay = relay;
|
||||||
|
}
|
||||||
|
self.client(insecure);
|
||||||
|
self.sync_proxy_cfg();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sync_proxy_cfg(&self) {
|
||||||
|
if let Ok(g) = self.proxy.lock() {
|
||||||
|
if let Some((_, shared)) = g.as_ref() {
|
||||||
|
let cfg = self.current_proxy_cfg();
|
||||||
|
if let Ok(mut c) = shared.cfg.lock() {
|
||||||
|
*c = cfg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn current_proxy_cfg(&self) -> ProxyCfg {
|
||||||
|
let r = self.runtime.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
ProxyCfg {
|
||||||
|
base_url: r.base_url.clone(),
|
||||||
|
token: r.token.clone(),
|
||||||
|
access_code: r.access_code.clone(),
|
||||||
|
relay: r.relay,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 惰性启动流代理(PLAN §3.2),返回端口。
|
||||||
|
async fn ensure_proxy(&self) -> Result<u16, String> {
|
||||||
|
{
|
||||||
|
let g = self.proxy.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if let Some((port, _)) = g.as_ref() {
|
||||||
|
return Ok(*port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 锁全部收进块内,确保没有 MutexGuard 跨 await(future 必须 Send)
|
||||||
|
let client = {
|
||||||
|
let r = self.runtime.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
build_client(r.insecure, true) // 流式专用(无总超时)
|
||||||
|
};
|
||||||
|
let shared = ProxyShared {
|
||||||
|
client,
|
||||||
|
cfg: Arc::new(Mutex::new(self.current_proxy_cfg())),
|
||||||
|
};
|
||||||
|
let port = proxy::start(shared.clone()).await?;
|
||||||
|
let mut g = self.proxy.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
*g = Some((port, shared));
|
||||||
|
Ok(port)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 登录 / 登出 =====
|
||||||
|
|
||||||
|
/// 对已保存的连接执行登录(与 Thing feiniu_login 同一接口语义)。
|
||||||
|
/// 成功:token 存储 → 切换为激活连接 → 同步运行期。
|
||||||
|
pub async fn login(
|
||||||
|
&self,
|
||||||
|
connection_id: &str,
|
||||||
|
username: &str,
|
||||||
|
password: &str,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let (base, insecure, relay) = {
|
||||||
|
let s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let c = s
|
||||||
|
.connections
|
||||||
|
.iter()
|
||||||
|
.find(|c| c.id == connection_id)
|
||||||
|
.ok_or_else(|| "连接不存在".to_string())?;
|
||||||
|
(c.base_url.clone(), c.insecure, c.relay)
|
||||||
|
};
|
||||||
|
let base = normalize_base_url(&base);
|
||||||
|
let device_id = {
|
||||||
|
let mut s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if s.device_id.trim().is_empty() {
|
||||||
|
s.device_id = generate_device_id();
|
||||||
|
drop(s);
|
||||||
|
let _ = self.save_settings();
|
||||||
|
self.settings
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|e| e.into_inner())
|
||||||
|
.device_id
|
||||||
|
.clone()
|
||||||
|
} else {
|
||||||
|
s.device_id.clone()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let body = serde_json::json!({
|
||||||
|
"username": username,
|
||||||
|
"password": sha256_hex(password),
|
||||||
|
"deviceId": device_id,
|
||||||
|
});
|
||||||
|
let mut rb = self
|
||||||
|
.client(insecure)
|
||||||
|
.post(format!("{base}/music/api/v1/user/password-login"))
|
||||||
|
.json(&body);
|
||||||
|
if relay {
|
||||||
|
rb = rb.header("cookie", "mode=relay");
|
||||||
|
}
|
||||||
|
let resp = rb.send().await.map_err(|e| {
|
||||||
|
let kind = if e.is_timeout() {
|
||||||
|
"连接超时(NAS 不可达?)"
|
||||||
|
} else {
|
||||||
|
"连接失败"
|
||||||
|
};
|
||||||
|
format!("{kind}: {e}")
|
||||||
|
})?;
|
||||||
|
let status = resp.status();
|
||||||
|
let b: serde_json::Value = resp
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|_| serde_json::json!({ "code": status.as_u16() }));
|
||||||
|
let code = b["code"].as_i64().unwrap_or(i64::from(status.as_u16()));
|
||||||
|
if code != 0 {
|
||||||
|
if code == 120001 {
|
||||||
|
return Err("用户名或密码错误".into());
|
||||||
|
}
|
||||||
|
let msg = b["msg"]
|
||||||
|
.as_str()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.unwrap_or_else(|| format!("HTTP {status}"));
|
||||||
|
return Err(msg);
|
||||||
|
}
|
||||||
|
let token = b["data"]["userToken"]
|
||||||
|
.as_str()
|
||||||
|
.ok_or_else(|| "登录失败:未返回 token".to_string())?
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
// token 落盘 + 回写账号到连接记录(重登页"上次登录"预填)+ 切激活 + 同步运行期
|
||||||
|
let mut tokens = self.load_tokens();
|
||||||
|
tokens.insert(connection_id.to_string(), token);
|
||||||
|
self.save_tokens(&tokens)?;
|
||||||
|
{
|
||||||
|
let mut s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
s.active_id = connection_id.to_string();
|
||||||
|
if let Some(c) = s.connections.iter_mut().find(|c| c.id == connection_id) {
|
||||||
|
c.username = username.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.save_settings()?;
|
||||||
|
self.sync_runtime();
|
||||||
|
println!("[feiniu] 登录成功: {username} @ {base}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 登出激活连接:清 token(连接信息保留)。
|
||||||
|
pub fn logout(&self) {
|
||||||
|
let active = {
|
||||||
|
let s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
s.active_id.clone()
|
||||||
|
};
|
||||||
|
if active.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut tokens = self.load_tokens();
|
||||||
|
tokens.remove(&active);
|
||||||
|
let _ = self.save_tokens(&tokens);
|
||||||
|
self.sync_runtime();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 连接管理 =====
|
||||||
|
|
||||||
|
/// 保存(upsert)一条连接;`id` 为空则生成。返回保存后的连接。
|
||||||
|
pub fn save_connection(&self, mut conn: FeiniuConnection) -> Result<FeiniuConnection, String> {
|
||||||
|
if conn.id.trim().is_empty() {
|
||||||
|
conn.id = format!("c{}", generate_device_id()[..12].to_string());
|
||||||
|
}
|
||||||
|
conn.base_url = normalize_base_url(&conn.base_url);
|
||||||
|
if conn.name.trim().is_empty() {
|
||||||
|
conn.name = conn.base_url.clone();
|
||||||
|
}
|
||||||
|
let mut s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
match s.connections.iter().position(|c| c.id == conn.id) {
|
||||||
|
Some(i) => s.connections[i] = conn.clone(),
|
||||||
|
None => s.connections.push(conn.clone()),
|
||||||
|
}
|
||||||
|
if s.active_id.is_empty() {
|
||||||
|
s.active_id = conn.id.clone();
|
||||||
|
}
|
||||||
|
drop(s);
|
||||||
|
self.save_settings()?;
|
||||||
|
self.sync_runtime();
|
||||||
|
Ok(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete_connection(&self, id: &str) -> Result<(), String> {
|
||||||
|
{
|
||||||
|
let mut s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
s.connections.retain(|c| c.id != id);
|
||||||
|
if s.active_id == id {
|
||||||
|
s.active_id = s.connections.first().map(|c| c.id.clone()).unwrap_or_default();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut tokens = self.load_tokens();
|
||||||
|
tokens.remove(id);
|
||||||
|
let _ = self.save_tokens(&tokens);
|
||||||
|
self.save_settings()?;
|
||||||
|
self.sync_runtime();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_active(&self, id: &str) -> Result<(), String> {
|
||||||
|
{
|
||||||
|
let s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if !s.connections.iter().any(|c| c.id == id) {
|
||||||
|
return Err("连接不存在".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
s.active_id = id.to_string();
|
||||||
|
}
|
||||||
|
self.save_settings()?;
|
||||||
|
self.sync_runtime();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 状态快照(前端入口)。
|
||||||
|
pub fn state(&self) -> FeiniuState {
|
||||||
|
let s = self.settings.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let tokens = self.load_tokens();
|
||||||
|
let connections = s
|
||||||
|
.connections
|
||||||
|
.iter()
|
||||||
|
.map(|c| ConnectionView {
|
||||||
|
logged_in: tokens.contains_key(&c.id),
|
||||||
|
active: c.id == s.active_id,
|
||||||
|
conn: c.clone(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let r = self.runtime.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
FeiniuState {
|
||||||
|
connections,
|
||||||
|
active_id: s.active_id.clone(),
|
||||||
|
username: r.username.clone(),
|
||||||
|
logged_in: !r.token.is_empty(),
|
||||||
|
media_prefix: self.proxy_port().map(|p| format!("http://127.0.0.1:{p}/feiniu")),
|
||||||
|
device_id: s.device_id.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn proxy_port(&self) -> Option<u16> {
|
||||||
|
self.proxy
|
||||||
|
.lock()
|
||||||
|
.ok()
|
||||||
|
.and_then(|g| g.as_ref().map(|(p, _)| *p))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 曲库 / 歌词 =====
|
||||||
|
|
||||||
|
/// 运行期连接快照(同步取出,保证 async 路径里没有 MutexGuard——future 必须 Send)。
|
||||||
|
fn runtime_snapshot(&self) -> Result<(String, String, String, bool, bool), String> {
|
||||||
|
let r = self.runtime.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if r.base_url.is_empty() || r.token.is_empty() {
|
||||||
|
return Err("未登录".into());
|
||||||
|
}
|
||||||
|
Ok((
|
||||||
|
r.base_url.clone(),
|
||||||
|
r.token.clone(),
|
||||||
|
r.access_code.clone(),
|
||||||
|
r.relay,
|
||||||
|
r.insecure,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 鉴权 GET(对齐 Thing authed_get:Cookie music-token + 可选安全码头)。
|
||||||
|
async fn authed_get(&self, path: &str, query: Vec<(String, String)>) -> Result<serde_json::Value, String> {
|
||||||
|
let (base, token, access_code, relay, insecure) = self.runtime_snapshot()?;
|
||||||
|
let qrefs: Vec<(&str, &str)> = query.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect();
|
||||||
|
let mut rb = self
|
||||||
|
.client(insecure)
|
||||||
|
.get(format!("{base}{path}"))
|
||||||
|
.query(&qrefs);
|
||||||
|
rb = rb.header(
|
||||||
|
"cookie",
|
||||||
|
if relay {
|
||||||
|
format!("music-token={token}; mode=relay")
|
||||||
|
} else {
|
||||||
|
format!("music-token={token}")
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if !access_code.is_empty() {
|
||||||
|
use base64::Engine;
|
||||||
|
rb = rb
|
||||||
|
.header(
|
||||||
|
"x-access-code",
|
||||||
|
base64::engine::general_purpose::STANDARD.encode(access_code.as_bytes()),
|
||||||
|
)
|
||||||
|
.header("x-access-source", "app");
|
||||||
|
}
|
||||||
|
let resp = rb.send().await.map_err(|e| format!("请求失败: {e}"))?;
|
||||||
|
let status = resp.status();
|
||||||
|
let body: serde_json::Value = resp
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|_| serde_json::json!({ "code": status.as_u16() }));
|
||||||
|
let code = body["code"].as_i64().unwrap_or(i64::from(status.as_u16()));
|
||||||
|
if code != 0 {
|
||||||
|
if status == reqwest::StatusCode::UNAUTHORIZED
|
||||||
|
|| status == reqwest::StatusCode::FORBIDDEN
|
||||||
|
{
|
||||||
|
return Err("登录已过期,请重新登录".into());
|
||||||
|
}
|
||||||
|
let msg = body["msg"]
|
||||||
|
.as_str()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.unwrap_or_else(|| format!("请求失败(HTTP {status})"));
|
||||||
|
return Err(msg);
|
||||||
|
}
|
||||||
|
Ok(body["data"].clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 分页拉曲目(`GET /track/list`,可选 keyword——实测 NAS 忽略 keyword,
|
||||||
|
/// 搜索由前端本地筛选,保留参数仅为与 Thing 接口兼容)。
|
||||||
|
/// 返回前把 NAS 行归一化为 [`Track`]:`id`=guid、`path`=本机代理流 URL、
|
||||||
|
/// `coverPath`=代理封面 URL、`nas`=true。
|
||||||
|
pub async fn list_tracks(
|
||||||
|
&self,
|
||||||
|
page: u32,
|
||||||
|
size: u32,
|
||||||
|
keyword: Option<&str>,
|
||||||
|
) -> Result<TrackListResult, String> {
|
||||||
|
let port = self.ensure_proxy().await?;
|
||||||
|
let prefix = format!("http://127.0.0.1:{port}/feiniu");
|
||||||
|
let size = size.clamp(1, 100);
|
||||||
|
let mut query = vec![
|
||||||
|
("page".to_string(), page.to_string()),
|
||||||
|
("size".to_string(), size.to_string()),
|
||||||
|
];
|
||||||
|
let kw = keyword.unwrap_or("").trim().to_string();
|
||||||
|
if !kw.is_empty() {
|
||||||
|
query.push(("keyword".to_string(), kw));
|
||||||
|
}
|
||||||
|
let data = self.authed_get("/music/api/v1/track/list", query).await?;
|
||||||
|
|
||||||
|
// 响应形状宽松映射(对齐 Thing 前端 normalizeTrack 的兼容面)
|
||||||
|
let (rows, total) = if let Some(arr) = data.as_array() {
|
||||||
|
(arr.clone(), None)
|
||||||
|
} else {
|
||||||
|
let list = data
|
||||||
|
.get("list")
|
||||||
|
.or_else(|| data.get("items"))
|
||||||
|
.or_else(|| data.get("tracks"))
|
||||||
|
.and_then(|v| v.as_array())
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default();
|
||||||
|
let total = data
|
||||||
|
.get("total")
|
||||||
|
.or_else(|| data.get("count"))
|
||||||
|
.and_then(|v| v.as_u64());
|
||||||
|
(list, total)
|
||||||
|
};
|
||||||
|
|
||||||
|
let items = rows.iter().map(|t| map_track(t, &prefix)).collect();
|
||||||
|
Ok(TrackListResult { items, total })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 歌词纯文本(`GET /lyric/list?trackGUID=`,宽松提取,对齐 Thing extract_lyric_text)。
|
||||||
|
pub async fn lyric(&self, guid: &str) -> Result<String, String> {
|
||||||
|
let v = self
|
||||||
|
.authed_get(
|
||||||
|
"/music/api/v1/lyric/list",
|
||||||
|
vec![("trackGUID".to_string(), guid.to_string())],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(extract_lyric_text(&v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// NAS 行 → 统一 [`Track`](映射规则对齐 Thing feiniuStore.normalizeTrack)。
|
||||||
|
fn map_track(t: &serde_json::Value, prefix: &str) -> Track {
|
||||||
|
use serde_json::Value;
|
||||||
|
let artists = t.get("artists").and_then(|a| a.as_array()).cloned().unwrap_or_default();
|
||||||
|
let album = match t.get("album") {
|
||||||
|
Some(Value::String(s)) => s.clone(),
|
||||||
|
Some(Value::Object(o)) => o
|
||||||
|
.get("name")
|
||||||
|
.or_else(|| o.get("albumName"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string(),
|
||||||
|
_ => t
|
||||||
|
.get("albumName")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string(),
|
||||||
|
};
|
||||||
|
let artist = {
|
||||||
|
let from_arr: String = artists
|
||||||
|
.iter()
|
||||||
|
.filter_map(|a| a.get("name").and_then(|n| n.as_str()))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" / ");
|
||||||
|
if !from_arr.is_empty() {
|
||||||
|
from_arr
|
||||||
|
} else {
|
||||||
|
t.get("artist")
|
||||||
|
.or_else(|| t.get("singers"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let guid = t
|
||||||
|
.get("guid")
|
||||||
|
.or_else(|| t.get("trackGuid"))
|
||||||
|
.or_else(|| t.get("id"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string();
|
||||||
|
let title = t
|
||||||
|
.get("title")
|
||||||
|
.or_else(|| t.get("name"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("未知标题")
|
||||||
|
.to_string();
|
||||||
|
let duration_ms = t
|
||||||
|
.get("durationMs")
|
||||||
|
.or_else(|| t.get("duration"))
|
||||||
|
.and_then(|v| v.as_u64())
|
||||||
|
.unwrap_or(0);
|
||||||
|
let cover_id = t.get("coverId").and_then(|v| v.as_str()).unwrap_or("");
|
||||||
|
// 源格式:audioSpec.format(dsf/dff/flac/mp3…)——前端白名单拦截 ExoPlayer 不支持的 DSD
|
||||||
|
let fmt = t
|
||||||
|
.get("audioSpec")
|
||||||
|
.and_then(|a| a.get("format"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(|s| s.to_lowercase());
|
||||||
|
Track {
|
||||||
|
id: guid.clone(),
|
||||||
|
title,
|
||||||
|
artist,
|
||||||
|
album,
|
||||||
|
duration_sec: duration_ms as f64 / 1000.0,
|
||||||
|
path: format!("{prefix}/stream?guid={guid}"),
|
||||||
|
cover_path: if cover_id.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(format!("{prefix}/cover?coverId={cover_id}&size=512"))
|
||||||
|
},
|
||||||
|
nas: true,
|
||||||
|
fmt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 从 /lyric/list 响应取第一段歌词文本(对齐 Thing extract_lyric_text 的宽松映射)。
|
||||||
|
fn extract_lyric_text(v: &serde_json::Value) -> String {
|
||||||
|
use serde_json::Value;
|
||||||
|
match v {
|
||||||
|
Value::Array(arr) => arr
|
||||||
|
.first()
|
||||||
|
.map(|it| {
|
||||||
|
it["content"]
|
||||||
|
.as_str()
|
||||||
|
.or_else(|| it["lyric"].as_str())
|
||||||
|
.or_else(|| it["text"].as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string()
|
||||||
|
})
|
||||||
|
.unwrap_or_default(),
|
||||||
|
// authed_get 已解包到 data 层,实测形状为 { list: [ { content } ], preferred }
|
||||||
|
Value::Object(_) => v["content"]
|
||||||
|
.as_str()
|
||||||
|
.or_else(|| v["lyric"].as_str())
|
||||||
|
.or_else(|| v["text"].as_str())
|
||||||
|
.map(str::to_string)
|
||||||
|
.unwrap_or_else(|| first_lyric_in_list(&v["list"])),
|
||||||
|
_ => String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `list` 数组里取第一段歌词(content / lyric / text 宽松映射)。
|
||||||
|
fn first_lyric_in_list(v: &serde_json::Value) -> String {
|
||||||
|
v.as_array()
|
||||||
|
.and_then(|arr| arr.first())
|
||||||
|
.map(|it| {
|
||||||
|
it["content"]
|
||||||
|
.as_str()
|
||||||
|
.or_else(|| it["lyric"].as_str())
|
||||||
|
.or_else(|| it["text"].as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string()
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Tauri 命令
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// 状态(连接列表 + 登录态 + 代理前缀)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn feiniu_get_state(app: AppHandle) -> FeiniuState {
|
||||||
|
app.state::<FeiniuManager>().state()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 保存/upsert 连接(不含 token;登录走 feiniu_login)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn feiniu_save_connection(
|
||||||
|
app: AppHandle,
|
||||||
|
connection: FeiniuConnection,
|
||||||
|
) -> Result<ConnectionView, String> {
|
||||||
|
let m = app.state::<FeiniuManager>();
|
||||||
|
let saved = m.save_connection(connection)?;
|
||||||
|
let st = m.state();
|
||||||
|
st.connections
|
||||||
|
.into_iter()
|
||||||
|
.find(|c| c.conn.id == saved.id)
|
||||||
|
.ok_or_else(|| "保存后未找到连接".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn feiniu_delete_connection(app: AppHandle, id: String) -> Result<(), String> {
|
||||||
|
app.state::<FeiniuManager>().delete_connection(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn feiniu_set_active(app: AppHandle, id: String) -> Result<(), String> {
|
||||||
|
app.state::<FeiniuManager>().set_active(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 登录(接口与 Thing feiniu_login 对齐:connectionId + 账号密码)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn feiniu_login(
|
||||||
|
app: AppHandle,
|
||||||
|
connection_id: String,
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
app.state::<FeiniuManager>()
|
||||||
|
.login(&connection_id, &username, &password)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn feiniu_logout(app: AppHandle) {
|
||||||
|
app.state::<FeiniuManager>().logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 曲库分页(size clamp 1..=100,与 Thing 一致)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn feiniu_list_tracks(
|
||||||
|
app: AppHandle,
|
||||||
|
page: u32,
|
||||||
|
size: u32,
|
||||||
|
keyword: Option<String>,
|
||||||
|
) -> Result<TrackListResult, String> {
|
||||||
|
app.state::<FeiniuManager>()
|
||||||
|
.list_tracks(page, size, keyword.as_deref())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 歌词(guid = Track.id)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn feiniu_lyric(app: AppHandle, guid: String) -> Result<String, String> {
|
||||||
|
let r = app.state::<FeiniuManager>().lyric(&guid).await;
|
||||||
|
match &r {
|
||||||
|
Ok(s) => println!("[feiniu] lyric ok guid={guid} len={}", s.len()),
|
||||||
|
Err(e) => println!("[feiniu] lyric err guid={guid}: {e}"),
|
||||||
|
}
|
||||||
|
r
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 确保流代理已启动并返回前缀(前端预热/封面地址兜底用)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn feiniu_media_prefix(app: AppHandle) -> Result<String, String> {
|
||||||
|
let port = app.state::<FeiniuManager>().ensure_proxy().await?;
|
||||||
|
Ok(format!("http://127.0.0.1:{port}/feiniu"))
|
||||||
|
}
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
//! 飞牛音乐本地流代理(axum)——移植自 Thing `music/feiniu/proxy.rs`(裁剪 local-cover,
|
||||||
|
//! 本地封面在本端走 convertFileSrc 直读内嵌图片文件)。
|
||||||
|
//!
|
||||||
|
//! 原生 `/track/stream`、`/static/cover` 需要 `Cookie: music-token=<token>`,
|
||||||
|
//! 而 WebView 的 `<audio>/<img>` 无法设置 Cookie。本模块绑定 `127.0.0.1:<动态端口>`,
|
||||||
|
//! 转发时注入 Cookie 与可选的安全码头,前端直接用本地地址播放/显示,
|
||||||
|
//! **天然支持 Range/seek**(PLAN §3.2:Range 透传是流式播放的硬需求)。
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::{Query, State},
|
||||||
|
http::{header, HeaderMap, StatusCode},
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
routing::get,
|
||||||
|
Router,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// 由 Feiniu 运行期与代理 handler 共享的连接配置(登录更新、登出置空即时生效)。
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
pub struct ProxyCfg {
|
||||||
|
pub base_url: String,
|
||||||
|
pub token: String,
|
||||||
|
pub access_code: String,
|
||||||
|
/// FnConnect 中继链路(P2 启用):请求需携带 `Cookie: mode=relay`
|
||||||
|
pub relay: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ProxyShared {
|
||||||
|
pub client: reqwest::Client,
|
||||||
|
pub cfg: Arc<Mutex<ProxyCfg>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 启动本地流代理,绑定 `127.0.0.1:0`(动态空闲端口),返回实际端口。
|
||||||
|
/// 代理以独立任务常驻应用存活期;token 变化经共享 `ProxyCfg` 即时生效。
|
||||||
|
pub async fn start(shared: ProxyShared) -> Result<u16, String> {
|
||||||
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("绑定本地端口失败: {e}"))?;
|
||||||
|
let port = listener
|
||||||
|
.local_addr()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.port();
|
||||||
|
let app = Router::new()
|
||||||
|
.route("/feiniu/stream", get(proxy_stream))
|
||||||
|
.route("/feiniu/cover", get(proxy_cover))
|
||||||
|
.with_state(shared);
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
if let Err(e) = axum::serve(listener, app).await {
|
||||||
|
println!("[feiniu] 流代理异常退出: {e}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
println!("[feiniu] 流代理已启动: http://127.0.0.1:{port}");
|
||||||
|
Ok(port)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 音频流:`GET /feiniu/stream?guid=<trackGuid>`(seek 依赖 Range 透传)。
|
||||||
|
async fn proxy_stream(
|
||||||
|
State(s): State<ProxyShared>,
|
||||||
|
Query(q): Query<HashMap<String, String>>,
|
||||||
|
headers: HeaderMap,
|
||||||
|
) -> Response {
|
||||||
|
let guid = q.get("guid").cloned().unwrap_or_default().trim().to_string();
|
||||||
|
if guid.is_empty() {
|
||||||
|
return (StatusCode::BAD_REQUEST, "missing guid").into_response();
|
||||||
|
}
|
||||||
|
forward(
|
||||||
|
&s,
|
||||||
|
"/music/api/v1/track/stream",
|
||||||
|
vec![("guid".to_string(), guid)],
|
||||||
|
&headers,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 封面:`GET /feiniu/cover?coverId=<id>&size=<px>`(缓存头必须透传,见 forward)。
|
||||||
|
async fn proxy_cover(
|
||||||
|
State(s): State<ProxyShared>,
|
||||||
|
Query(q): Query<HashMap<String, String>>,
|
||||||
|
headers: HeaderMap,
|
||||||
|
) -> Response {
|
||||||
|
let cover_id = q
|
||||||
|
.get("coverId")
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.trim()
|
||||||
|
.to_string();
|
||||||
|
if cover_id.is_empty() {
|
||||||
|
return (StatusCode::BAD_REQUEST, "missing coverId").into_response();
|
||||||
|
}
|
||||||
|
let size = q.get("size").cloned().unwrap_or_else(|| "320".into());
|
||||||
|
forward(
|
||||||
|
&s,
|
||||||
|
"/music/api/v1/static/cover",
|
||||||
|
vec![
|
||||||
|
("coverId".to_string(), cover_id),
|
||||||
|
("size".to_string(), size),
|
||||||
|
],
|
||||||
|
&headers,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 统一转发:向 NAS 发起上游 GET,注入 Cookie/安全码,透传 Range 与响应头,流式回传 body。
|
||||||
|
async fn forward(
|
||||||
|
s: &ProxyShared,
|
||||||
|
path: &str,
|
||||||
|
query: Vec<(String, String)>,
|
||||||
|
headers: &HeaderMap,
|
||||||
|
) -> Response {
|
||||||
|
let cfg = match s.cfg.lock() {
|
||||||
|
Ok(g) => g.clone(),
|
||||||
|
Err(e) => e.into_inner().clone(),
|
||||||
|
};
|
||||||
|
if cfg.base_url.is_empty() || cfg.token.is_empty() {
|
||||||
|
return (StatusCode::UNAUTHORIZED, "飞牛音乐未登录").into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
let base = super::normalize_base_url(&cfg.base_url);
|
||||||
|
let url = format!("{base}{path}");
|
||||||
|
let qrefs: Vec<(&str, &str)> = query.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect();
|
||||||
|
|
||||||
|
let mut rb = s.client.get(&url).query(&qrefs);
|
||||||
|
rb = rb.header(
|
||||||
|
"cookie",
|
||||||
|
if cfg.relay {
|
||||||
|
format!("music-token={}; mode=relay", cfg.token)
|
||||||
|
} else {
|
||||||
|
format!("music-token={}", cfg.token)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if !cfg.access_code.is_empty() {
|
||||||
|
use base64::Engine;
|
||||||
|
rb = rb
|
||||||
|
.header(
|
||||||
|
"x-access-code",
|
||||||
|
base64::engine::general_purpose::STANDARD.encode(cfg.access_code.as_bytes()),
|
||||||
|
)
|
||||||
|
.header("x-access-source", "app");
|
||||||
|
}
|
||||||
|
if let Some(range) = headers.get(header::RANGE) {
|
||||||
|
rb = rb.header(header::RANGE, range.clone());
|
||||||
|
}
|
||||||
|
drop(cfg);
|
||||||
|
|
||||||
|
let resp = match rb.send().await {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => return (StatusCode::BAD_GATEWAY, format!("上游错误: {e}")).into_response(),
|
||||||
|
};
|
||||||
|
let status = resp.status();
|
||||||
|
|
||||||
|
// 缓存头/范围头必须透传:丢掉缓存头 = 每次进曲库都重下全部封面;
|
||||||
|
// 丢掉 Content-Range = 拖动进度条后播放器收到 200 全量流、seek 失效。
|
||||||
|
let passthrough = [
|
||||||
|
header::CONTENT_TYPE,
|
||||||
|
header::CONTENT_LENGTH,
|
||||||
|
header::CONTENT_RANGE,
|
||||||
|
header::ACCEPT_RANGES,
|
||||||
|
header::CACHE_CONTROL,
|
||||||
|
];
|
||||||
|
let mut builder = Response::builder().status(status);
|
||||||
|
for h in passthrough {
|
||||||
|
if let Some(v) = resp.headers().get(&h) {
|
||||||
|
builder = builder.header(h, v.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// body 流式转发(不缓冲整首)
|
||||||
|
let stream = resp.bytes_stream();
|
||||||
|
match builder.body(axum::body::Body::from_stream(stream)) {
|
||||||
|
Ok(r) => r.into_response(),
|
||||||
|
Err(_) => (StatusCode::BAD_GATEWAY, "响应构造失败").into_response(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||||
|
mod feiniu;
|
||||||
|
mod library;
|
||||||
|
mod player;
|
||||||
|
mod remote;
|
||||||
|
mod uac;
|
||||||
|
|
||||||
|
use tauri::Manager;
|
||||||
|
|
||||||
|
use feiniu::{
|
||||||
|
feiniu_delete_connection, feiniu_get_state, feiniu_list_tracks, feiniu_login, feiniu_logout,
|
||||||
|
feiniu_lyric, feiniu_media_prefix, feiniu_save_connection, feiniu_set_active, FeiniuManager,
|
||||||
|
};
|
||||||
|
|
||||||
|
use library::{LibraryManager, library_groups, library_list, library_scan};
|
||||||
|
use player::{
|
||||||
|
PlayerManager, player_add_queue, player_clear, player_ended, player_get_state, player_jump,
|
||||||
|
player_next, player_prev, player_set_mode, player_set_queue,
|
||||||
|
};
|
||||||
|
use remote::{
|
||||||
|
remote_forget, remote_get_device, remote_get_token, remote_pair, remote_update_addr,
|
||||||
|
};
|
||||||
|
use uac::{uac_close, uac_enumerate, uac_open, uac_play, uac_set_paused, uac_set_volume, uac_status, uac_stop};
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn greet(name: &str) -> String {
|
||||||
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 「media」插件壳:把 Kotlin `MediaPlugin` 注册进 Tauri 移动插件管理器。
|
||||||
|
/// **JS 路由名 = 这里的 Builder 名 "media"**(`plugin:media|check_permissions`),
|
||||||
|
/// Kotlin 类用包名+类名经 JNI 实例化(M1-a,见 gen/android/.../MediaPlugin.kt)。
|
||||||
|
fn media_plugin<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
||||||
|
tauri::plugin::Builder::new("media")
|
||||||
|
.setup(|_app, _api| {
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
{
|
||||||
|
_api.register_android_plugin("music.lfeng.me", "MediaPlugin")?;
|
||||||
|
println!("[media] Android plugin registered: music.lfeng.me.MediaPlugin");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 「usb」插件壳(M4 UAC):把 Kotlin `UsbPlugin` 注册进 Tauri 移动插件管理器
|
||||||
|
/// (UsbManager 枚举/授权/openDevice→fd 桥,见 gen/android/.../UsbPlugin.kt)。
|
||||||
|
fn usb_plugin<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
||||||
|
tauri::plugin::Builder::new("usb")
|
||||||
|
.setup(|_app, _api| {
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
{
|
||||||
|
_api.register_android_plugin("music.lfeng.me", "UsbPlugin")?;
|
||||||
|
println!("[usb] Android plugin registered: music.lfeng.me.UsbPlugin");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
|
pub fn run() {
|
||||||
|
tauri::Builder::default()
|
||||||
|
.plugin(tauri_plugin_opener::init())
|
||||||
|
// M1 普通播放:原生播放引擎(通知栏/锁屏/后台由插件自带)
|
||||||
|
.plugin(tauri_plugin_native_audio::init())
|
||||||
|
// M1-a:媒体权限 Kotlin 桥(check/request_permissions 约定)
|
||||||
|
.plugin(media_plugin())
|
||||||
|
// M4 UAC:USB Host Kotlin 桥(UsbManager 枚举/授权/openDevice→fd)
|
||||||
|
.plugin(usb_plugin())
|
||||||
|
.setup(|app| {
|
||||||
|
// 手机遥控:beacon 监听常驻(M3,LFMusic PLAN §5.1)
|
||||||
|
remote::spawn_beacon(app.handle().clone());
|
||||||
|
|
||||||
|
// M1 曲库 + 播放编排(扫描需 READ_MEDIA_AUDIO,见 library.rs)
|
||||||
|
let data = app
|
||||||
|
.path()
|
||||||
|
.app_data_dir()
|
||||||
|
.map_err(|e| format!("取应用数据目录失败: {e}"))?;
|
||||||
|
let lib = LibraryManager::open(&data)
|
||||||
|
.map_err(|e| format!("曲库初始化失败: {e}"))?;
|
||||||
|
app.manage(lib);
|
||||||
|
app.manage(PlayerManager::new());
|
||||||
|
|
||||||
|
// M2 飞牛曲库:加载连接/token 并同步运行期(代理按需惰性启动)
|
||||||
|
let feiniu = FeiniuManager::new(&data);
|
||||||
|
feiniu.sync_runtime();
|
||||||
|
app.manage(feiniu);
|
||||||
|
// M4 UAC:DAC 接入状态(fd→libusb 桥)
|
||||||
|
app.manage(uac::UacManager::new());
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
greet,
|
||||||
|
remote_pair,
|
||||||
|
remote_get_device,
|
||||||
|
remote_get_token,
|
||||||
|
remote_update_addr,
|
||||||
|
remote_forget,
|
||||||
|
library_scan,
|
||||||
|
library_list,
|
||||||
|
library_groups,
|
||||||
|
feiniu_get_state,
|
||||||
|
feiniu_save_connection,
|
||||||
|
feiniu_delete_connection,
|
||||||
|
feiniu_set_active,
|
||||||
|
feiniu_login,
|
||||||
|
feiniu_logout,
|
||||||
|
feiniu_list_tracks,
|
||||||
|
feiniu_lyric,
|
||||||
|
feiniu_media_prefix,
|
||||||
|
player_get_state,
|
||||||
|
player_set_queue,
|
||||||
|
player_add_queue,
|
||||||
|
player_next,
|
||||||
|
player_ended,
|
||||||
|
player_prev,
|
||||||
|
player_jump,
|
||||||
|
player_set_mode,
|
||||||
|
player_clear,
|
||||||
|
uac_open,
|
||||||
|
uac_status,
|
||||||
|
uac_close,
|
||||||
|
uac_enumerate,
|
||||||
|
uac_play,
|
||||||
|
uac_stop,
|
||||||
|
uac_set_paused,
|
||||||
|
uac_set_volume
|
||||||
|
])
|
||||||
|
.run(tauri::generate_context!())
|
||||||
|
.expect("error while running tauri application");
|
||||||
|
}
|
||||||
@@ -0,0 +1,475 @@
|
|||||||
|
//! 本地曲库(M1-c,PLAN §3.3):扫描 → lofty 元数据/内嵌封面 → SQLite 索引。
|
||||||
|
//!
|
||||||
|
//! 权限前提:`READ_MEDIA_AUDIO`(spike 真机实证:授予后 Rust 直接路径
|
||||||
|
//! walkdir 枚举/读取全部可用,见 PLAN §3.3);默认扫描根为共享存储
|
||||||
|
//! Music / Download(SAF 无目录选择器、Android/data 他应用私有目录不可达
|
||||||
|
//! 是已知边界——见 PLAN §3.3 注意事项)。
|
||||||
|
//!
|
||||||
|
//! 扫描在 `spawn_blocking` 中执行,进度经 `lfm-library-progress` 事件推送
|
||||||
|
//! (每 200 个文件一次 + 收尾一次)。
|
||||||
|
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::Mutex;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use lofty::file::{AudioFile, TaggedFileExt};
|
||||||
|
use lofty::tag::Accessor;
|
||||||
|
use rusqlite::{Connection, params};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tauri::{AppHandle, Emitter, Manager};
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
/// 与 native-audio(ExoPlayer/AVPlayer)兼容的常见音频格式(M1 能力清单)
|
||||||
|
const AUDIO_EXTS: [&str; 6] = ["mp3", "flac", "m4a", "aac", "ogg", "wav"];
|
||||||
|
|
||||||
|
/// 加密/DRM 格式标记:文件名含这些(`.kgm.flac` 双扩展或 `.ncm` 等结尾)一律跳过,
|
||||||
|
/// 它们无法被 lofty/symphonia/ExoPlayer 解码(M1 酷狗 kgm 实证)
|
||||||
|
const ENCRYPTED_MARKS: [&str; 12] = [
|
||||||
|
"kgm", "kgma", "nkg", "kge", "vpr", "mflac", "mgg", "mmp4", "ncm", "qmc0", "qmc2", "qmc3",
|
||||||
|
];
|
||||||
|
|
||||||
|
/// 录音目录路径段:通话/社交录音不是"曲库"(2026-09-26 用户实测:937/938 首全是录音)
|
||||||
|
const RECORDING_DIR_MARKS: [&str; 6] = [
|
||||||
|
"recordings",
|
||||||
|
"sound_recorder",
|
||||||
|
"call",
|
||||||
|
"通话录音",
|
||||||
|
"录音",
|
||||||
|
"audio_recorder",
|
||||||
|
];
|
||||||
|
|
||||||
|
/// 该路径是否应被扫描跳过
|
||||||
|
fn is_excluded(path: &std::path::Path) -> bool {
|
||||||
|
let Some(name) = path.file_name().map(|s| s.to_string_lossy().to_lowercase()) else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
// 加密格式(双扩展如 .kgm.flac 或结尾 .kgm/.ncm)
|
||||||
|
if ENCRYPTED_MARKS.iter().any(|m| name.contains(&format!(".{m}"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 录音目录(任一路径段命中)
|
||||||
|
let lower = path.to_string_lossy().to_lowercase();
|
||||||
|
if RECORDING_DIR_MARKS
|
||||||
|
.iter()
|
||||||
|
.any(|m| lower.contains(&format!("/{m}/")) || lower.starts_with(&format!("{m}/")))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 默认扫描根(spike 结论的共享存储直读路径;Atie/音乐 为用户实际曲库目录,
|
||||||
|
/// 2026-09-26 用户反馈"扫不到真音乐"——根目录未覆盖所致,非权限问题)
|
||||||
|
const DEFAULT_ROOTS: [&str; 3] = [
|
||||||
|
"/storage/emulated/0/Music",
|
||||||
|
"/storage/emulated/0/Download",
|
||||||
|
"/storage/emulated/0/Atie/音乐",
|
||||||
|
];
|
||||||
|
|
||||||
|
/// 扫描进度事件(前端 listen)
|
||||||
|
pub const PROGRESS_EVENT: &str = "lfm-library-progress";
|
||||||
|
|
||||||
|
/// 内嵌封面提取上限(防超大图拖垮库)
|
||||||
|
const MAX_COVER_BYTES: usize = 2 * 1024 * 1024;
|
||||||
|
|
||||||
|
/// 曲目(serde camelCase ↔ TS `Track`,与 `src/lib/player-types.ts` 互指)
|
||||||
|
/// `nas=true` 时 `path`/`cover_path` 为本机流代理 URL(飞牛曲库 M2),
|
||||||
|
/// 与本地绝对路径同字段语义——player 编排层无需区分来源。
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Track {
|
||||||
|
pub id: String,
|
||||||
|
pub title: String,
|
||||||
|
pub artist: String,
|
||||||
|
pub album: String,
|
||||||
|
pub duration_sec: f64,
|
||||||
|
pub path: String,
|
||||||
|
pub cover_path: Option<String>,
|
||||||
|
/// false=本地扫描文件,true=飞牛 NAS(feiniu/mod.rs map_track)
|
||||||
|
#[serde(default)]
|
||||||
|
pub nas: bool,
|
||||||
|
/// 源格式(NAS 取 `audioSpec.format`,如 flac/dsf/dff/mp3;本地为 None)。
|
||||||
|
/// 前端按白名单拦截不支持格式(ExoPlayer 无法解码 DSD 等,PLAN §3.3 能力边界)
|
||||||
|
#[serde(default)]
|
||||||
|
pub fmt: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 扫描结果(命令返回值;过程进度走事件)
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct ScanResult {
|
||||||
|
/// 本轮遍历到的音频文件数
|
||||||
|
pub scanned: u32,
|
||||||
|
/// 新入库 / 元数据或封面更新 / 未变化
|
||||||
|
pub added: u32,
|
||||||
|
pub updated: u32,
|
||||||
|
pub unchanged: u32,
|
||||||
|
/// 库内总数(收尾时统计)
|
||||||
|
pub total: u32,
|
||||||
|
pub elapsed_ms: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 分组条目(专辑/歌手视图)
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct TrackGroup {
|
||||||
|
/// 分组键:专辑名或歌手名(空串由前端显示为"未知")
|
||||||
|
pub key: String,
|
||||||
|
/// 附属信息:专辑组 = 主要歌手;歌手组 = 空
|
||||||
|
pub sub: String,
|
||||||
|
pub count: u32,
|
||||||
|
pub cover_path: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 进度事件负载
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct ScanProgress {
|
||||||
|
pub scanned: u32,
|
||||||
|
pub added: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LibraryManager {
|
||||||
|
conn: Mutex<Connection>,
|
||||||
|
covers_dir: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_id(path: &str) -> String {
|
||||||
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||||
|
path.hash(&mut h);
|
||||||
|
format!("{:016x}", h.finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mtime_of(meta: &std::fs::Metadata) -> i64 {
|
||||||
|
meta.modified()
|
||||||
|
.ok()
|
||||||
|
.and_then(|t| t.duration_since(SystemTime::UNIX_EPOCH).ok())
|
||||||
|
.map(|d| d.as_secs() as i64)
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LibraryManager {
|
||||||
|
pub fn open(app_data: &Path) -> Result<Self, String> {
|
||||||
|
let db_dir = app_data.join("library");
|
||||||
|
let covers_dir = app_data.join("covers");
|
||||||
|
std::fs::create_dir_all(&db_dir).map_err(|e| format!("建库目录失败: {e}"))?;
|
||||||
|
std::fs::create_dir_all(&covers_dir).map_err(|e| format!("建封面目录失败: {e}"))?;
|
||||||
|
let conn = Connection::open(db_dir.join("library.db"))
|
||||||
|
.map_err(|e| format!("打开曲库数据库失败: {e}"))?;
|
||||||
|
conn.execute_batch(
|
||||||
|
"PRAGMA journal_mode=WAL;
|
||||||
|
CREATE TABLE IF NOT EXISTS tracks (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
path TEXT NOT NULL UNIQUE,
|
||||||
|
title TEXT NOT NULL DEFAULT '',
|
||||||
|
artist TEXT NOT NULL DEFAULT '',
|
||||||
|
album TEXT NOT NULL DEFAULT '',
|
||||||
|
duration_sec REAL NOT NULL DEFAULT 0,
|
||||||
|
mtime INTEGER NOT NULL DEFAULT 0,
|
||||||
|
size INTEGER NOT NULL DEFAULT 0,
|
||||||
|
cover_path TEXT
|
||||||
|
);",
|
||||||
|
)
|
||||||
|
.map_err(|e| format!("初始化曲库表失败: {e}"))?;
|
||||||
|
Ok(Self {
|
||||||
|
conn: Mutex::new(conn),
|
||||||
|
covers_dir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 扫描(增量:mtime+size 未变则跳过;消失的文件从库中移除)。
|
||||||
|
/// `roots` 为空 → 用 [`DEFAULT_ROOTS`]。阻塞实现,调用方放 blocking 线程。
|
||||||
|
pub fn scan(&self, roots: &[String], app: &AppHandle) -> Result<ScanResult, String> {
|
||||||
|
let roots: Vec<PathBuf> = if roots.is_empty() {
|
||||||
|
DEFAULT_ROOTS.iter().map(PathBuf::from).collect()
|
||||||
|
} else {
|
||||||
|
roots.iter().map(PathBuf::from).collect()
|
||||||
|
};
|
||||||
|
let t0 = std::time::Instant::now();
|
||||||
|
|
||||||
|
// 现有行:path → (mtime, size)
|
||||||
|
let existing: HashMap<String, (i64, i64)> = {
|
||||||
|
let conn = self.conn.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let mut stmt = conn
|
||||||
|
.prepare("SELECT path, mtime, size FROM tracks")
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
let rows = stmt
|
||||||
|
.query_map([], |r| {
|
||||||
|
Ok((r.get::<_, String>(0)?, r.get::<_, i64>(1)?, r.get::<_, i64>(2)?))
|
||||||
|
})
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
let mut m = HashMap::new();
|
||||||
|
for row in rows.flatten() {
|
||||||
|
m.insert(row.0, (row.1, row.2));
|
||||||
|
}
|
||||||
|
m
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut scanned: u32 = 0;
|
||||||
|
let mut added: u32 = 0;
|
||||||
|
let mut updated: u32 = 0;
|
||||||
|
let mut unchanged: u32 = 0;
|
||||||
|
let mut seen: HashSet<String> = HashSet::new();
|
||||||
|
|
||||||
|
for root in &roots {
|
||||||
|
if !root.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for entry in WalkDir::new(root).into_iter().filter_map(Result::ok) {
|
||||||
|
if !entry.file_type().is_file() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let path = entry.path();
|
||||||
|
let ext_ok = path
|
||||||
|
.extension()
|
||||||
|
.map(|e| AUDIO_EXTS.contains(&e.to_string_lossy().to_lowercase().as_str()))
|
||||||
|
.unwrap_or(false);
|
||||||
|
if !ext_ok || is_excluded(path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
scanned += 1;
|
||||||
|
let path_str = path.to_string_lossy().to_string();
|
||||||
|
seen.insert(path_str.clone());
|
||||||
|
|
||||||
|
let Ok(meta) = entry.metadata() else { continue };
|
||||||
|
let mtime = mtime_of(&meta);
|
||||||
|
let size = meta.len() as i64;
|
||||||
|
|
||||||
|
if let Some((em, es)) = existing.get(&path_str) {
|
||||||
|
if *em == mtime && *es == size {
|
||||||
|
unchanged += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let is_new = !existing.contains_key(&path_str);
|
||||||
|
match self.index_file(path, &path_str, mtime, size) {
|
||||||
|
Ok(_) => {
|
||||||
|
if is_new {
|
||||||
|
added += 1;
|
||||||
|
} else {
|
||||||
|
updated += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// 单文件失败不中断整轮(损坏文件/无权限)
|
||||||
|
println!("[library] 索引失败 {path_str}: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if scanned % 200 == 0 {
|
||||||
|
let _ = app.emit(
|
||||||
|
PROGRESS_EVENT,
|
||||||
|
ScanProgress {
|
||||||
|
scanned,
|
||||||
|
added: added + updated,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理已消失文件(仅限本轮扫描根下的路径)
|
||||||
|
{
|
||||||
|
let conn = self.conn.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let stale: Vec<String> = existing
|
||||||
|
.keys()
|
||||||
|
.filter(|p| {
|
||||||
|
!seen.contains(*p)
|
||||||
|
&& roots.iter().any(|r| {
|
||||||
|
p.starts_with(&r.to_string_lossy().to_string())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
for chunk in stale.chunks(200) {
|
||||||
|
let placeholders = vec!["?"; chunk.len()].join(",");
|
||||||
|
let sql = format!("DELETE FROM tracks WHERE path IN ({placeholders})");
|
||||||
|
conn.execute(&sql, rusqlite::params_from_iter(chunk.iter()))
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let total: u32 = {
|
||||||
|
let conn = self.conn.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
conn.query_row("SELECT COUNT(*) FROM tracks", [], |r| r.get(0))
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = ScanResult {
|
||||||
|
scanned,
|
||||||
|
added,
|
||||||
|
updated,
|
||||||
|
unchanged,
|
||||||
|
total,
|
||||||
|
elapsed_ms: t0.elapsed().as_millis() as u64,
|
||||||
|
};
|
||||||
|
let _ = app.emit(PROGRESS_EVENT, ScanProgress { scanned, added: added + updated });
|
||||||
|
println!(
|
||||||
|
"[library] 扫描完成: 遍历 {scanned},新增 {added},更新 {updated},未变 {unchanged},库内 {total},耗时 {}ms",
|
||||||
|
result.elapsed_ms
|
||||||
|
);
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 单文件入库/更新(读元数据 + 提取内嵌封面到 covers/)
|
||||||
|
fn index_file(
|
||||||
|
&self,
|
||||||
|
path: &Path,
|
||||||
|
path_str: &str,
|
||||||
|
mtime: i64,
|
||||||
|
size: i64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let stem = path
|
||||||
|
.file_stem()
|
||||||
|
.map(|s| s.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_else(|| "未知曲目".to_string());
|
||||||
|
let mut title = stem.clone();
|
||||||
|
let mut artist = String::new();
|
||||||
|
let mut album = String::new();
|
||||||
|
let mut duration = 0.0f64;
|
||||||
|
let mut cover_path: Option<String> = None;
|
||||||
|
|
||||||
|
if let Ok(tagged) = lofty::read_from_path(path) {
|
||||||
|
if let Some(tag) = tagged.primary_tag().or_else(|| tagged.first_tag()) {
|
||||||
|
if let Some(v) = tag.title().filter(|s| !s.trim().is_empty()) {
|
||||||
|
title = v.trim().to_string();
|
||||||
|
}
|
||||||
|
if let Some(v) = tag.artist().filter(|s| !s.trim().is_empty()) {
|
||||||
|
artist = v.trim().to_string();
|
||||||
|
}
|
||||||
|
if let Some(v) = tag.album().filter(|s| !s.trim().is_empty()) {
|
||||||
|
album = v.trim().to_string();
|
||||||
|
}
|
||||||
|
if let Some(pic) = tag.pictures().first() {
|
||||||
|
let data = pic.data();
|
||||||
|
if !data.is_empty() && data.len() <= MAX_COVER_BYTES {
|
||||||
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||||
|
data.hash(&mut h);
|
||||||
|
let ext = match pic.mime_type().map(|m| m.to_string()).as_deref() {
|
||||||
|
Some("image/png") => "png",
|
||||||
|
Some("image/webp") => "webp",
|
||||||
|
_ => "jpg",
|
||||||
|
};
|
||||||
|
let file = self.covers_dir.join(format!("{:016x}.{ext}", h.finish()));
|
||||||
|
if !file.exists() {
|
||||||
|
std::fs::write(&file, data).map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
cover_path = Some(file.to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let secs = tagged.properties().duration().as_secs_f64();
|
||||||
|
if secs > 0.0 {
|
||||||
|
duration = secs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = file_id(path_str);
|
||||||
|
let conn = self.conn.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO tracks (id, path, title, artist, album, duration_sec, mtime, size, cover_path)
|
||||||
|
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)
|
||||||
|
ON CONFLICT(path) DO UPDATE SET
|
||||||
|
id=excluded.id, title=excluded.title, artist=excluded.artist,
|
||||||
|
album=excluded.album, duration_sec=excluded.duration_sec,
|
||||||
|
mtime=excluded.mtime, size=excluded.size, cover_path=excluded.cover_path",
|
||||||
|
params![id, path_str, title, artist, album, duration, mtime, size, cover_path],
|
||||||
|
)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 全量曲目(sort: title | album | artist,默认 title)
|
||||||
|
pub fn list(&self, sort: &str) -> Result<Vec<Track>, String> {
|
||||||
|
let order = match sort {
|
||||||
|
"album" => "album COLLATE NOCASE, title COLLATE NOCASE",
|
||||||
|
"artist" => "artist COLLATE NOCASE, title COLLATE NOCASE",
|
||||||
|
_ => "title COLLATE NOCASE",
|
||||||
|
};
|
||||||
|
let sql = format!(
|
||||||
|
"SELECT id, title, artist, album, duration_sec, path, cover_path FROM tracks ORDER BY {order}"
|
||||||
|
);
|
||||||
|
let conn = self.conn.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let mut stmt = conn.prepare(&sql).map_err(|e| e.to_string())?;
|
||||||
|
let rows = stmt
|
||||||
|
.query_map([], |r| {
|
||||||
|
Ok(Track {
|
||||||
|
id: r.get(0)?,
|
||||||
|
title: r.get(1)?,
|
||||||
|
artist: r.get(2)?,
|
||||||
|
album: r.get(3)?,
|
||||||
|
duration_sec: r.get(4)?,
|
||||||
|
path: r.get(5)?,
|
||||||
|
cover_path: r.get(6)?,
|
||||||
|
nas: false,
|
||||||
|
fmt: None,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
Ok(rows.flatten().collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 分组(kind: album | artist)
|
||||||
|
pub fn groups(&self, kind: &str) -> Result<Vec<TrackGroup>, String> {
|
||||||
|
let sql = match kind {
|
||||||
|
"artist" => "SELECT artist AS k, '' AS sub, COUNT(DISTINCT album) AS c, MAX(cover_path) AS cv
|
||||||
|
FROM tracks GROUP BY artist COLLATE NOCASE ORDER BY artist COLLATE NOCASE",
|
||||||
|
_ => "SELECT album AS k, MIN(artist) AS sub, COUNT(*) AS c, MAX(cover_path) AS cv
|
||||||
|
FROM tracks GROUP BY album COLLATE NOCASE ORDER BY album COLLATE NOCASE",
|
||||||
|
};
|
||||||
|
let conn = self.conn.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let mut stmt = conn.prepare(sql).map_err(|e| e.to_string())?;
|
||||||
|
let rows = stmt
|
||||||
|
.query_map([], |r| {
|
||||||
|
Ok(TrackGroup {
|
||||||
|
key: r.get(0)?,
|
||||||
|
sub: r.get(1)?,
|
||||||
|
count: r.get(2)?,
|
||||||
|
cover_path: r.get(3)?,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
Ok(rows.flatten().collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 扫描根列表(前端展示用;与 DEFAULT_ROOTS 一致,M1 不做自定义根 UI)
|
||||||
|
#[allow(dead_code)] // 预留:自定义扫描根 UI
|
||||||
|
pub fn default_roots() -> Vec<String> {
|
||||||
|
DEFAULT_ROOTS.iter().map(|s| s.to_string()).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Tauri 命令
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// 扫描曲库(阻塞在后台线程;进度走 `lfm-library-progress` 事件)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_scan(app: AppHandle, roots: Option<Vec<String>>) -> Result<ScanResult, String> {
|
||||||
|
let roots = roots.unwrap_or_default();
|
||||||
|
let app2 = app.clone();
|
||||||
|
tauri::async_runtime::spawn_blocking(move || {
|
||||||
|
let mgr = app2.state::<LibraryManager>();
|
||||||
|
mgr.scan(&roots, &app2)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("扫描任务异常: {e}"))?
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 全量列表(sort: title | album | artist)
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn library_list(
|
||||||
|
app: AppHandle,
|
||||||
|
sort: Option<String>,
|
||||||
|
) -> Result<Vec<Track>, String> {
|
||||||
|
app.state::<LibraryManager>()
|
||||||
|
.list(&sort.unwrap_or_else(|| "title".into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 分组(kind: album | artist)
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn library_groups(app: AppHandle, kind: String) -> Result<Vec<TrackGroup>, String> {
|
||||||
|
app.state::<LibraryManager>().groups(&kind)
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
lfmusic_lib::run()
|
||||||
|
}
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
//! 播放编排(M1-c,PLAN §6 `player/`):队列 + 播放模式的**真源**。
|
||||||
|
//!
|
||||||
|
//! 分工(PLAN §3.1 / audio.ts 能力边界清单):`tauri-plugin-native-audio`
|
||||||
|
//! 无队列概念,原语执行在前端——前端拿到本层返回的 `source` 后调
|
||||||
|
//! `setSource/play`;本层只做"下一首是谁"的决策。所有命令**返回最新
|
||||||
|
//! [`PlayerQueueState`]**,前端以返回值刷新镜像,无额外事件。
|
||||||
|
//!
|
||||||
|
//! 曲目结束时前端调 `player_ended`(= 自动 next),返回 None 表示播完停止。
|
||||||
|
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use rand::Rng;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::library::Track;
|
||||||
|
|
||||||
|
/// 播放模式(↔ TS `PlayMode`)
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub enum PlayMode {
|
||||||
|
/// 顺序:播到队尾停止
|
||||||
|
#[default]
|
||||||
|
Sequence,
|
||||||
|
/// 循环:列表循环
|
||||||
|
Loop,
|
||||||
|
/// 随机:每次取随机下一首
|
||||||
|
Shuffle,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 队列状态(↔ TS `PlayerQueueState`)
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct PlayerQueueState {
|
||||||
|
pub tracks: Vec<Track>,
|
||||||
|
/// 当前下标;-1 = 无曲目或已播完
|
||||||
|
pub index: i64,
|
||||||
|
pub mode: PlayMode,
|
||||||
|
/// 当前可播源(本地绝对路径;index 无效时 None)
|
||||||
|
pub source: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Inner {
|
||||||
|
tracks: Vec<Track>,
|
||||||
|
index: i64,
|
||||||
|
mode: PlayMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PlayerManager {
|
||||||
|
inner: Mutex<Inner>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PlayerManager {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn state_of(inner: &Inner) -> PlayerQueueState {
|
||||||
|
let source = if inner.index >= 0 {
|
||||||
|
inner
|
||||||
|
.tracks
|
||||||
|
.get(inner.index as usize)
|
||||||
|
.map(|t| t.path.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
PlayerQueueState {
|
||||||
|
tracks: inner.tracks.clone(),
|
||||||
|
index: inner.index,
|
||||||
|
mode: inner.mode,
|
||||||
|
source,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerManager {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
inner: Mutex::new(Inner {
|
||||||
|
tracks: Vec::new(),
|
||||||
|
index: -1,
|
||||||
|
mode: PlayMode::Sequence,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with<F>(&self, f: F) -> PlayerQueueState
|
||||||
|
where
|
||||||
|
F: FnOnce(&mut Inner),
|
||||||
|
{
|
||||||
|
let mut g = self.inner.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
f(&mut g);
|
||||||
|
state_of(&g)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random_index(len: usize, current: i64) -> i64 {
|
||||||
|
if len <= 1 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
loop {
|
||||||
|
let pick = rng.gen_range(0..len as i64);
|
||||||
|
if pick != current {
|
||||||
|
return pick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 整列替换并从 `start_index` 开始
|
||||||
|
pub fn set_queue(&self, tracks: Vec<Track>, start_index: i64) -> PlayerQueueState {
|
||||||
|
self.with(|g| {
|
||||||
|
g.tracks = tracks;
|
||||||
|
g.index = if g.tracks.is_empty() {
|
||||||
|
-1
|
||||||
|
} else {
|
||||||
|
start_index.clamp(0, g.tracks.len() as i64 - 1)
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 追加到队尾;空队列或"播完停止"状态下追加 → 自动从第一首开始
|
||||||
|
/// (播完后追加从头播,行为简单可预期;随机模式下用户可再点下一首)
|
||||||
|
pub fn add_queue(&self, more: Vec<Track>) -> PlayerQueueState {
|
||||||
|
self.with(|g| {
|
||||||
|
g.tracks.extend(more);
|
||||||
|
if g.index < 0 && !g.tracks.is_empty() {
|
||||||
|
g.index = 0;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 下一首。`auto=true` 为曲终自动推进(Sequence 播完 → 停,index=-1)。
|
||||||
|
pub fn next(&self, auto: bool) -> PlayerQueueState {
|
||||||
|
self.with(|g| {
|
||||||
|
let len = g.tracks.len() as i64;
|
||||||
|
if len == 0 {
|
||||||
|
g.index = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if g.index < 0 {
|
||||||
|
// 未开始 或 已播完:手动 → 从头/随机;自动播完保持停止
|
||||||
|
if auto && g.mode == PlayMode::Sequence {
|
||||||
|
g.index = -1;
|
||||||
|
} else if g.mode == PlayMode::Shuffle {
|
||||||
|
g.index = Self::random_index(len as usize, -1);
|
||||||
|
} else {
|
||||||
|
g.index = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g.index = match g.mode {
|
||||||
|
PlayMode::Shuffle => Self::random_index(len as usize, g.index),
|
||||||
|
PlayMode::Loop => (g.index + 1) % len,
|
||||||
|
PlayMode::Sequence => {
|
||||||
|
let n = g.index + 1;
|
||||||
|
if n >= len {
|
||||||
|
if auto {
|
||||||
|
-1 // 顺序播完停止(队列保留,前端隐藏迷你条)
|
||||||
|
} else {
|
||||||
|
0 // 手动下一首回绕
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prev(&self) -> PlayerQueueState {
|
||||||
|
self.with(|g| {
|
||||||
|
let len = g.tracks.len() as i64;
|
||||||
|
if len == 0 {
|
||||||
|
g.index = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g.index = if g.mode == PlayMode::Shuffle {
|
||||||
|
Self::random_index(len as usize, g.index)
|
||||||
|
} else if g.index <= 0 {
|
||||||
|
len - 1
|
||||||
|
} else {
|
||||||
|
g.index - 1
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn jump(&self, index: i64) -> PlayerQueueState {
|
||||||
|
self.with(|g| {
|
||||||
|
if (0..g.tracks.len() as i64).contains(&index) {
|
||||||
|
g.index = index;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_mode(&self, mode: PlayMode) -> PlayerQueueState {
|
||||||
|
self.with(|g| g.mode = mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear(&self) -> PlayerQueueState {
|
||||||
|
self.with(|g| {
|
||||||
|
g.tracks.clear();
|
||||||
|
g.index = -1;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 曲目自然播完(= 自动 next;由前端 ended 状态触发)
|
||||||
|
pub fn ended(&self) -> PlayerQueueState {
|
||||||
|
self.next(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn state(&self) -> PlayerQueueState {
|
||||||
|
state_of(&self.inner.lock().unwrap_or_else(|e| e.into_inner()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Tauri 命令(全部返回最新队列状态)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
use tauri::{AppHandle, Manager};
|
||||||
|
|
||||||
|
fn mgr(app: &AppHandle) -> tauri::State<'_, PlayerManager> {
|
||||||
|
app.state::<PlayerManager>()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_get_state(app: AppHandle) -> PlayerQueueState {
|
||||||
|
mgr(&app).state()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_set_queue(app: AppHandle, tracks: Vec<Track>, start_index: i64) -> PlayerQueueState {
|
||||||
|
mgr(&app).set_queue(tracks, start_index)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_add_queue(app: AppHandle, tracks: Vec<Track>) -> PlayerQueueState {
|
||||||
|
mgr(&app).add_queue(tracks)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_next(app: AppHandle) -> PlayerQueueState {
|
||||||
|
mgr(&app).next(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_ended(app: AppHandle) -> PlayerQueueState {
|
||||||
|
mgr(&app).ended()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_prev(app: AppHandle) -> PlayerQueueState {
|
||||||
|
mgr(&app).prev()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_jump(app: AppHandle, index: i64) -> PlayerQueueState {
|
||||||
|
mgr(&app).jump(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_set_mode(app: AppHandle, mode: PlayMode) -> PlayerQueueState {
|
||||||
|
mgr(&app).set_mode(mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn player_clear(app: AppHandle) -> PlayerQueueState {
|
||||||
|
mgr(&app).clear()
|
||||||
|
}
|
||||||
@@ -0,0 +1,274 @@
|
|||||||
|
//! 手机遥控客户端——Rust 侧(LFMusic PLAN §5 / M3)。
|
||||||
|
//!
|
||||||
|
//! 职责边界(对齐计划 §0 判断 5 与 §5.1):
|
||||||
|
//! - **beacon 监听**:bind `:26123` 收 Thing 的 3s UDP 广播 → 事件转发前端;
|
||||||
|
//! - **配对**:`POST /pair` 在 Rust 侧执行(绕开 WebView 对局域网地址的 CORS 限制),
|
||||||
|
//! 成功后 token 落本机应用私有文件;
|
||||||
|
//! - **WS 不在这里**:连接由前端 WebView 原生 `WebSocket` 持有,`hello.token` 经
|
||||||
|
//! [`remote_get_token`] 读出后仅驻内存。
|
||||||
|
//!
|
||||||
|
//! token 存储说明:P0 存应用私有目录 `remote_device.json`(仅 root/备份可读,
|
||||||
|
//! 与计划接受的"局域网明文传输"威胁模型同级);**M2 实测 keyring/Keystore 后替换**
|
||||||
|
//! (LFMusic PLAN §4 连接管理既有安排),存储接口已按此隔离。
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tauri::{AppHandle, Emitter, Manager};
|
||||||
|
|
||||||
|
/// beacon 事件名(前端 `listen` 同名)。
|
||||||
|
pub const BEACON_EVENT: &str = "lfm-remote-beacon";
|
||||||
|
/// Thing 端 beacon 端口(MUSIC_REMOTE_PLAN §3.3)。
|
||||||
|
const BEACON_PORT: u16 = 26123;
|
||||||
|
|
||||||
|
/// beacon 负载(镜像 Thing `discovery.rs::BeaconPayload`,camelCase)。
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct RemoteBeacon {
|
||||||
|
pub device_id: String,
|
||||||
|
pub name: String,
|
||||||
|
pub port: u16,
|
||||||
|
pub proto_ver: u32,
|
||||||
|
pub addrs: Vec<String>,
|
||||||
|
/// 发包方 IP:连接地址优先用它(多网卡时按路由回包最准,§5.1 地址优先级)
|
||||||
|
pub from_ip: String,
|
||||||
|
/// 本机收包时刻(Unix 毫秒);前端据此判在线(9s = 3 个周期)
|
||||||
|
pub at_ms: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 已配对设备(单设备 P0;多电脑为 P2)。
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct PairedDevice {
|
||||||
|
pub device_id: String,
|
||||||
|
pub name: String,
|
||||||
|
pub ip: String,
|
||||||
|
pub port: u16,
|
||||||
|
pub token: String,
|
||||||
|
pub paired_at_ms: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Thing `/pair` 的原始 beacon JSON(仅解析用)。
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct BeaconRaw {
|
||||||
|
service: String,
|
||||||
|
device_id: String,
|
||||||
|
name: String,
|
||||||
|
port: u16,
|
||||||
|
proto_ver: u32,
|
||||||
|
#[serde(default)]
|
||||||
|
addrs: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn now_ms() -> i64 {
|
||||||
|
SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_millis() as i64)
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn device_path(app: &AppHandle) -> Result<PathBuf, String> {
|
||||||
|
app.path()
|
||||||
|
.app_data_dir()
|
||||||
|
.map(|d| d.join("remote_device.json"))
|
||||||
|
.map_err(|e| format!("取应用数据目录失败: {e}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_device(app: &AppHandle) -> Option<PairedDevice> {
|
||||||
|
let path = device_path(app).ok()?;
|
||||||
|
let text = std::fs::read_to_string(path).ok()?;
|
||||||
|
serde_json::from_str(&text).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save_device(app: &AppHandle, dev: &PairedDevice) -> Result<(), String> {
|
||||||
|
let path = device_path(app)?;
|
||||||
|
let text = serde_json::to_string_pretty(dev).map_err(|e| format!("序列化失败: {e}"))?;
|
||||||
|
std::fs::write(&path, text).map_err(|e| format!("写入配对信息失败: {e}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 启动 beacon 监听线程(应用级常驻;绑定失败只记日志,不阻断启动)。
|
||||||
|
pub fn spawn_beacon(app: AppHandle) {
|
||||||
|
let _ = std::thread::Builder::new()
|
||||||
|
.name("lfm-beacon".to_string())
|
||||||
|
.spawn(move || {
|
||||||
|
let sock = match std::net::UdpSocket::bind(("0.0.0.0", BEACON_PORT)) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
println!("[remote] beacon 绑定 :{BEACON_PORT} 失败: {e}(发现不可用)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// 接收超时让线程可被 EINTR/错误唤醒后继续(应用生命周期内不退出)
|
||||||
|
let _ = sock.set_read_timeout(Some(Duration::from_secs(1)));
|
||||||
|
println!("[remote] beacon 监听中 :{BEACON_PORT}");
|
||||||
|
let mut buf = [0u8; 4096];
|
||||||
|
loop {
|
||||||
|
let (n, from) = match sock.recv_from(&mut buf) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(_) => continue, // 超时/瞬时错误:继续听
|
||||||
|
};
|
||||||
|
let Ok(text) = std::str::from_utf8(&buf[..n]) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let Ok(raw) = serde_json::from_str::<BeaconRaw>(text) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if raw.service != "thing-music" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let beacon = RemoteBeacon {
|
||||||
|
device_id: raw.device_id,
|
||||||
|
name: raw.name,
|
||||||
|
port: raw.port,
|
||||||
|
proto_ver: raw.proto_ver,
|
||||||
|
addrs: raw.addrs,
|
||||||
|
from_ip: from.ip().to_string(),
|
||||||
|
at_ms: now_ms(),
|
||||||
|
};
|
||||||
|
let _ = app.emit(BEACON_EVENT, beacon);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Tauri 命令
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// 配对结果(token 不回传——前端随后用 [`remote_get_token`] 按需取)。
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct PairResult {
|
||||||
|
pub device_id: String,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 配对:`POST http://{ip}:{port}/pair`(Rust 侧执行,绕开 WebView CORS)。
|
||||||
|
/// 错误信息透传 Thing 返回体的 `error` 字段(配对码错误/过期/限速等)。
|
||||||
|
///
|
||||||
|
/// - `device_name`:**本机**名称(发给 Thing 记入其设备表)
|
||||||
|
/// - `peer_device_id` / `peer_name`:**对端电脑**的 beacon 标识与名称——
|
||||||
|
/// 本地必须存**电脑 id**(PLAN §5.1「deviceId → ip/port 记忆」语义),
|
||||||
|
/// 才能与 beacon 按 deviceId 关联;`/pair` 响应里的 deviceId 是 Thing
|
||||||
|
/// 给手机分配的行 id,对手机端关联无用,不落盘。
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn remote_pair(
|
||||||
|
app: AppHandle,
|
||||||
|
ip: String,
|
||||||
|
port: u16,
|
||||||
|
pairing_code: String,
|
||||||
|
device_name: String,
|
||||||
|
peer_device_id: String,
|
||||||
|
peer_name: String,
|
||||||
|
) -> Result<PairResult, String> {
|
||||||
|
let url = format!("http://{ip}:{port}/pair");
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(8))
|
||||||
|
.build()
|
||||||
|
.map_err(|e| format!("创建 HTTP 客户端失败: {e}"))?;
|
||||||
|
let resp = client
|
||||||
|
.post(&url)
|
||||||
|
.json(&serde_json::json!({
|
||||||
|
"pairingCode": pairing_code.trim(),
|
||||||
|
"deviceName": device_name,
|
||||||
|
}))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("连接 Thing 失败({url}): {e}"))?;
|
||||||
|
|
||||||
|
let status = resp.status();
|
||||||
|
if !status.is_success() {
|
||||||
|
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||||
|
let msg = body
|
||||||
|
.get("error")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.unwrap_or_else(|| format!("配对失败(HTTP {})", status.as_u16()));
|
||||||
|
return Err(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct PairResp {
|
||||||
|
token: String,
|
||||||
|
#[serde(default)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
device_id: String,
|
||||||
|
}
|
||||||
|
let r: PairResp = resp
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("解析配对响应失败: {e}"))?;
|
||||||
|
|
||||||
|
let dev = PairedDevice {
|
||||||
|
device_id: if peer_device_id.trim().is_empty() {
|
||||||
|
r.device_id
|
||||||
|
} else {
|
||||||
|
peer_device_id
|
||||||
|
},
|
||||||
|
name: if peer_name.trim().is_empty() {
|
||||||
|
device_name.clone()
|
||||||
|
} else {
|
||||||
|
peer_name
|
||||||
|
},
|
||||||
|
ip,
|
||||||
|
port,
|
||||||
|
token: r.token,
|
||||||
|
paired_at_ms: now_ms(),
|
||||||
|
};
|
||||||
|
save_device(&app, &dev)?;
|
||||||
|
println!("[remote] 配对成功: {}({}:{})", dev.device_id, dev.ip, dev.port);
|
||||||
|
Ok(PairResult {
|
||||||
|
device_id: dev.device_id.clone(),
|
||||||
|
name: dev.name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 已配对设备(**token 置空**——前端要 hello 令牌走 [`remote_get_token`])。
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn remote_get_device(app: AppHandle) -> Option<PairedDevice> {
|
||||||
|
load_device(&app).map(|mut d| {
|
||||||
|
d.token = String::new();
|
||||||
|
d
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 读取设备 token(仅供 WS `hello`,仅驻前端内存;不落前端存储)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn remote_get_token(app: AppHandle, device_id: String) -> Result<String, String> {
|
||||||
|
let dev = load_device(&app).ok_or_else(|| "尚未配对任何设备".to_string())?;
|
||||||
|
if dev.device_id != device_id {
|
||||||
|
return Err("设备不匹配,请重新配对".into());
|
||||||
|
}
|
||||||
|
if dev.token.is_empty() {
|
||||||
|
return Err("token 缺失,请重新配对".into());
|
||||||
|
}
|
||||||
|
Ok(dev.token)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// beacon 地址刷新(§5.1 地址优先级:当次 beacon 覆盖记忆值,应对 DHCP 换 IP)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn remote_update_addr(app: AppHandle, ip: String, port: u16) -> Result<(), String> {
|
||||||
|
let Some(mut dev) = load_device(&app) else {
|
||||||
|
return Ok(()); // 未配对时无需记录
|
||||||
|
};
|
||||||
|
if dev.ip == ip && dev.port == port {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
println!("[remote] 设备地址更新: {} → {}:{port}", dev.ip, ip);
|
||||||
|
dev.ip = ip;
|
||||||
|
dev.port = port;
|
||||||
|
save_device(&app, &dev)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 忘记设备(清本地配对信息;Thing 侧设备表需在其设置页吊销)。
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn remote_forget(app: AppHandle) -> Result<(), String> {
|
||||||
|
let path = device_path(&app)?;
|
||||||
|
if path.exists() {
|
||||||
|
std::fs::remove_file(&path).map_err(|e| format!("删除配对信息失败: {e}"))?;
|
||||||
|
}
|
||||||
|
println!("[remote] 已清除本地配对信息");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,522 @@
|
|||||||
|
//! UAC 2.0 描述符解析(M4,设计参考 Flick `rust/src/uac2/`,MIT)。
|
||||||
|
//!
|
||||||
|
//! 输入:rusb `DeviceHandle`(Android 上来自 Kotlin fd 经
|
||||||
|
//! `Context::open_device_with_fd`(libusb `wrap_sys_device`)包装,桌面为直接枚举)。
|
||||||
|
//! 输出:`DeviceCaps` —— 控制接口/UAC 版本/clock 实体(GET_RANGE 实测采样率)/
|
||||||
|
//! 流接口 alt setting 矩阵(通道/位深/端点/同步类型/最大包长)。
|
||||||
|
//!
|
||||||
|
//! 关键协议事实(UAC2 spec 4.7/5.2,Flick android_direct.rs 印证):
|
||||||
|
//! - UAC2 的采样率不在 format 描述符里,而在 Clock Source 实体上,
|
||||||
|
//! 经 GET_RANGE(CS_SAM_FREQ_CONTROL) 查询、SET_CUR 设置;
|
||||||
|
//! 流接口 AS_GENERAL.bTerminalLink → Output Terminal(bSourceID/bCSourceID) → Clock Source。
|
||||||
|
//! - UAC1 的采样率在 FORMAT_TYPE(Type I) 描述符里(离散表或连续三元组),
|
||||||
|
//! 设置走 SET_CUR 到 iso 端点(无 clock 实体)。
|
||||||
|
//! - 同步类型看 iso 端点 bmAttributes bit5:4(0=同步 1=异步 2=自适应)。
|
||||||
|
|
||||||
|
use rusb::{DeviceHandle, UsbContext};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
const USB_CLASS_AUDIO: u8 = 0x01;
|
||||||
|
const SUBCLASS_CONTROL: u8 = 0x01;
|
||||||
|
const SUBCLASS_STREAMING: u8 = 0x02;
|
||||||
|
|
||||||
|
// class-specific 描述符子类型
|
||||||
|
const CS_INTERFACE: u8 = 0x24;
|
||||||
|
const CS_HEADER: u8 = 0x01;
|
||||||
|
const CS_INPUT_TERMINAL: u8 = 0x02;
|
||||||
|
const CS_OUTPUT_TERMINAL: u8 = 0x03;
|
||||||
|
const CS_FEATURE_UNIT: u8 = 0x06;
|
||||||
|
const CS_CLOCK_SOURCE: u8 = 0x0a;
|
||||||
|
const CS_AS_GENERAL: u8 = 0x01;
|
||||||
|
const CS_FORMAT_TYPE: u8 = 0x02;
|
||||||
|
|
||||||
|
const FORMAT_TYPE_I: u8 = 0x01;
|
||||||
|
|
||||||
|
// UAC2 clock 控制请求
|
||||||
|
const REQ_CUR: u8 = 0x01;
|
||||||
|
const REQ_RANGE: u8 = 0x02;
|
||||||
|
const CS_SAM_FREQ_CONTROL: u16 = 0x0100;
|
||||||
|
|
||||||
|
/// 采样率集合:离散列表 + 连续区间(UAC1 格式描述符与 UAC2 GET_RANGE 共用)
|
||||||
|
#[derive(Serialize, Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct RateSpec {
|
||||||
|
pub discrete: Vec<u32>,
|
||||||
|
/// (min, max, res)
|
||||||
|
pub ranges: Vec<(u32, u32, u32)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RateSpec {
|
||||||
|
pub fn supports(&self, rate: u32) -> bool {
|
||||||
|
self.discrete.contains(&rate)
|
||||||
|
|| self
|
||||||
|
.ranges
|
||||||
|
.iter()
|
||||||
|
.any(|&(min, max, res)| rate >= min && rate <= max && (res == 0 || (rate - min) % res == 0))
|
||||||
|
}
|
||||||
|
#[allow(dead_code)] // 预留:RateSpec 构造校验
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.discrete.is_empty() && self.ranges.is_empty()
|
||||||
|
}
|
||||||
|
pub fn max_rate(&self) -> Option<u32> {
|
||||||
|
self.discrete
|
||||||
|
.iter()
|
||||||
|
.chain(self.ranges.iter().map(|r| &r.1))
|
||||||
|
.copied()
|
||||||
|
.max()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone, Debug)]
|
||||||
|
pub struct ClockEntity {
|
||||||
|
pub entity_id: u8,
|
||||||
|
/// 实测 GET_RANGE 结果(UAC2);UAC1 恒空
|
||||||
|
pub rates: RateSpec,
|
||||||
|
/// GET_CUR 当前值(如设备在位且可读)
|
||||||
|
pub current_rate: Option<u32>,
|
||||||
|
pub error: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone, Debug)]
|
||||||
|
pub struct AltSettingCaps {
|
||||||
|
pub interface_number: u8,
|
||||||
|
pub alt_setting: u8,
|
||||||
|
pub terminal_link: Option<u8>,
|
||||||
|
/// 经 terminal_link 链解析到的 Clock Source 实体(仅 UAC2)
|
||||||
|
pub clock_entity: Option<u8>,
|
||||||
|
pub format_tag: u32,
|
||||||
|
pub channels: u8,
|
||||||
|
/// PCM 子槽字节数(2=16bit 载体,3=24bit,4=32bit;iso 打包要用)
|
||||||
|
pub subslot_size: u8,
|
||||||
|
pub bit_depths: Vec<u8>,
|
||||||
|
/// UAC1:格式描述符自带的;UAC2:来自其 clock 实体 GET_RANGE(查不到则空)
|
||||||
|
pub sample_rates: RateSpec,
|
||||||
|
pub endpoint_address: u8,
|
||||||
|
pub max_packet_bytes: u16,
|
||||||
|
/// asynchronous / adaptive / synchronous
|
||||||
|
pub sync_type: String,
|
||||||
|
pub synch_address: u8,
|
||||||
|
/// 诊断用:该 alt setting 的 class-specific extra 原始字节(hex,截断 96B)
|
||||||
|
pub extra_hex: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone, Debug)]
|
||||||
|
pub struct DeviceCaps {
|
||||||
|
/// 从 bcdADC 推断:1=UAC1,2=UAC2,0=未知
|
||||||
|
pub uac_version: u8,
|
||||||
|
pub control_interface: Option<u8>,
|
||||||
|
pub has_feature_unit_volume: bool,
|
||||||
|
/// Feature Unit 实体 id(硬件音量/静音控制目标)
|
||||||
|
pub feature_unit: Option<u8>,
|
||||||
|
/// 诊断用:控制接口 class-specific extra 原始字节(hex,截断 128B)
|
||||||
|
pub control_extra_hex: String,
|
||||||
|
pub clock_entities: Vec<ClockEntity>,
|
||||||
|
pub streaming_alts: Vec<AltSettingCaps>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type DescResult<T> = Result<T, String>;
|
||||||
|
|
||||||
|
/// 把 class-specific extra 字节串按 bLength 切成单条描述符
|
||||||
|
fn split_extra(extra: &[u8]) -> Vec<&[u8]> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
let mut i = 0usize;
|
||||||
|
while i + 2 <= extra.len() {
|
||||||
|
let len = extra[i] as usize;
|
||||||
|
if len < 3 || i + len > extra.len() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
out.push(&extra[i..i + len]);
|
||||||
|
i += len;
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
fn le16(b: &[u8], off: usize) -> Option<u16> {
|
||||||
|
b.get(off..off + 2).map(|s| u16::from_le_bytes([s[0], s[1]]))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn le24(b: &[u8], off: usize) -> Option<u32> {
|
||||||
|
b.get(off..off + 3)
|
||||||
|
.map(|s| u32::from_le_bytes([s[0], s[1], s[2], 0]))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn le32(b: &[u8], off: usize) -> Option<u32> {
|
||||||
|
b.get(off..off + 4).map(|s| u32::from_le_bytes([s[0], s[1], s[2], s[3]]))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// UAC2 GET_RANGE(CS_SAM_FREQ_CONTROL):返回子区间列表
|
||||||
|
/// (与 Flick get_sampling_frequency_ranges 同参数口径:512B 缓冲、1s 超时)
|
||||||
|
fn clock_get_ranges<C: UsbContext>(
|
||||||
|
handle: &DeviceHandle<C>,
|
||||||
|
control_if: u8,
|
||||||
|
entity: u8,
|
||||||
|
) -> Result<(RateSpec, Option<u32>), String> {
|
||||||
|
let mut buf = [0u8; 512];
|
||||||
|
let windex = ((entity as u16) << 8) | control_if as u16;
|
||||||
|
let n = handle
|
||||||
|
.read_control(0xa1, REQ_RANGE, CS_SAM_FREQ_CONTROL, windex, &mut buf, std::time::Duration::from_secs(1))
|
||||||
|
.map_err(|e| format!("GET_RANGE: {e:?}"))?;
|
||||||
|
if n < 2 {
|
||||||
|
return Err(format!("GET_RANGE 响应过短: {n}"));
|
||||||
|
}
|
||||||
|
let count = le16(&buf, 0).ok_or("GET_RANGE 解包失败")? as usize;
|
||||||
|
let expect = 2 + count * 12;
|
||||||
|
if n < expect {
|
||||||
|
return Err(format!("GET_RANGE 声明 {count} 子区间但响应仅 {n} 字节"));
|
||||||
|
}
|
||||||
|
let mut rates = RateSpec::default();
|
||||||
|
for i in 0..count {
|
||||||
|
let off = 2 + i * 12;
|
||||||
|
let min = le32(&buf, off).ok_or("区间解包失败")?;
|
||||||
|
let max = le32(&buf, off + 4).ok_or("区间解包失败")?;
|
||||||
|
let res = le32(&buf, off + 8).unwrap_or(0);
|
||||||
|
if min == max || (res == 0 && max > min) {
|
||||||
|
rates.discrete.push(min);
|
||||||
|
if max != min {
|
||||||
|
rates.discrete.push(max);
|
||||||
|
}
|
||||||
|
} else if max > min {
|
||||||
|
rates.ranges.push((min, max, res));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rates.discrete.sort_unstable();
|
||||||
|
rates.discrete.dedup();
|
||||||
|
|
||||||
|
let current = handle
|
||||||
|
.read_control(0xa1, REQ_CUR, CS_SAM_FREQ_CONTROL, windex, &mut buf[..4], std::time::Duration::from_secs(1))
|
||||||
|
.ok()
|
||||||
|
.filter(|&n| n == 4)
|
||||||
|
.map(|_n| u32::from_le_bytes([buf[0], buf[1], buf[2], buf[3]]));
|
||||||
|
|
||||||
|
Ok((rates, current))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 解析整只设备的 UAC 结构(纯描述符,不含 clock 实测)。
|
||||||
|
/// clock GET_RANGE 需在 claim 控制接口后调用 `probe_clocks` 填充。
|
||||||
|
pub fn parse_structure<C: UsbContext>(handle: &DeviceHandle<C>) -> DescResult<DeviceCaps> {
|
||||||
|
let config = handle
|
||||||
|
.device()
|
||||||
|
.active_config_descriptor()
|
||||||
|
.map_err(|e| format!("active_config_descriptor 失败: {e}"))?;
|
||||||
|
|
||||||
|
let mut uac_version = 0u8;
|
||||||
|
let mut control_interface: Option<u8> = None;
|
||||||
|
let mut control_extra_hex = String::new();
|
||||||
|
let mut clock_entity_ids: Vec<u8> = Vec::new();
|
||||||
|
// input terminal: id -> (csource_id, nr_channels)
|
||||||
|
let mut in_terms: Vec<(u8, Option<u8>, u8)> = Vec::new();
|
||||||
|
// output terminal: id -> (source_id, csource_id)
|
||||||
|
let mut out_terms: Vec<(u8, Option<u8>, Option<u8>)> = Vec::new();
|
||||||
|
let mut has_feature_unit_volume = false;
|
||||||
|
let mut feature_unit: Option<u8> = None;
|
||||||
|
|
||||||
|
// ---- 第一遍:控制接口(header/terminal/clock 实体) ----
|
||||||
|
for iface in config.interfaces() {
|
||||||
|
for setting in iface.descriptors() {
|
||||||
|
if setting.class_code() != USB_CLASS_AUDIO || setting.sub_class_code() != SUBCLASS_CONTROL {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
control_interface = Some(setting.interface_number());
|
||||||
|
let extra = setting.extra();
|
||||||
|
control_extra_hex = hex_truncate(extra, 128);
|
||||||
|
if extra.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for d in split_extra(extra) {
|
||||||
|
if d[1] != CS_INTERFACE {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
match d[2] {
|
||||||
|
CS_HEADER => {
|
||||||
|
if let Some(bcd) = le16(d, 3) {
|
||||||
|
uac_version = match bcd {
|
||||||
|
0x0100..=0x01ff => 1,
|
||||||
|
0x0200..=0x02ff => 2,
|
||||||
|
0x0300..=0x03ff => 3,
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CS_INPUT_TERMINAL => {
|
||||||
|
// UAC2: bID(3) wTerminalType(4) bAssoc(6) bCSourceID(7) bNrChannels(8)
|
||||||
|
let id = *d.get(3).unwrap_or(&0);
|
||||||
|
let csource = d.get(7).copied().filter(|&v| v != 0);
|
||||||
|
let channels = d.get(8).copied().unwrap_or(0);
|
||||||
|
in_terms.push((id, csource, channels));
|
||||||
|
if let Some(cid) = csource {
|
||||||
|
if !clock_entity_ids.contains(&cid) {
|
||||||
|
clock_entity_ids.push(cid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CS_OUTPUT_TERMINAL => {
|
||||||
|
let id = *d.get(3).unwrap_or(&0);
|
||||||
|
let source = d.get(7).copied();
|
||||||
|
// UAC2 bCSourceID 在 offset 8;UAC1 无此字段(len<9)
|
||||||
|
let csource = if d.len() > 8 { d.get(8).copied().filter(|&v| v != 0) } else { None };
|
||||||
|
out_terms.push((id, source, csource));
|
||||||
|
if let Some(cid) = csource {
|
||||||
|
if !clock_entity_ids.contains(&cid) {
|
||||||
|
clock_entity_ids.push(cid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CS_CLOCK_SOURCE => {
|
||||||
|
let id = *d.get(3).unwrap_or(&0);
|
||||||
|
if !clock_entity_ids.contains(&id) {
|
||||||
|
clock_entity_ids.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CS_FEATURE_UNIT => {
|
||||||
|
let id = *d.get(3).unwrap_or(&0);
|
||||||
|
// bmControls 里 bit0(mute)/bit1(volume) 任一非零即视作有音量控制
|
||||||
|
// (粗判即可,M4 音量阶段再细化)
|
||||||
|
if d.len() > 6 && d[5..].iter().any(|&b| b & 0b11 != 0) {
|
||||||
|
has_feature_unit_volume = true;
|
||||||
|
feature_unit = Some(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- clock 实体登记(UAC2;UAC1 无 clock 实体)——实测在 probe_clocks ----
|
||||||
|
let clock_entities: Vec<ClockEntity> = clock_entity_ids
|
||||||
|
.iter()
|
||||||
|
.map(|&id| ClockEntity { entity_id: id, rates: RateSpec::default(), current_rate: None, error: None })
|
||||||
|
.collect();
|
||||||
|
let clock_by_id = |id: u8| clock_entities.iter().find(|c| c.entity_id == id).cloned();
|
||||||
|
|
||||||
|
// ---- 第二遍:流接口 alt settings ----
|
||||||
|
let mut streaming_alts: Vec<AltSettingCaps> = Vec::new();
|
||||||
|
for iface in config.interfaces() {
|
||||||
|
for setting in iface.descriptors() {
|
||||||
|
if setting.class_code() != USB_CLASS_AUDIO || setting.sub_class_code() != SUBCLASS_STREAMING {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let if_num = setting.interface_number();
|
||||||
|
let alt = setting.setting_number();
|
||||||
|
if alt == 0 {
|
||||||
|
continue; // 零带宽设置
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut terminal_link = None;
|
||||||
|
let mut format_tag = 0u32;
|
||||||
|
let mut channels = 0u8;
|
||||||
|
let mut subslot_size = 0u8;
|
||||||
|
let mut bit_depths: Vec<u8> = Vec::new();
|
||||||
|
let mut uac1_rates = RateSpec::default();
|
||||||
|
|
||||||
|
let extra = setting.extra();
|
||||||
|
let extra_hex = hex_truncate(extra, 96);
|
||||||
|
for d in split_extra(extra) {
|
||||||
|
if d[1] != CS_INTERFACE {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
match d[2] {
|
||||||
|
CS_AS_GENERAL => {
|
||||||
|
terminal_link = d.get(3).copied();
|
||||||
|
// UAC1 在 [5..6] 放 wFormatTag;UAC2 无此字段(格式看 FORMAT_TYPE),
|
||||||
|
// 部分 FIFO 固件又按 UAC1 摆——Type I 时统一视作 PCM
|
||||||
|
format_tag = le16(d, 5).unwrap_or(0) as u32;
|
||||||
|
}
|
||||||
|
CS_FORMAT_TYPE if d.get(3) == Some(&FORMAT_TYPE_I) => {
|
||||||
|
// 标准布局(≥7B):bNrChannels(4) bSubslotSize(5) bBitResolution(6)
|
||||||
|
// 非标 6B(部分 XMOS/ES9018 固件缺 bNrChannels):
|
||||||
|
// bSubslotSize(4) bBitResolution(5)
|
||||||
|
if d.len() >= 7 {
|
||||||
|
channels = d[4];
|
||||||
|
subslot_size = d[5];
|
||||||
|
let bits = d[6];
|
||||||
|
if bits > 0 && !bit_depths.contains(&bits) {
|
||||||
|
bit_depths.push(bits);
|
||||||
|
}
|
||||||
|
} else if d.len() >= 6 {
|
||||||
|
subslot_size = d[4];
|
||||||
|
let bits = d[5];
|
||||||
|
if bits > 0 && !bit_depths.contains(&bits) {
|
||||||
|
bit_depths.push(bits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if uac_version >= 2 {
|
||||||
|
format_tag = 1; // PCM
|
||||||
|
}
|
||||||
|
// UAC1 才在格式描述符里带采样率
|
||||||
|
if uac_version == 1 && d.len() > 7 {
|
||||||
|
let freq_type = d[7];
|
||||||
|
if freq_type == 0 {
|
||||||
|
// 连续:dMin(8) dMax(11) dRes(14)
|
||||||
|
if let (Some(min), Some(max), Some(res)) = (le24(d, 8), le24(d, 11), le24(d, 14)) {
|
||||||
|
uac1_rates.ranges.push((min, max, res));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i in 0..freq_type as usize {
|
||||||
|
if let Some(r) = le24(d, 8 + i * 3) {
|
||||||
|
uac1_rates.discrete.push(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// iso 端点(取第一个 OUT iso)
|
||||||
|
let ep = setting
|
||||||
|
.endpoint_descriptors()
|
||||||
|
.find(|e| e.transfer_type() == rusb::TransferType::Isochronous);
|
||||||
|
let (ep_addr, max_packet, sync, synch_addr) = match ep {
|
||||||
|
Some(e) => {
|
||||||
|
let sync = match e.sync_type() {
|
||||||
|
rusb::SyncType::NoSync => "synchronous",
|
||||||
|
rusb::SyncType::Asynchronous => "asynchronous",
|
||||||
|
rusb::SyncType::Adaptive => "adaptive",
|
||||||
|
rusb::SyncType::Synchronous => "synchronous",
|
||||||
|
};
|
||||||
|
let synch = e.extra().and_then(split_extra_peek_synch).unwrap_or(0);
|
||||||
|
(e.address(), e.max_packet_size(), sync, synch)
|
||||||
|
}
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
// clock 解析:bTerminalLink 一般指向 Input Terminal(USB streaming),
|
||||||
|
// 也可能有固件直接指 clock/Output Terminal——沿 IT/OT 链走到 Clock Source
|
||||||
|
let mut clock_entity = None;
|
||||||
|
let mut rates = uac1_rates.clone();
|
||||||
|
if uac_version >= 2 {
|
||||||
|
if let Some(link) = terminal_link {
|
||||||
|
clock_entity = resolve_clock(link, &clock_entity_ids, &in_terms, &out_terms);
|
||||||
|
}
|
||||||
|
if let Some(ce) = clock_entity.and_then(clock_by_id) {
|
||||||
|
if ce.error.is_none() {
|
||||||
|
rates = ce.rates.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 通道数:format 描述符缺 bNrChannels(非标固件)时从 Input Terminal 回填
|
||||||
|
if channels == 0 {
|
||||||
|
if let Some(link) = terminal_link {
|
||||||
|
if let Some(&(_, _, ch)) = in_terms.iter().find(|(id, _, _)| *id == link) {
|
||||||
|
channels = ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
streaming_alts.push(AltSettingCaps {
|
||||||
|
interface_number: if_num,
|
||||||
|
alt_setting: alt,
|
||||||
|
terminal_link,
|
||||||
|
clock_entity,
|
||||||
|
format_tag,
|
||||||
|
channels,
|
||||||
|
subslot_size,
|
||||||
|
bit_depths,
|
||||||
|
sample_rates: rates,
|
||||||
|
endpoint_address: ep_addr,
|
||||||
|
max_packet_bytes: max_packet,
|
||||||
|
sync_type: sync.to_string(),
|
||||||
|
synch_address: synch_addr,
|
||||||
|
extra_hex,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(DeviceCaps {
|
||||||
|
uac_version,
|
||||||
|
control_interface,
|
||||||
|
has_feature_unit_volume,
|
||||||
|
feature_unit,
|
||||||
|
control_extra_hex,
|
||||||
|
clock_entities,
|
||||||
|
streaming_alts,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hex_truncate(bytes: &[u8], max: usize) -> String {
|
||||||
|
bytes
|
||||||
|
.iter()
|
||||||
|
.take(max)
|
||||||
|
.map(|b| format!("{b:02x}"))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 沿 UAC2 实体链(IT/OT/FeatureUnit)找到 Clock Source 实体 id(深度限制防环)
|
||||||
|
fn resolve_clock(
|
||||||
|
start: u8,
|
||||||
|
clock_ids: &[u8],
|
||||||
|
in_terms: &[(u8, Option<u8>, u8)],
|
||||||
|
out_terms: &[(u8, Option<u8>, Option<u8>)],
|
||||||
|
) -> Option<u8> {
|
||||||
|
if clock_ids.contains(&start) {
|
||||||
|
return Some(start);
|
||||||
|
}
|
||||||
|
let mut current = start;
|
||||||
|
for _ in 0..8 {
|
||||||
|
if let Some(&(_, Some(cid), _)) = in_terms.iter().find(|(id, _, _)| *id == current) {
|
||||||
|
if clock_ids.contains(&cid) {
|
||||||
|
return Some(cid);
|
||||||
|
}
|
||||||
|
current = cid;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(&(_, _, Some(cid))) = out_terms.iter().find(|(id, _, _)| *id == current) {
|
||||||
|
if clock_ids.contains(&cid) {
|
||||||
|
return Some(cid);
|
||||||
|
}
|
||||||
|
current = cid;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(&(_, Some(src), None)) = out_terms.iter().find(|(id, _, _)| *id == current) {
|
||||||
|
current = src;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 在 claim 控制接口**之后**调用:GET_RANGE 实测各 clock 实体采样率,
|
||||||
|
/// 并把结果回填到引用它的流接口 alt settings(UAC2)。
|
||||||
|
pub fn probe_clocks<C: UsbContext>(handle: &DeviceHandle<C>, caps: &mut DeviceCaps) {
|
||||||
|
if caps.uac_version < 2 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Some(cif) = caps.control_interface else { return };
|
||||||
|
for ce in caps.clock_entities.iter_mut() {
|
||||||
|
match clock_get_ranges(handle, cif, ce.entity_id) {
|
||||||
|
Ok((rates, current)) => {
|
||||||
|
ce.rates = rates;
|
||||||
|
ce.current_rate = current;
|
||||||
|
ce.error = None;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
ce.rates = RateSpec::default();
|
||||||
|
ce.current_rate = None;
|
||||||
|
ce.error = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 回填 alt settings
|
||||||
|
for alt in caps.streaming_alts.iter_mut() {
|
||||||
|
if let Some(id) = alt.clock_entity {
|
||||||
|
if let Some(ce) = caps.clock_entities.iter().find(|c| c.entity_id == id) {
|
||||||
|
if ce.error.is_none() {
|
||||||
|
alt.sample_rates = ce.rates.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 从 class-specific endpoint 描述符(subtype=1)读 bSynchAddress
|
||||||
|
fn split_extra_peek_synch(extra: &[u8]) -> Option<u8> {
|
||||||
|
for d in split_extra(extra) {
|
||||||
|
if d[1] == CS_INTERFACE && d[2] == 1 && d.len() > 5 {
|
||||||
|
return Some(d[5]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
@@ -0,0 +1,375 @@
|
|||||||
|
//! M4:UAC 播放(Android USB DAC bit-perfect 直出,PLAN §3.4)。
|
||||||
|
//!
|
||||||
|
//! 阶段一(已完成):设备接入 + 能力枚举。
|
||||||
|
//! - Kotlin `UsbPlugin`(gen/android/.../UsbPlugin.kt)完成 UsbManager 授权与
|
||||||
|
//! openDevice,把 `fileDescriptor` 交给前端 → 本模块 `uac_open`。
|
||||||
|
//! - Rust 侧 `dup` fd → `Context::open_device_with_fd`(libusb
|
||||||
|
//! `wrap_sys_device`,Flick 同款桥接)→ 解析 UAC 描述符 → GET_RANGE 实测
|
||||||
|
//! clock 采样率 → 返回能力矩阵。
|
||||||
|
//!
|
||||||
|
//! 阶段二(本次):iso 传输引擎 + symphonia 解码(engine.rs / player.rs),
|
||||||
|
//! `uac_play`/`uac_stop`/`uac_set_volume`;播放期间设备从 manager 移出
|
||||||
|
//! (接口被引擎独占 claim),停止后需重新「接入」。
|
||||||
|
//!
|
||||||
|
//! 设计参考:Flick `rust/src/uac2/android_direct.rs`(MIT,PLAN 参考项目)。
|
||||||
|
|
||||||
|
mod desc;
|
||||||
|
mod engine;
|
||||||
|
mod player;
|
||||||
|
|
||||||
|
use rusb::{Context, DeviceHandle, UsbContext};
|
||||||
|
use serde::Serialize;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
// app.path() 需要 Manager trait(android fd 桥里写诊断文件用)
|
||||||
|
use tauri::Manager;
|
||||||
|
|
||||||
|
pub use desc::{AltSettingCaps, DeviceCaps};
|
||||||
|
pub use player::UacPlayState;
|
||||||
|
|
||||||
|
/// libusb「禁用设备发现」只需执行一次(全局选项,须在 Context::new 前调用;
|
||||||
|
/// Android 上 fd 包装模式必须禁用枚举扫描,Flick `prepare_direct_usb_libusb` 同款)
|
||||||
|
static DISCOVERY_DISABLED: std::sync::Once = std::sync::Once::new();
|
||||||
|
|
||||||
|
fn prepare_libusb_direct() {
|
||||||
|
DISCOVERY_DISABLED.call_once(|| {
|
||||||
|
// rusb::disable_device_discovery 仅 unix(libusb 全局选项,须在 Context::new 前);
|
||||||
|
// Windows 桌面走正常枚举,无需禁用。
|
||||||
|
#[cfg(unix)]
|
||||||
|
if let Err(e) = rusb::disable_device_discovery() {
|
||||||
|
eprintln!("[uac] disable_device_discovery 失败: {e}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone, Debug)]
|
||||||
|
pub struct UacDeviceInfo {
|
||||||
|
pub fd: i32,
|
||||||
|
pub vendor_id: u16,
|
||||||
|
pub product_id: u16,
|
||||||
|
pub product: String,
|
||||||
|
pub manufacturer: String,
|
||||||
|
pub serial: Option<String>,
|
||||||
|
pub device_name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone, Debug)]
|
||||||
|
pub struct UacReport {
|
||||||
|
pub info: UacDeviceInfo,
|
||||||
|
pub caps: DeviceCaps,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ActiveDevice {
|
||||||
|
/// 共享句柄:播放引擎与音量等同步控制请求并发使用(libusb 文档保证
|
||||||
|
/// 同步控制传输与其他线程 handle_events 并发安全)
|
||||||
|
handle: Arc<DeviceHandle<Context>>,
|
||||||
|
/// libusb context 必须比 handle 活得久
|
||||||
|
_context: Arc<Context>,
|
||||||
|
info: UacDeviceInfo,
|
||||||
|
caps: DeviceCaps,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct UacManager {
|
||||||
|
device: Mutex<Option<ActiveDevice>>,
|
||||||
|
player: Mutex<player::PlayerCore>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UacManager {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
device: Mutex::new(None),
|
||||||
|
player: Mutex::new(player::PlayerCore::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn player(&self) -> std::sync::MutexGuard<'_, player::PlayerCore> {
|
||||||
|
self.player.lock().unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 打开(注册)USB DAC:前端从 `plugin:usb|open_device` 拿到 fd 后调用。
|
||||||
|
/// fd 已被 Kotlin 侧 `UsbDeviceConnection` 保活,此处再 dup 一份归 Rust 所有。
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_open(
|
||||||
|
app: tauri::AppHandle,
|
||||||
|
manager: tauri::State<UacManager>,
|
||||||
|
fd: i32,
|
||||||
|
vendor_id: u16,
|
||||||
|
product_id: u16,
|
||||||
|
product: String,
|
||||||
|
manufacturer: String,
|
||||||
|
serial: Option<String>,
|
||||||
|
device_name: Option<String>,
|
||||||
|
) -> Result<UacReport, String> {
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
{
|
||||||
|
open_with_fd(app, manager, fd, vendor_id, product_id, product, manufacturer, serial, device_name)
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
{
|
||||||
|
let _ = app;
|
||||||
|
let _ = manager;
|
||||||
|
let _ = fd;
|
||||||
|
let _ = vendor_id;
|
||||||
|
let _ = product_id;
|
||||||
|
let _ = product;
|
||||||
|
let _ = manufacturer;
|
||||||
|
let _ = serial;
|
||||||
|
let _ = device_name;
|
||||||
|
Err("fd 桥接仅支持 Android;桌面调试请用 uac_enumerate".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
fn open_with_fd(
|
||||||
|
app: tauri::AppHandle,
|
||||||
|
manager: tauri::State<UacManager>,
|
||||||
|
fd: i32,
|
||||||
|
vendor_id: u16,
|
||||||
|
product_id: u16,
|
||||||
|
product: String,
|
||||||
|
manufacturer: String,
|
||||||
|
serial: Option<String>,
|
||||||
|
device_name: Option<String>,
|
||||||
|
) -> Result<UacReport, String> {
|
||||||
|
if fd < 0 {
|
||||||
|
return Err(format!("无效 fd: {fd}"));
|
||||||
|
}
|
||||||
|
// 若还在播放:先停(释放接口后才能重新接入)
|
||||||
|
if manager.player().snapshot().phase != 0 {
|
||||||
|
let _ = player::stop(&app, &manager.player()); // 返回的归还数据随断开丢弃
|
||||||
|
}
|
||||||
|
prepare_libusb_direct();
|
||||||
|
let context = Arc::new(Context::new().map_err(|e| format!("libusb Context::new 失败: {e}"))?);
|
||||||
|
// SAFETY:fd 来自 Kotlin UsbDeviceConnection(框架保证合法、设备已授权)
|
||||||
|
let handle = unsafe { context.open_device_with_fd(fd) }
|
||||||
|
.map_err(|e| format!("libusb wrap fd({fd}) 失败: {e}(fd 是否仍有效?)"))?;
|
||||||
|
let handle = Arc::new(handle);
|
||||||
|
|
||||||
|
// 内核驱动占用检测/自动分离(Android 上通常无,桌面有)
|
||||||
|
let _ = handle.set_auto_detach_kernel_driver(true);
|
||||||
|
|
||||||
|
// 1. 纯描述符解析(结构)
|
||||||
|
let mut caps = desc::parse_structure(&handle).map_err(|e| format!("UAC 描述符解析失败: {e}"))?;
|
||||||
|
|
||||||
|
// 2. claim 控制接口(Flick 同款:class 请求前先 claim),失败不致命(只影响 clock 实测)
|
||||||
|
if let Some(cif) = caps.control_interface {
|
||||||
|
match handle.claim_interface(cif) {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(rusb::Error::Busy) => {} // 已由本 fd claim(重复接入场景)
|
||||||
|
Err(e) => eprintln!("[uac] claim 控制接口 {cif} 失败(clock 实测可能不可用): {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. clock GET_RANGE 实测(UAC2)并回填流接口采样率
|
||||||
|
desc::probe_clocks(&handle, &mut caps);
|
||||||
|
|
||||||
|
let info = UacDeviceInfo {
|
||||||
|
fd,
|
||||||
|
vendor_id,
|
||||||
|
product_id,
|
||||||
|
product,
|
||||||
|
manufacturer,
|
||||||
|
serial,
|
||||||
|
device_name,
|
||||||
|
};
|
||||||
|
println!(
|
||||||
|
"[uac] 设备已接入: {} (vid={:#06x} pid={:#06x}) UAC{} 流alt={} clock={}",
|
||||||
|
info.product,
|
||||||
|
info.vendor_id,
|
||||||
|
info.product_id,
|
||||||
|
caps.uac_version,
|
||||||
|
caps.streaming_alts.len(),
|
||||||
|
caps.clock_entities.len(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let report = UacReport { info: info.clone(), caps: caps.clone() };
|
||||||
|
// 诊断出口:完整报告落盘(debug 包可 `adb shell run-as music.lfeng.me cat uac_report.json`)
|
||||||
|
if let Ok(dir) = app.path().app_data_dir() {
|
||||||
|
if let Ok(json) = serde_json::to_string_pretty(&report) {
|
||||||
|
let _ = std::fs::write(dir.join("uac_report.json"), json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*manager.device.lock().map_err(|_| "UacManager 锁中毒")? = Some(ActiveDevice {
|
||||||
|
handle,
|
||||||
|
_context: context,
|
||||||
|
info,
|
||||||
|
caps: report.caps.clone(),
|
||||||
|
});
|
||||||
|
Ok(report)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 终态回收:播放结束/停止/出错后,把设备从 PlayerCore 归还 manager(重新可接入)
|
||||||
|
fn reclaim_if_finished(manager: &UacManager) {
|
||||||
|
let snap = manager.player().snapshot();
|
||||||
|
if !matches!(snap.phase, 3 | 4 | 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Ok((_, restore)) = manager.player().stop_inner() else { return };
|
||||||
|
if let Some(r) = restore {
|
||||||
|
let mut guard = match manager.device.lock() {
|
||||||
|
Ok(g) => g,
|
||||||
|
Err(_) => return,
|
||||||
|
};
|
||||||
|
if guard.is_none() {
|
||||||
|
*guard = Some(ActiveDevice {
|
||||||
|
handle: r.handle,
|
||||||
|
_context: r.context,
|
||||||
|
info: r.info,
|
||||||
|
caps: r.caps,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设备 + 播放综合状态
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_status(manager: tauri::State<UacManager>) -> Result<serde_json::Value, String> {
|
||||||
|
// 先回收终态(自然结束/出错后设备自动回到可接入状态)
|
||||||
|
reclaim_if_finished(&manager);
|
||||||
|
let dev = manager.device.lock().map_err(|_| "锁中毒")?;
|
||||||
|
let play = manager.player().snapshot();
|
||||||
|
let device = dev.as_ref().map(|d| serde_json::to_value(UacReport {
|
||||||
|
info: d.info.clone(),
|
||||||
|
caps: d.caps.clone(),
|
||||||
|
}).unwrap_or(serde_json::Value::Null));
|
||||||
|
Ok(serde_json::json!({ "device": device, "play": play }))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 断开设备(若在播放先停止);释放后尝试重挂内核驱动恢复系统音频
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_close(app: tauri::AppHandle, manager: tauri::State<UacManager>) -> Result<(), String> {
|
||||||
|
// 若在播放先停
|
||||||
|
if manager.player().snapshot().phase != 0 {
|
||||||
|
let _ = player::stop(&app, &manager.player()); // 返回的归还数据随断开丢弃
|
||||||
|
}
|
||||||
|
let dev = manager.device.lock().map_err(|_| "锁中毒")?.take();
|
||||||
|
if let Some(d) = dev {
|
||||||
|
// 未播放场景:open 时 claim 过控制接口,这里释放并重挂内核驱动,
|
||||||
|
// 让系统 USB 音频(snd-usb-audio)恢复
|
||||||
|
if let Some(cif) = d.caps.control_interface {
|
||||||
|
let _ = d.handle.release_interface(cif);
|
||||||
|
match d.handle.attach_kernel_driver(cif) {
|
||||||
|
Ok(()) => println!("[uac] 内核驱动已重挂 if{cif}(系统音频恢复)"),
|
||||||
|
Err(rusb::Error::Busy) => {}
|
||||||
|
Err(rusb::Error::NotSupported) => {}
|
||||||
|
Err(e) => println!("[uac] 重挂内核驱动 if{cif}: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 启动 UAC 播放(source = 本地文件路径 / http URL;`start_ms` = 起播位置,
|
||||||
|
/// 输出路径切换时由前端传入以保持进度)
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_play(
|
||||||
|
app: tauri::AppHandle,
|
||||||
|
manager: tauri::State<UacManager>,
|
||||||
|
source: String,
|
||||||
|
name: Option<String>,
|
||||||
|
start_ms: Option<u64>,
|
||||||
|
) -> Result<UacPlayState, String> {
|
||||||
|
let name = name.unwrap_or_else(|| {
|
||||||
|
std::path::Path::new(&source)
|
||||||
|
.file_name()
|
||||||
|
.map(|s| s.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_else(|| source.clone())
|
||||||
|
});
|
||||||
|
player::play(app, &manager.device, &manager.player(), source, name, start_ms)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止播放(设备自动归还,无需重新接入)
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_stop(app: tauri::AppHandle, manager: tauri::State<UacManager>) -> Result<UacPlayState, String> {
|
||||||
|
let (state, restore) = manager.player().stop(&app)?;
|
||||||
|
if let Some(r) = restore {
|
||||||
|
let mut guard = manager.device.lock().map_err(|_| "锁中毒")?;
|
||||||
|
if guard.is_none() {
|
||||||
|
*guard = Some(ActiveDevice {
|
||||||
|
handle: r.handle,
|
||||||
|
_context: r.context,
|
||||||
|
info: r.info,
|
||||||
|
caps: r.caps,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(state)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 暂停/恢复 UAC 播放
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_set_paused(manager: tauri::State<UacManager>, paused: bool) -> Result<(), String> {
|
||||||
|
manager.player().set_paused(paused)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 硬件音量(0.0~1.0;FU VOLUME GET_RANGE + SET_CUR;播放中/未播均可)
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_set_volume(
|
||||||
|
manager: tauri::State<UacManager>,
|
||||||
|
percent: f32,
|
||||||
|
) -> Result<i16, String> {
|
||||||
|
// 优先播放中(设备被引擎接管)
|
||||||
|
if let Some((handle, cif, fu)) =
|
||||||
|
manager.player().hardware_volume_target()
|
||||||
|
{
|
||||||
|
return engine::set_hardware_volume(&handle, cif, fu, percent);
|
||||||
|
}
|
||||||
|
let dev = manager.device.lock().map_err(|_| "锁中毒")?;
|
||||||
|
let d = dev.as_ref().ok_or("DAC 未接入")?;
|
||||||
|
let cif = d.caps.control_interface.ok_or("缺少控制接口")?;
|
||||||
|
let fu = d
|
||||||
|
.caps
|
||||||
|
.feature_unit
|
||||||
|
.ok_or("DAC 无硬件音量控制(Feature Unit)")?;
|
||||||
|
engine::set_hardware_volume(&d.handle, cif, fu, percent)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 桌面调试(M4 PLAN 首项:Windows CLI 验证 UAC2 逻辑):直接 rusb 枚举 UAC 设备。
|
||||||
|
/// 注意 Windows 下 libusb 需 WinUSB/libusb 驱动(Zadig 替换),否则枚举可见但打不开。
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn uac_enumerate() -> Result<Vec<serde_json::Value>, String> {
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
{
|
||||||
|
let context = Context::new().map_err(|e| format!("libusb Context::new 失败: {e}"))?;
|
||||||
|
let mut out = Vec::new();
|
||||||
|
for device in context.devices().map_err(|e| format!("枚举失败: {e}"))?.iter() {
|
||||||
|
let Ok(desc) = device.device_descriptor() else { continue };
|
||||||
|
let Ok(cfg) = device.active_config_descriptor() else { continue };
|
||||||
|
let mut is_uac = false;
|
||||||
|
let mut is_uac2 = false;
|
||||||
|
for iface in cfg.interfaces() {
|
||||||
|
for s in iface.descriptors() {
|
||||||
|
if s.class_code() == 0x01 {
|
||||||
|
is_uac = true;
|
||||||
|
if s.protocol_code() == 0x20 {
|
||||||
|
is_uac2 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !is_uac {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let product = device
|
||||||
|
.open()
|
||||||
|
.ok()
|
||||||
|
.and_then(|h| h.read_product_string_ascii(&desc).ok());
|
||||||
|
let manufacturer = device
|
||||||
|
.open()
|
||||||
|
.ok()
|
||||||
|
.and_then(|h| h.read_manufacturer_string_ascii(&desc).ok());
|
||||||
|
out.push(serde_json::json!({
|
||||||
|
"vendor_id": desc.vendor_id(),
|
||||||
|
"product_id": desc.product_id(),
|
||||||
|
"product": product,
|
||||||
|
"manufacturer": manufacturer,
|
||||||
|
"is_uac2": is_uac2,
|
||||||
|
"bus": device.bus_number(),
|
||||||
|
"address": device.address(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
Err("Android 上请走 plugin:usb|list_devices(经 UsbManager)".into())
|
||||||
|
}
|
||||||
@@ -0,0 +1,771 @@
|
|||||||
|
//! M4-3b:UAC 播放编排 —— symphonia 解码 → 位深保真转换 → 引擎环形缓冲。
|
||||||
|
//!
|
||||||
|
//! 位深/采样率策略(bit-perfect 优先,与 Flick `format_negotiation` 同口径):
|
||||||
|
//! - 整数解码路径(S16/S24/S32)直接移位/拷贝,不经过 f32,杜绝精度损失
|
||||||
|
//! - f32 路径(mp3/aac 等)按目标位深乘满幅
|
||||||
|
//! - alt 协商:优先「采样率支持 + 位深精确匹配」,其次 subslot ≥ 源位深的最小 alt
|
||||||
|
//! - 源采样率直出:不重采样、不强制容器宽度;DAC 不支持该速率 → 报错拒绝
|
||||||
|
//!
|
||||||
|
//! 所有权:`PlayerCore` 持有 `ActivePlayback`(EngineHandle 拥有 stop/state/ring 与
|
||||||
|
//! 共享的 Arc<DeviceHandle>);播放期间 UacManager 的设备被移出(置 None),
|
||||||
|
//! 停止/结束后用户需在输出页重新「接入」(Kotlin 侧连接仍保活,秒级完成)。
|
||||||
|
|
||||||
|
use crate::uac::engine::{self, EngineConfig, EngineHandle, EngineState};
|
||||||
|
use serde::Serialize;
|
||||||
|
use std::io::Read;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use symphonia::core::audio::{AudioBufferRef, Signal};
|
||||||
|
use symphonia::core::codecs::{DecoderOptions, CODEC_TYPE_NULL};
|
||||||
|
use symphonia::core::formats::FormatOptions;
|
||||||
|
use symphonia::core::io::MediaSourceStream;
|
||||||
|
use symphonia::core::meta::MetadataOptions;
|
||||||
|
use symphonia::core::probe::Hint;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct UacPlayState {
|
||||||
|
/// 0=idle 1=prime 2=play 3=ended 4=stopped 5=error
|
||||||
|
pub phase: u8,
|
||||||
|
pub track: String,
|
||||||
|
pub sample_rate: Option<u32>,
|
||||||
|
pub bit_depth: Option<u8>,
|
||||||
|
pub channels: Option<u8>,
|
||||||
|
pub alt_setting: Option<u8>,
|
||||||
|
pub position_ms: Option<u64>,
|
||||||
|
pub duration_ms: Option<u64>,
|
||||||
|
pub underruns: u64,
|
||||||
|
/// 反馈实测帧率/微帧 ×1000
|
||||||
|
pub fpf_milli: Option<i32>,
|
||||||
|
pub paused: bool,
|
||||||
|
pub error: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ActivePlayback {
|
||||||
|
engine: EngineHandle,
|
||||||
|
config: EngineConfig,
|
||||||
|
track: String,
|
||||||
|
duration_frames: Option<u64>,
|
||||||
|
#[allow(dead_code)] // 预留:记录输出采样率
|
||||||
|
rate: u32,
|
||||||
|
decode_join: Option<std::thread::JoinHandle<()>>,
|
||||||
|
/// 播放结束/停止后用于归还 manager(设备重新可接入)
|
||||||
|
restore: Option<RestoreInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 归还 manager 所需的设备数据
|
||||||
|
pub struct RestoreInfo {
|
||||||
|
pub handle: Arc<rusb::DeviceHandle<rusb::Context>>,
|
||||||
|
pub context: Arc<rusb::Context>,
|
||||||
|
pub info: crate::uac::UacDeviceInfo,
|
||||||
|
pub caps: crate::uac::DeviceCaps,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PlayerCore {
|
||||||
|
inner: Mutex<Option<ActivePlayback>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerCore {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { inner: Mutex::new(None) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn state_locked(
|
||||||
|
guard: &Option<ActivePlayback>,
|
||||||
|
engine_state: Option<&Arc<EngineState>>,
|
||||||
|
) -> UacPlayState {
|
||||||
|
let Some(pb) = guard else {
|
||||||
|
return UacPlayState {
|
||||||
|
phase: 0,
|
||||||
|
track: String::new(),
|
||||||
|
sample_rate: None,
|
||||||
|
bit_depth: None,
|
||||||
|
channels: None,
|
||||||
|
alt_setting: None,
|
||||||
|
position_ms: None,
|
||||||
|
duration_ms: None,
|
||||||
|
underruns: 0,
|
||||||
|
fpf_milli: None,
|
||||||
|
paused: false,
|
||||||
|
error: None,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
let es = engine_state.unwrap_or(&pb.engine.state);
|
||||||
|
let phase = es.phase.load(Ordering::Relaxed) as u8;
|
||||||
|
let position_ms = pb
|
||||||
|
.config
|
||||||
|
.sample_rate
|
||||||
|
.checked_div(1000)
|
||||||
|
.map(|per_ms| {
|
||||||
|
let f = pb
|
||||||
|
.engine
|
||||||
|
.state
|
||||||
|
.decoded_frames
|
||||||
|
.load(Ordering::Relaxed)
|
||||||
|
.min(pb.engine.state.sent_frames.load(Ordering::Relaxed));
|
||||||
|
f / per_ms as u64
|
||||||
|
});
|
||||||
|
UacPlayState {
|
||||||
|
phase,
|
||||||
|
track: pb.track.clone(),
|
||||||
|
sample_rate: Some(pb.config.sample_rate),
|
||||||
|
bit_depth: Some(pb.config.subslot_size * 8),
|
||||||
|
channels: Some(pb.config.channels),
|
||||||
|
alt_setting: Some(pb.config.alt_setting),
|
||||||
|
position_ms,
|
||||||
|
duration_ms: pb
|
||||||
|
.duration_frames
|
||||||
|
.map(|f| f * 1000 / pb.config.sample_rate as u64),
|
||||||
|
underruns: es.underruns.load(Ordering::Relaxed),
|
||||||
|
fpf_milli: Some(es.fpf_milli.load(Ordering::Relaxed)),
|
||||||
|
paused: es.paused.load(Ordering::Relaxed),
|
||||||
|
error: es.error(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn snapshot(&self) -> UacPlayState {
|
||||||
|
let guard = self.inner.lock().unwrap();
|
||||||
|
Self::state_locked(&guard, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 暂停/恢复(引擎静音包保时钟,进度冻结)
|
||||||
|
pub fn set_paused(&self, paused: bool) -> Result<(), String> {
|
||||||
|
let guard = self.inner.lock().unwrap();
|
||||||
|
let Some(pb) = guard.as_ref() else {
|
||||||
|
return Err("没有进行中的 UAC 播放".into());
|
||||||
|
};
|
||||||
|
pb.engine.state.paused.store(paused, Ordering::Relaxed);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 播放中的硬件音量控制目标(handle/control_if/feature_unit)。
|
||||||
|
/// 仅引擎存活(prime/play)时有效——结束后接口已释放,控制请求会 EIO。
|
||||||
|
pub fn hardware_volume_target(
|
||||||
|
&self,
|
||||||
|
) -> Option<(Arc<rusb::DeviceHandle<rusb::Context>>, u8, u8)> {
|
||||||
|
let guard = self.inner.lock().unwrap();
|
||||||
|
let pb = guard.as_ref()?;
|
||||||
|
let phase = pb.engine.state.phase.load(Ordering::Relaxed);
|
||||||
|
if phase != 1 && phase != 2 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let fu = pb.config.feature_unit?;
|
||||||
|
Some((pb.engine.handle.clone(), pb.config.control_interface, fu))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止播放;返回归还数据(设备重新放回 manager),不发事件
|
||||||
|
pub fn stop_inner(&self) -> Result<(UacPlayState, Option<RestoreInfo>), String> {
|
||||||
|
let mut guard = self.inner.lock().unwrap();
|
||||||
|
let Some(mut pb) = guard.take() else {
|
||||||
|
return Ok((Self::state_locked(&None, None), None));
|
||||||
|
};
|
||||||
|
pb.engine.request_stop();
|
||||||
|
if let Some(j) = pb.decode_join.take() {
|
||||||
|
let _ = j.join();
|
||||||
|
}
|
||||||
|
if let Some(j) = pb.engine.join.take() {
|
||||||
|
let _ = j.join();
|
||||||
|
}
|
||||||
|
let st = UacPlayState {
|
||||||
|
phase: 4,
|
||||||
|
track: pb.track.clone(),
|
||||||
|
sample_rate: Some(pb.config.sample_rate),
|
||||||
|
bit_depth: Some(pb.config.subslot_size * 8),
|
||||||
|
channels: Some(pb.config.channels),
|
||||||
|
alt_setting: Some(pb.config.alt_setting),
|
||||||
|
position_ms: None,
|
||||||
|
duration_ms: None,
|
||||||
|
underruns: pb.engine.state.underruns.load(Ordering::Relaxed),
|
||||||
|
fpf_milli: None,
|
||||||
|
paused: false,
|
||||||
|
error: pb.engine.state.error(),
|
||||||
|
};
|
||||||
|
drop(guard);
|
||||||
|
Ok((st, pb.restore))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止播放并发状态事件
|
||||||
|
pub fn stop(&self, app: &tauri::AppHandle) -> Result<(UacPlayState, Option<RestoreInfo>), String> {
|
||||||
|
let (st, restore) = self.stop_inner()?;
|
||||||
|
emit_state(app, &st);
|
||||||
|
Ok((st, restore))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn emit_state(app: &tauri::AppHandle, st: &UacPlayState) {
|
||||||
|
use tauri::Emitter;
|
||||||
|
let _ = app.emit("uac://state", st);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 媒体源(本地文件 / HTTP Range 流,两者都 Read+Seek 供 symphonia 使用)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct HttpSource {
|
||||||
|
url: String,
|
||||||
|
client: reqwest::blocking::Client,
|
||||||
|
pos: u64,
|
||||||
|
len: Option<u64>,
|
||||||
|
current: Option<reqwest::blocking::Response>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HttpSource {
|
||||||
|
fn new(url: &str) -> Result<Self, String> {
|
||||||
|
// **不能**用 Client::timeout:那是「整个请求含响应体」的总时限,
|
||||||
|
// 流式读一首几分钟的曲子会在 15s 处被掐断,之后每次 read 都失败
|
||||||
|
// → 解码端空转 → 环形缓冲抽干 → 播放卡死。只保留连接超时;
|
||||||
|
// 读挂死由解码端的连续 IoError 计数兜底(见 decode 循环)。
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
.connect_timeout(Duration::from_secs(15))
|
||||||
|
.build()
|
||||||
|
.map_err(|e| format!("HTTP client 构建失败: {e}"))?;
|
||||||
|
let len = client
|
||||||
|
.head(url)
|
||||||
|
.send()
|
||||||
|
.ok()
|
||||||
|
.and_then(|r| {
|
||||||
|
r.headers()
|
||||||
|
.get(reqwest::header::CONTENT_LENGTH)?
|
||||||
|
.to_str()
|
||||||
|
.ok()?
|
||||||
|
.parse::<u64>()
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
Ok(Self { url: url.to_string(), client, pos: 0, len, current: None })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_range(&mut self, start: u64) -> Result<(), String> {
|
||||||
|
let resp = self
|
||||||
|
.client
|
||||||
|
.get(&self.url)
|
||||||
|
.header(reqwest::header::RANGE, format!("bytes={start}-"))
|
||||||
|
.send()
|
||||||
|
.map_err(|e| format!("流打开失败: {e}"))?;
|
||||||
|
if !(resp.status().is_success() || resp.status().as_u16() == 206) {
|
||||||
|
return Err(format!("流打开 HTTP {}", resp.status()));
|
||||||
|
}
|
||||||
|
self.current = Some(resp);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Read for HttpSource {
|
||||||
|
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
||||||
|
if self.current.is_none() {
|
||||||
|
self.open_range(self.pos).map_err(std::io::Error::other)?;
|
||||||
|
}
|
||||||
|
let resp = self.current.as_mut().unwrap();
|
||||||
|
match resp.read(buf) {
|
||||||
|
Ok(0) => {
|
||||||
|
self.current = None;
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
Ok(n) => {
|
||||||
|
self.pos += n as u64;
|
||||||
|
Ok(n)
|
||||||
|
}
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl symphonia::core::io::MediaSource for HttpSource {
|
||||||
|
fn is_seekable(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
fn byte_len(&self) -> Option<u64> {
|
||||||
|
self.len
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::io::Seek for HttpSource {
|
||||||
|
fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> {
|
||||||
|
let target = match pos {
|
||||||
|
std::io::SeekFrom::Start(o) => o,
|
||||||
|
std::io::SeekFrom::Current(d) => (self.pos as i64 + d) as u64,
|
||||||
|
std::io::SeekFrom::End(d) => {
|
||||||
|
let len = self
|
||||||
|
.len
|
||||||
|
.ok_or_else(|| std::io::Error::other("流长度未知,无法 End seek"))?;
|
||||||
|
(len as i64 + d) as u64
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if self.current.is_none() || target != self.pos {
|
||||||
|
self.open_range(target).map_err(std::io::Error::other)?;
|
||||||
|
}
|
||||||
|
self.pos = target;
|
||||||
|
Ok(target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 位深保真转换
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
enum TargetBits {
|
||||||
|
B16,
|
||||||
|
B24,
|
||||||
|
B32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TargetBits {
|
||||||
|
fn from_subslot(subslot: u8) -> Option<Self> {
|
||||||
|
match subslot {
|
||||||
|
2 => Some(Self::B16),
|
||||||
|
3 => Some(Self::B24),
|
||||||
|
4 => Some(Self::B32),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 整数样本 → 目标位深字节(LE)。`bits_src` 为源有效位深(8/16/24/32)
|
||||||
|
fn push_sample_int(out: &mut Vec<u8>, v: i64, bits_src: u32, target: &TargetBits) {
|
||||||
|
match target {
|
||||||
|
TargetBits::B16 => {
|
||||||
|
let s = match bits_src {
|
||||||
|
8 => v << 8,
|
||||||
|
16 => v,
|
||||||
|
24 => v >> 8,
|
||||||
|
_ => v >> 16,
|
||||||
|
};
|
||||||
|
out.extend_from_slice(
|
||||||
|
&(s.clamp(i16::MIN as i64, i16::MAX as i64) as i16).to_le_bytes(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
TargetBits::B24 => {
|
||||||
|
let s = match bits_src {
|
||||||
|
8 => v << 16,
|
||||||
|
16 => v << 8,
|
||||||
|
24 => v,
|
||||||
|
_ => v >> 8,
|
||||||
|
};
|
||||||
|
let s = (s.clamp(-(1 << 23), (1 << 23) - 1) as i32) as u32;
|
||||||
|
out.push((s & 0xff) as u8);
|
||||||
|
out.push(((s >> 8) & 0xff) as u8);
|
||||||
|
out.push(((s >> 16) & 0xff) as u8);
|
||||||
|
}
|
||||||
|
TargetBits::B32 => {
|
||||||
|
let s = match bits_src {
|
||||||
|
8 => v << 24,
|
||||||
|
16 => v << 16,
|
||||||
|
24 => v << 8,
|
||||||
|
_ => v,
|
||||||
|
};
|
||||||
|
out.extend_from_slice(
|
||||||
|
&(s.clamp(i32::MIN as i64, i32::MAX as i64) as i32).to_le_bytes(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn push_sample_f32(out: &mut Vec<u8>, v: f32, target: &TargetBits) {
|
||||||
|
let v = v.clamp(-1.0, 1.0);
|
||||||
|
match target {
|
||||||
|
TargetBits::B16 => out.extend_from_slice(&((v * 32767.0) as i16).to_le_bytes()),
|
||||||
|
TargetBits::B24 => {
|
||||||
|
let s = ((v * 8388607.0) as i32) as u32;
|
||||||
|
out.push((s & 0xff) as u8);
|
||||||
|
out.push(((s >> 8) & 0xff) as u8);
|
||||||
|
out.push(((s >> 16) & 0xff) as u8);
|
||||||
|
}
|
||||||
|
TargetBits::B32 => out.extend_from_slice(&((v * 2147483647.0) as i32).to_le_bytes()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// AudioBufferRef 交错化 → 目标位深字节(整数路径不经过 f32)。
|
||||||
|
/// `out_channels` 为 DAC 端声道数:源 mono 升混为 stereo(复制),多余声道截断。
|
||||||
|
fn convert_interleaved(buf: &AudioBufferRef<'_>, target: &TargetBits, out_channels: usize) -> Vec<u8> {
|
||||||
|
use symphonia::core::audio::AudioBufferRef::*;
|
||||||
|
let frames = buf.frames() as usize;
|
||||||
|
let src_channels = buf.spec().channels.count().max(1);
|
||||||
|
let mut out = Vec::with_capacity(frames * out_channels * 4);
|
||||||
|
macro_rules! loop_int {
|
||||||
|
($get:expr, $bits:expr) => {
|
||||||
|
for f in 0..frames {
|
||||||
|
for c in 0..out_channels {
|
||||||
|
// 声道映射:超出源声道数时回绕(mono→双声道同值)
|
||||||
|
push_sample_int(&mut out, $get(f, c % src_channels) as i64, $bits, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
match buf {
|
||||||
|
U8(b) => loop_int!(|f, c| *b.chan(c).get(f).unwrap_or(&0u8), 8),
|
||||||
|
S8(b) => loop_int!(|f, c| *b.chan(c).get(f).unwrap_or(&0i8), 8),
|
||||||
|
U16(b) => loop_int!(|f, c| (*b.chan(c).get(f).unwrap_or(&0u16) as i64) - 0x8000, 16),
|
||||||
|
S16(b) => loop_int!(|f, c| *b.chan(c).get(f).unwrap_or(&0i16), 16),
|
||||||
|
U24(b) => loop_int!(|f, c| b.chan(c).get(f).copied().map(|v| symphonia::core::sample::u24::inner(v)).unwrap_or(0) - 0x800000, 24),
|
||||||
|
S24(b) => loop_int!(|f, c| b.chan(c).get(f).copied().map(|v| symphonia::core::sample::i24::inner(v)).unwrap_or(0), 24),
|
||||||
|
S32(b) => loop_int!(|f, c| *b.chan(c).get(f).unwrap_or(&0i32), 32),
|
||||||
|
U32(b) => loop_int!(|f, c| (*b.chan(c).get(f).unwrap_or(&0u32) as i64) - 0x80000000, 32),
|
||||||
|
F32(b) => {
|
||||||
|
for f in 0..frames {
|
||||||
|
for c in 0..out_channels {
|
||||||
|
push_sample_f32(&mut out, *b.chan(c % src_channels).get(f).unwrap_or(&0f32), target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
F64(b) => {
|
||||||
|
for f in 0..frames {
|
||||||
|
for c in 0..out_channels {
|
||||||
|
push_sample_f32(&mut out, *b.chan(c % src_channels).get(f).unwrap_or(&0f64) as f32, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 协商
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// 选 alt:采样率必须支持;位深精确匹配优先,其次 subslot ≥ 源位深的最小者。
|
||||||
|
/// 与 Flick `format_negotiation.rs` 同口径:按源位深选 alt,**不强制容器宽度、
|
||||||
|
/// 不强制采样率**——2026-09-26 真机实测,强制 48k+32bit 容器正是杂音根因。
|
||||||
|
fn negotiate(
|
||||||
|
caps: &crate::uac::DeviceCaps,
|
||||||
|
#[allow(dead_code)] // 预留:记录输出采样率
|
||||||
|
rate: u32,
|
||||||
|
src_bits: u32,
|
||||||
|
channels: u8,
|
||||||
|
) -> Result<(crate::uac::AltSettingCaps, u8), String> {
|
||||||
|
let candidates: Vec<&crate::uac::AltSettingCaps> = caps
|
||||||
|
.streaming_alts
|
||||||
|
.iter()
|
||||||
|
.filter(|a| a.sample_rates.supports(rate))
|
||||||
|
.collect();
|
||||||
|
if candidates.is_empty() {
|
||||||
|
let max_rate = caps
|
||||||
|
.streaming_alts
|
||||||
|
.iter()
|
||||||
|
.filter_map(|a| a.sample_rates.max_rate())
|
||||||
|
.max()
|
||||||
|
.unwrap_or(0);
|
||||||
|
return Err(format!(
|
||||||
|
"DAC 不支持 {rate}Hz(支持上限 {max_rate}Hz);UAC 路径无重采样,宁缺毋滥"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if channels > 2 {
|
||||||
|
return Err(format!("暂仅支持单声道/立体声(源 {channels} 声道)"));
|
||||||
|
}
|
||||||
|
let bits_of = |a: &crate::uac::AltSettingCaps| -> u32 {
|
||||||
|
a.bit_depths.first().copied().unwrap_or(a.subslot_size * 8) as u32
|
||||||
|
};
|
||||||
|
if let Some(a) = candidates.iter().find(|a| bits_of(a) == src_bits) {
|
||||||
|
let bits = a.bit_depths.first().copied().unwrap_or(a.subslot_size * 8);
|
||||||
|
return Ok(((*a).clone(), bits));
|
||||||
|
}
|
||||||
|
let need_subslot = src_bits.div_ceil(8) as u8;
|
||||||
|
let fallback = candidates
|
||||||
|
.iter()
|
||||||
|
.filter(|a| a.subslot_size >= need_subslot)
|
||||||
|
.min_by_key(|a| a.subslot_size)
|
||||||
|
.or_else(|| candidates.iter().max_by_key(|a| a.subslot_size))
|
||||||
|
.expect("candidates 非空");
|
||||||
|
let bits = fallback.bit_depths.first().copied().unwrap_or(fallback.subslot_size * 8);
|
||||||
|
Ok(((*fallback).clone(), bits))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 播放启动
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// 启动播放:接管 DeviceHandle(UacManager 移出置 None),协商、解码、驱动引擎。
|
||||||
|
/// `source`:本地文件路径或 http(s) URL(飞牛本机代理流直接可用)。
|
||||||
|
pub fn play(
|
||||||
|
app: tauri::AppHandle,
|
||||||
|
manager_state: &Mutex<Option<crate::uac::ActiveDevice>>,
|
||||||
|
core: &PlayerCore,
|
||||||
|
source: String,
|
||||||
|
display_name: String,
|
||||||
|
start_ms: Option<u64>,
|
||||||
|
) -> Result<UacPlayState, String> {
|
||||||
|
{
|
||||||
|
let guard = core.inner.lock().unwrap();
|
||||||
|
if guard.is_some() {
|
||||||
|
return Err("已有 UAC 播放在进行,请先停止".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 先克隆设备数据(caps/handle/context),probe/协商失败不触碰设备状态;
|
||||||
|
// 直到 start_engine 前才 take(失败归还)
|
||||||
|
let (caps, dev_handle, dev_context) = {
|
||||||
|
let guard = manager_state.lock().unwrap();
|
||||||
|
let d = guard.as_ref().ok_or("DAC 未接入,请先在输出页接入设备")?;
|
||||||
|
(d.caps.clone(), d.handle.clone(), d._context.clone())
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---- 打开源 + probe ----
|
||||||
|
let is_http = source.starts_with("http://") || source.starts_with("https://");
|
||||||
|
let mss = if is_http {
|
||||||
|
let src = HttpSource::new(&source)?;
|
||||||
|
MediaSourceStream::new(Box::new(src), Default::default())
|
||||||
|
} else {
|
||||||
|
let f = std::fs::File::open(&source).map_err(|e| format!("打开文件失败: {e}"))?;
|
||||||
|
MediaSourceStream::new(Box::new(f), Default::default())
|
||||||
|
};
|
||||||
|
let ext = std::path::Path::new(&source)
|
||||||
|
.extension()
|
||||||
|
.and_then(|e| e.to_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string();
|
||||||
|
let mut hint = Hint::new();
|
||||||
|
if !ext.is_empty() {
|
||||||
|
hint.with_extension(&ext);
|
||||||
|
}
|
||||||
|
let probed = symphonia::default::get_probe()
|
||||||
|
.format(&hint, mss, &FormatOptions::default(), &MetadataOptions::default())
|
||||||
|
.map_err(|e| format!("格式探测失败: {e}({display_name})"))?;
|
||||||
|
let mut format = probed.format;
|
||||||
|
let track = format
|
||||||
|
.tracks()
|
||||||
|
.iter()
|
||||||
|
.find(|t| t.codec_params.codec != CODEC_TYPE_NULL)
|
||||||
|
.ok_or("未找到音频轨")?
|
||||||
|
.clone();
|
||||||
|
let duration_frames = track.codec_params.n_frames.map(|f| f as u64);
|
||||||
|
|
||||||
|
let mut decoder = symphonia::default::get_codecs()
|
||||||
|
.make(&track.codec_params, &DecoderOptions::default())
|
||||||
|
.map_err(|e| format!("解码器创建失败: {e}"))?;
|
||||||
|
let track_id = track.id;
|
||||||
|
|
||||||
|
// ---- 源格式(codec_params 由 probe 填充;flac/mp3/m4a 均含) ----
|
||||||
|
let rate = track
|
||||||
|
.codec_params
|
||||||
|
.sample_rate
|
||||||
|
.ok_or("源采样率未知(codec_params 缺失)")?;
|
||||||
|
let channels = track
|
||||||
|
.codec_params
|
||||||
|
.channels
|
||||||
|
.map(|c| c.count() as u8)
|
||||||
|
.ok_or("源声道数未知(codec_params 缺失)")?;
|
||||||
|
let src_bits: u32 = track.codec_params.bits_per_sample.unwrap_or(0).max(16);
|
||||||
|
|
||||||
|
// ---- 与 DAC 能力协商(与 Flick 同口径:源采样率 + 源位深,不强制/不重采样) ----
|
||||||
|
let (alt, _out_bits) = negotiate(&caps, rate, src_bits.max(16), channels)?;
|
||||||
|
if TargetBits::from_subslot(alt.subslot_size).is_none() {
|
||||||
|
return Err(format!("非法 subslot {}", alt.subslot_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
// feedback EP:async 端点必须有反馈,否则频率漂移。本 DAC 的 feedback EP
|
||||||
|
// 描述符未带 bSynchAddress(desc 读到 0),按 UAC 惯例取 EP 同号 IN 位
|
||||||
|
// (OUT 0x01 → IN 0x81),后续用 usbfs 实测验证。
|
||||||
|
let feedback_address = if alt.sync_type == "asynchronous" {
|
||||||
|
Some(alt.endpoint_address | 0x80)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let config = EngineConfig {
|
||||||
|
control_interface: caps.control_interface.ok_or("缺少控制接口")?,
|
||||||
|
streaming_interface: alt.interface_number,
|
||||||
|
alt_setting: alt.alt_setting,
|
||||||
|
endpoint_address: alt.endpoint_address,
|
||||||
|
max_packet_bytes: alt.max_packet_bytes,
|
||||||
|
feedback_address,
|
||||||
|
clock_entity: alt.clock_entity,
|
||||||
|
feature_unit: caps.feature_unit,
|
||||||
|
sample_rate: rate,
|
||||||
|
channels: alt.channels.max(channels),
|
||||||
|
subslot_size: alt.subslot_size,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 独占开始:take 设备(接口将被引擎 claim);失败归还
|
||||||
|
let dev = manager_state
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.take()
|
||||||
|
.ok_or("设备状态已变化,请重新接入")?;
|
||||||
|
let engine = match engine::start_engine(dev_context, dev_handle, config.clone()) {
|
||||||
|
Ok(e) => e,
|
||||||
|
Err(e) => {
|
||||||
|
*manager_state.lock().unwrap() = Some(dev);
|
||||||
|
return Err(format!("引擎启动失败: {e}"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let cfg_out = engine.config.clone();
|
||||||
|
let engine_state = engine.state.clone();
|
||||||
|
|
||||||
|
// ---- 解码线程 ----
|
||||||
|
let decode_ring = engine.ring.clone();
|
||||||
|
let decode_stop = engine.stop.clone();
|
||||||
|
let decode_join = {
|
||||||
|
let cfg = cfg_out.clone();
|
||||||
|
let engine_state_for_thread = engine_state.clone();
|
||||||
|
let track_id_u32 = track_id;
|
||||||
|
std::thread::Builder::new()
|
||||||
|
.name("uac-decode".into())
|
||||||
|
.spawn(move || {
|
||||||
|
let target = match TargetBits::from_subslot(cfg.subslot_size) {
|
||||||
|
Some(t) => t,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
let mut written_frames: u64 = 0;
|
||||||
|
let src_rate = rate;
|
||||||
|
// 输出路径切换(系统输出 ↔ UAC 直出)时保持进度:起播前定位。
|
||||||
|
// 此刻环形缓冲还是空的,不存在"定位前的旧数据残留"问题。
|
||||||
|
if let Some(ms) = start_ms.filter(|&m| m > 0) {
|
||||||
|
let to = symphonia::core::formats::SeekTo::Time {
|
||||||
|
time: symphonia::core::units::Time::new(
|
||||||
|
ms / 1000,
|
||||||
|
(ms % 1000) as f64 / 1000.0,
|
||||||
|
),
|
||||||
|
track_id: Some(track_id_u32),
|
||||||
|
};
|
||||||
|
match format.seek(symphonia::core::formats::SeekMode::Accurate, to) {
|
||||||
|
Ok(_) => {
|
||||||
|
written_frames = ms * src_rate as u64 / 1000;
|
||||||
|
decoder.reset();
|
||||||
|
println!("[uac-player] 从 {ms}ms 起播({src_rate}Hz)");
|
||||||
|
}
|
||||||
|
Err(e) => println!("[uac-player] 定位 {ms}ms 失败({e}),从头播放"),
|
||||||
|
}
|
||||||
|
engine_state_for_thread
|
||||||
|
.decoded_frames
|
||||||
|
.store(written_frames, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
let mut io_errors: u32 = 0;
|
||||||
|
let mut decode_skips: u32 = 0;
|
||||||
|
let result: Result<(), String> = (|| {
|
||||||
|
loop {
|
||||||
|
if decode_stop.load(Ordering::Relaxed) {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let packet = match format.next_packet() {
|
||||||
|
Ok(p) => {
|
||||||
|
io_errors = 0;
|
||||||
|
p
|
||||||
|
}
|
||||||
|
Err(symphonia::core::errors::Error::IoError(e))
|
||||||
|
if e.kind() == std::io::ErrorKind::UnexpectedEof =>
|
||||||
|
{
|
||||||
|
return Ok(()); // EOF
|
||||||
|
}
|
||||||
|
Err(symphonia::core::errors::Error::IoError(e)) => {
|
||||||
|
// 流式源短读可重试,但**不能无限空转**:一旦持续失败,
|
||||||
|
// 解码端不再产出 → 环形缓冲被抽干 → 播放卡住却毫无日志
|
||||||
|
io_errors += 1;
|
||||||
|
if io_errors == 1 || io_errors % 50 == 0 {
|
||||||
|
eprintln!(
|
||||||
|
"[uac-player] 读包 IoError 连续 {io_errors} 次: {e}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if io_errors >= 200 {
|
||||||
|
return Err(format!("持续读包失败({io_errors} 次): {e}"));
|
||||||
|
}
|
||||||
|
std::thread::sleep(Duration::from_millis(2));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Err(e) => return Err(format!("读包失败: {e}")),
|
||||||
|
};
|
||||||
|
if packet.track_id() != track_id_u32 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let decoded = match decoder.decode(&packet) {
|
||||||
|
Ok(d) => d,
|
||||||
|
Err(symphonia::core::errors::Error::DecodeError(msg)) => {
|
||||||
|
// **静默跳包**:丢一帧 ≈ 4096 样本 ≈ 93ms,
|
||||||
|
// 听感就是"停顿一瞬间",且 underruns/ring 全看不出来
|
||||||
|
decode_skips += 1;
|
||||||
|
if decode_skips <= 5 || decode_skips % 50 == 0 {
|
||||||
|
eprintln!(
|
||||||
|
"[uac-player] 跳过无法解码的包 #{decode_skips}: {msg}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Err(symphonia::core::errors::Error::IoError(e))
|
||||||
|
if e.kind() == std::io::ErrorKind::UnexpectedEof =>
|
||||||
|
{
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
Err(e) => return Err(format!("解码失败: {e}")),
|
||||||
|
};
|
||||||
|
let spec = decoded.spec();
|
||||||
|
if spec.rate != src_rate {
|
||||||
|
return Err(format!(
|
||||||
|
"源采样率中途变化 {}→{},终止",
|
||||||
|
src_rate, spec.rate
|
||||||
|
));
|
||||||
|
}
|
||||||
|
// 与 Flick 同口径:不重采样,整数直拷路径(bit-perfect)
|
||||||
|
let bytes = convert_interleaved(&decoded, &target, cfg.channels as usize);
|
||||||
|
let frame_bytes = cfg.channels as usize * cfg.subslot_size as usize;
|
||||||
|
let frames = (bytes.len() / frame_bytes.max(1)) as u64;
|
||||||
|
if !decode_ring.write_all(&bytes) {
|
||||||
|
return Ok(()); // ring 关闭 = 停止
|
||||||
|
}
|
||||||
|
written_frames += frames;
|
||||||
|
engine_state_for_thread
|
||||||
|
.decoded_frames
|
||||||
|
.store(written_frames, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
match result {
|
||||||
|
Ok(()) => {
|
||||||
|
engine_state_for_thread
|
||||||
|
.decoder_done
|
||||||
|
.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("[uac-player] 解码错误: {e}");
|
||||||
|
*engine_state_for_thread.fatal.lock().unwrap() =
|
||||||
|
Some(format!("解码: {e}"));
|
||||||
|
engine_state_for_thread.phase.store(5, Ordering::Relaxed);
|
||||||
|
engine_state_for_thread
|
||||||
|
.decoder_done
|
||||||
|
.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map_err(|e| format!("派生解码线程失败: {e}"))?
|
||||||
|
};
|
||||||
|
|
||||||
|
let st = UacPlayState {
|
||||||
|
phase: engine_state.phase.load(Ordering::Relaxed) as u8,
|
||||||
|
track: display_name,
|
||||||
|
sample_rate: Some(cfg_out.sample_rate),
|
||||||
|
bit_depth: Some(cfg_out.subslot_size * 8),
|
||||||
|
channels: Some(cfg_out.channels),
|
||||||
|
alt_setting: Some(cfg_out.alt_setting),
|
||||||
|
position_ms: Some(0),
|
||||||
|
duration_ms: duration_frames.map(|f| f * 1000 / cfg_out.sample_rate as u64),
|
||||||
|
underruns: 0,
|
||||||
|
fpf_milli: None,
|
||||||
|
paused: false,
|
||||||
|
error: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
*core.inner.lock().unwrap() = Some(ActivePlayback {
|
||||||
|
engine,
|
||||||
|
config: cfg_out,
|
||||||
|
track: st.track.clone(),
|
||||||
|
duration_frames,
|
||||||
|
rate,
|
||||||
|
decode_join: Some(decode_join),
|
||||||
|
restore: Some(RestoreInfo {
|
||||||
|
handle: dev.handle.clone(),
|
||||||
|
context: dev._context.clone(),
|
||||||
|
info: dev.info.clone(),
|
||||||
|
caps: dev.caps.clone(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
emit_state(&app, &st);
|
||||||
|
Ok(st)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止并返回(状态, 归还数据);调用方负责把设备放回 manager
|
||||||
|
pub fn stop(
|
||||||
|
app: &tauri::AppHandle,
|
||||||
|
core: &PlayerCore,
|
||||||
|
) -> Result<(UacPlayState, Option<RestoreInfo>), String> {
|
||||||
|
core.stop(app)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 播放中状态快照
|
||||||
|
#[allow(dead_code)] // 预留:状态快照 API
|
||||||
|
pub fn snapshot(core: &PlayerCore) -> UacPlayState {
|
||||||
|
core.snapshot()
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
|
"productName": "lfmusic",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"identifier": "music.lfeng.me",
|
||||||
|
"build": {
|
||||||
|
"beforeDevCommand": "bun run dev",
|
||||||
|
"devUrl": "http://localhost:1420",
|
||||||
|
"beforeBuildCommand": "bun run build",
|
||||||
|
"frontendDist": "../dist"
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"windows": [
|
||||||
|
{
|
||||||
|
"title": "lfmusic",
|
||||||
|
"width": 800,
|
||||||
|
"height": 600
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"security": {
|
||||||
|
"csp": null,
|
||||||
|
"assetProtocol": {
|
||||||
|
"enable": true,
|
||||||
|
"scope": ["$APPDATA/covers/*", "$APPDATA/covers/**"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bundle": {
|
||||||
|
"active": true,
|
||||||
|
"targets": "all",
|
||||||
|
"icon": [
|
||||||
|
"icons/32x32.png",
|
||||||
|
"icons/128x128.png",
|
||||||
|
"icons/128x128@2x.png",
|
||||||
|
"icons/icon.icns",
|
||||||
|
"icons/icon.ico"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
# 包名 = Tauri 插件名(JS: plugin:usb|...;与 Kotlin UsbPlugin 通过
|
||||||
|
# lib.rs 的 register_android_plugin("music.lfeng.me", "UsbPlugin") 关联)
|
||||||
|
name = "usb"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
# tauri-plugin build 约定:links 必须设置且与包名一致(tauri-plugin 2.x try_build 强制)
|
||||||
|
links = "usb"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-plugin = "2"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
//! ACL 清单生成(M4):本 crate 只承载 Tauri 插件的**构建期权限清单**,
|
||||||
|
//! 无运行时代码。`CARGO_PKG_NAME = usb` 决定插件名;命令列表对应
|
||||||
|
//! Kotlin `UsbPlugin` 的 @Command 方法(M4 UAC:UsbManager 桥)。
|
||||||
|
fn main() {
|
||||||
|
tauri_plugin::Builder::new(&["list_devices", "request_permission", "open_device", "close_device", "set_playback_active"]).build();
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Automatically generated - DO NOT EDIT!
|
||||||
|
|
||||||
|
"$schema" = "../../schemas/schema.json"
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "allow-close-device"
|
||||||
|
description = "Enables the close_device command without any pre-configured scope."
|
||||||
|
commands.allow = ["close_device"]
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "deny-close-device"
|
||||||
|
description = "Denies the close_device command without any pre-configured scope."
|
||||||
|
commands.deny = ["close_device"]
|
||||||