From ed2d9169369e7811dfbcf3406d182ee13269151a Mon Sep 17 00:00:00 2001 From: Timothy Yin Date: Sat, 3 May 2025 04:25:15 +0800 Subject: [PATCH] feat: macOS compatibility --- package.json | 12 +- pnpm-lock.yaml | 22 +- src-tauri/Cargo.lock | 540 +++++++++++++++++++----------- src-tauri/Cargo.toml | 2 +- src-tauri/Info.plist | 8 + src-tauri/src/main.rs | 63 ++-- src/App.vue | 2 +- src/components/ScanningDevice.vue | 14 +- src/composables/useErrno.ts | 14 + src/pages/index.vue | 32 +- src/stores/index.ts | 7 +- 11 files changed, 447 insertions(+), 269 deletions(-) create mode 100644 src-tauri/Info.plist create mode 100644 src/composables/useErrno.ts diff --git a/package.json b/package.json index 2c3be81..f567ca1 100644 --- a/package.json +++ b/package.json @@ -10,23 +10,23 @@ "tauri": "tauri" }, "dependencies": { - "@tauri-apps/api": "^1", + "@tauri-apps/api": "^1.6.0", "@vueuse/core": "^10.11.0", "pinia": "^2.1.7", - "vue": "^3.3.4", + "vue": "^3.4.31", "vue-router": "^4.4.0", "vue3-snackbar": "^2.3.2" }, "devDependencies": { - "@tauri-apps/cli": "^1", + "@tauri-apps/cli": "^1.6.0", "@vitejs/plugin-vue": "^5.0.5", "autoprefixer": "^10.4.19", "postcss": "^8.4.39", "sass": "^1.77.8", "tailwindcss": "^3.4.4", - "typescript": "^5.2.2", + "typescript": "^5.5.3", "unplugin-vue-components": "^0.27.2", - "vite": "^5.3.1", - "vue-tsc": "^2.0.22" + "vite": "^5.3.3", + "vue-tsc": "^2.0.26" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 26ab74d..22811a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,7 +9,7 @@ importers: .: dependencies: '@tauri-apps/api': - specifier: ^1 + specifier: ^1.6.0 version: 1.6.0 '@vueuse/core': specifier: ^10.11.0 @@ -18,7 +18,7 @@ importers: specifier: ^2.1.7 version: 2.1.7(typescript@5.5.3)(vue@3.4.31(typescript@5.5.3)) vue: - specifier: ^3.3.4 + specifier: ^3.4.31 version: 3.4.31(typescript@5.5.3) vue-router: specifier: ^4.4.0 @@ -28,7 +28,7 @@ importers: version: 2.3.2(vue@3.4.31(typescript@5.5.3)) devDependencies: '@tauri-apps/cli': - specifier: ^1 + specifier: ^1.6.0 version: 1.6.0 '@vitejs/plugin-vue': specifier: ^5.0.5 @@ -46,16 +46,16 @@ importers: specifier: ^3.4.4 version: 3.4.4 typescript: - specifier: ^5.2.2 + specifier: ^5.5.3 version: 5.5.3 unplugin-vue-components: specifier: ^0.27.2 version: 0.27.2(@babel/parser@7.24.8)(rollup@4.18.1)(vue@3.4.31(typescript@5.5.3)) vite: - specifier: ^5.3.1 + specifier: ^5.3.3 version: 5.3.3(sass@1.77.8) vue-tsc: - specifier: ^2.0.22 + specifier: ^2.0.26 version: 2.0.26(typescript@5.5.3) packages: @@ -550,8 +550,8 @@ packages: resolution: {integrity: sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==} engines: {node: '>= 6'} - caniuse-lite@1.0.30001642: - resolution: {integrity: sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA==} + caniuse-lite@1.0.30001716: + resolution: {integrity: sha512-49/c1+x3Kwz7ZIWt+4DvK3aMJy9oYXXG6/97JKsnjdCk/6n9vVyWL8NAwVt95Lwt9eigI10Hl782kDfZUUlRXw==} chokidar@3.6.0: resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} @@ -1477,7 +1477,7 @@ snapshots: autoprefixer@10.4.19(postcss@8.4.39): dependencies: browserslist: 4.23.2 - caniuse-lite: 1.0.30001642 + caniuse-lite: 1.0.30001716 fraction.js: 4.3.7 normalize-range: 0.1.2 picocolors: 1.0.1 @@ -1498,14 +1498,14 @@ snapshots: browserslist@4.23.2: dependencies: - caniuse-lite: 1.0.30001642 + caniuse-lite: 1.0.30001716 electron-to-chromium: 1.4.827 node-releases: 2.0.14 update-browserslist-db: 1.1.0(browserslist@4.23.2) camelcase-css@2.0.1: {} - caniuse-lite@1.0.30001642: {} + caniuse-lite@1.0.30001716: {} chokidar@3.6.0: dependencies: diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 32e7427..e2073f5 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -64,13 +64,13 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -144,9 +144,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" [[package]] name = "block" @@ -164,13 +164,21 @@ dependencies = [ ] [[package]] -name = "bluez-async" -version = "0.7.2" +name = "block2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce7d4413c940e8e3cb6afc122d3f4a07096aca259d286781128683fc9f39d9b" +checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" dependencies = [ - "async-trait", - "bitflags 2.6.0", + "objc2", +] + +[[package]] +name = "bluez-async" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353dc0fbd494ab1d066ffdff16f07acbea46ca63f507e093c07fdf2408d84300" +dependencies = [ + "bitflags 2.9.0", "bluez-generated", "dbus", "dbus-tokio", @@ -179,16 +187,16 @@ dependencies = [ "log", "serde", "serde-xml-rs", - "thiserror", + "thiserror 2.0.12", "tokio", "uuid", ] [[package]] name = "bluez-generated" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d1c659dbc82f0b8ca75606c91a371e763589b7f6acf36858eeed0c705afe367" +checksum = "9676783265eadd6f11829982792c6f303f3854d014edfba384685dcf237dd062" dependencies = [ "dbus", ] @@ -226,31 +234,32 @@ dependencies = [ [[package]] name = "btleplug" -version = "0.11.5" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba345f9db94939c72959b2008abe1ffcdbcaa235243fd92ad12436532ff199cf" +checksum = "c9a11621cb2c8c024e444734292482b1ad86fb50ded066cf46252e46643c8748" dependencies = [ "async-trait", - "bitflags 2.6.0", + "bitflags 2.9.0", "bluez-async", - "cocoa 0.25.0", - "dashmap", + "dashmap 6.1.0", "dbus", "futures", "jni 0.19.0", "jni-utils", - "libc", "log", - "objc", + "objc2", + "objc2-core-bluetooth", + "objc2-foundation", "once_cell", "serde", "serde_bytes", "static_assertions", - "thiserror", + "thiserror 2.0.12", "tokio", "tokio-stream", "uuid", - "windows 0.52.0", + "windows 0.61.1", + "windows-future", ] [[package]] @@ -287,7 +296,7 @@ dependencies = [ "cairo-sys-rs", "glib", "libc", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -382,24 +391,8 @@ dependencies = [ "block", "cocoa-foundation", "core-foundation", - "core-graphics 0.22.3", - "foreign-types 0.3.2", - "libc", - "objc", -] - -[[package]] -name = "cocoa" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6140449f97a6e97f9511815c5632d84c8aacf8ac271ad77c559218161a1373c" -dependencies = [ - "bitflags 1.3.2", - "block", - "cocoa-foundation", - "core-foundation", - "core-graphics 0.23.2", - "foreign-types 0.5.0", + "core-graphics", + "foreign-types", "libc", "objc", ] @@ -465,20 +458,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types 0.3.2", - "libc", -] - -[[package]] -name = "core-graphics" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "libc", ] @@ -579,7 +559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" dependencies = [ "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -589,7 +569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" dependencies = [ "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -613,7 +593,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -624,7 +604,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -640,6 +620,20 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "dashmap" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "dbus" version = "0.9.7" @@ -684,7 +678,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -855,28 +849,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared 0.1.1", -] - -[[package]] -name = "foreign-types" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" -dependencies = [ - "foreign-types-macros", - "foreign-types-shared 0.3.1", -] - -[[package]] -name = "foreign-types-macros" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.70", + "foreign-types-shared", ] [[package]] @@ -885,12 +858,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "foreign-types-shared" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -912,9 +879,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -927,9 +894,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -937,15 +904,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -954,38 +921,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -1139,6 +1106,18 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "getrandom" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", +] + [[package]] name = "gimli" version = "0.29.0" @@ -1159,7 +1138,7 @@ dependencies = [ "glib", "libc", "once_cell", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -1192,7 +1171,7 @@ dependencies = [ "libc", "once_cell", "smallvec", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -1353,12 +1332,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - [[package]] name = "hex" version = "0.4.3" @@ -1407,7 +1380,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -1515,9 +1488,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.5" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] @@ -1567,7 +1540,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.61", "walkdir", ] @@ -1581,7 +1554,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.61", "walkdir", ] @@ -1597,7 +1570,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "259e9f2c3ead61de911f147000660511f07ab00adeed1d84f5ac4d0386e7a6c4" dependencies = [ - "dashmap", + "dashmap 5.5.3", "futures", "jni 0.19.0", "log", @@ -1623,7 +1596,7 @@ checksum = "ec9ad60d674508f3ca8f380a928cfe7b096bc729c4e2dbfe3852bc45da3ab30b" dependencies = [ "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -1647,9 +1620,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libdbus-sys" @@ -1666,7 +1639,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.0", "libc", ] @@ -1688,9 +1661,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "loom" @@ -1778,13 +1751,13 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1797,7 +1770,7 @@ dependencies = [ "jni-sys", "ndk-sys", "num_enum", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -1852,16 +1825,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "num_enum" version = "0.5.11" @@ -1904,6 +1867,51 @@ dependencies = [ "objc_id", ] +[[package]] +name = "objc-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" + +[[package]] +name = "objc2" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" +dependencies = [ + "objc-sys", + "objc2-encode", +] + +[[package]] +name = "objc2-core-bluetooth" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a644b62ffb826a5277f536cf0f701493de420b13d40e700c452c36567771111" +dependencies = [ + "bitflags 2.9.0", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + +[[package]] +name = "objc2-foundation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" +dependencies = [ + "bitflags 2.9.0", + "block2", + "libc", + "objc2", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -1933,9 +1941,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "open" @@ -2117,7 +2125,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -2251,9 +2259,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -2276,6 +2284,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + [[package]] name = "rand" version = "0.7.3" @@ -2378,7 +2392,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.0", ] [[package]] @@ -2389,7 +2403,7 @@ checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ "getrandom 0.2.15", "libredox", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -2481,7 +2495,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.0", "errno", "libc", "linux-raw-sys", @@ -2552,9 +2566,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.204" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] @@ -2567,28 +2581,28 @@ checksum = "fb3aa78ecda1ebc9ec9847d5d3aba7d618823446a049ba2491940506da6e2782" dependencies = [ "log", "serde", - "thiserror", + "thiserror 1.0.61", "xml-rs", ] [[package]] name = "serde_bytes" -version = "0.11.15" +version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" +checksum = "8437fd221bde2d4ca316d61b90e337e9e702b3820b87d63caa9ba6c02bd06d96" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -2611,7 +2625,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -2650,7 +2664,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -2845,9 +2859,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.70" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", @@ -2889,9 +2903,9 @@ dependencies = [ "bitflags 1.3.2", "cairo-rs", "cc", - "cocoa 0.24.1", + "cocoa", "core-foundation", - "core-graphics 0.22.3", + "core-graphics", "crossbeam-channel", "dispatch", "gdk", @@ -2923,7 +2937,7 @@ dependencies = [ "unicode-segmentation", "uuid", "windows 0.39.0", - "windows-implement", + "windows-implement 0.39.0", "x11-dl", ] @@ -2962,7 +2976,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "336bc661a3f3250853fa83c6e5245449ed1c26dce5dcb28bdee7efedf6278806" dependencies = [ "anyhow", - "cocoa 0.24.1", + "cocoa", "dirs-next", "dunce", "embed_plist", @@ -2996,7 +3010,7 @@ dependencies = [ "tauri-runtime-wry", "tauri-utils", "tempfile", - "thiserror", + "thiserror 1.0.61", "tokio", "url", "uuid", @@ -3044,7 +3058,7 @@ dependencies = [ "serde_json", "sha2", "tauri-utils", - "thiserror", + "thiserror 1.0.61", "time", "uuid", "walkdir", @@ -3078,7 +3092,7 @@ dependencies = [ "serde", "serde_json", "tauri-utils", - "thiserror", + "thiserror 1.0.61", "url", "uuid", "webview2-com", @@ -3091,7 +3105,7 @@ version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c3db170233096aa30330feadcd895bf9317be97e624458560a20e814db7955" dependencies = [ - "cocoa 0.24.1", + "cocoa", "gtk", "percent-encoding", "rand 0.8.5", @@ -3129,7 +3143,7 @@ dependencies = [ "serde", "serde_json", "serde_with", - "thiserror", + "thiserror 1.0.61", "url", "walkdir", "windows-version", @@ -3180,7 +3194,16 @@ version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.61", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl 2.0.12", ] [[package]] @@ -3191,7 +3214,18 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", ] [[package]] @@ -3252,39 +3286,38 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.0" +version = "1.44.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.3.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] name = "tokio-stream" -version = "0.1.15" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite", @@ -3392,7 +3425,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", ] [[package]] @@ -3487,11 +3520,11 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "uuid" -version = "1.10.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.3.2", "serde", ] @@ -3561,6 +3594,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -3582,7 +3624,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", "wasm-bindgen-shared", ] @@ -3616,7 +3658,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.101", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3693,7 +3735,7 @@ dependencies = [ "webview2-com-macros", "webview2-com-sys", "windows 0.39.0", - "windows-implement", + "windows-implement 0.39.0", ] [[package]] @@ -3716,7 +3758,7 @@ dependencies = [ "regex", "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", "windows 0.39.0", "windows-bindgen", "windows-metadata", @@ -3772,7 +3814,7 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a" dependencies = [ - "windows-implement", + "windows-implement 0.39.0", "windows_aarch64_msvc 0.39.0", "windows_i686_gnu 0.39.0", "windows_i686_msvc 0.39.0", @@ -3791,12 +3833,15 @@ dependencies = [ [[package]] name = "windows" -version = "0.52.0" +version = "0.61.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +checksum = "c5ee8f3d025738cb02bad7868bbb5f8a6327501e870bf51f1b455b0a2454a419" dependencies = [ - "windows-core", - "windows-targets 0.52.6", + "windows-collections", + "windows-core 0.61.0", + "windows-future", + "windows-link", + "windows-numerics", ] [[package]] @@ -3809,6 +3854,15 @@ dependencies = [ "windows-tokens", ] +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" +dependencies = [ + "windows-core 0.61.0", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -3818,6 +3872,29 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.61.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +dependencies = [ + "windows-implement 0.60.0", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a1d6bbefcb7b60acd19828e1bc965da6fcf18a7e39490c5f8be71e54a19ba32" +dependencies = [ + "windows-core 0.61.0", + "windows-link", +] + [[package]] name = "windows-implement" version = "0.39.0" @@ -3828,12 +3905,68 @@ dependencies = [ "windows-tokens", ] +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + [[package]] name = "windows-metadata" version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ee5e275231f07c6e240d14f34e1b635bf1faa1c76c57cfd59a5cdb9848e4278" +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" +dependencies = [ + "windows-core 0.61.0", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -4133,6 +4266,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags 2.9.0", +] + [[package]] name = "wry" version = "0.24.10" @@ -4141,8 +4283,8 @@ checksum = "00711278ed357350d44c749c286786ecac644e044e4da410d466212152383b45" dependencies = [ "base64 0.13.1", "block", - "cocoa 0.24.1", - "core-graphics 0.22.3", + "cocoa", + "core-graphics", "crossbeam-channel", "dunce", "gdk", @@ -4162,13 +4304,13 @@ dependencies = [ "sha2", "soup2", "tao", - "thiserror", + "thiserror 1.0.61", "url", "webkit2gtk", "webkit2gtk-sys", "webview2-com", "windows 0.39.0", - "windows-implement", + "windows-implement 0.39.0", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index dc52a75..474ee52 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -14,7 +14,7 @@ tauri-build = { version = "1", features = [] } tauri = { version = "1", features = [ "window-create", "path-all", "dialog-all", "window-show", "window-hide", "window-maximize", "window-unmaximize", "window-unminimize", "window-start-dragging", "window-minimize", "window-close", "shell-open"] } serde = { version = "1", features = ["derive"] } serde_json = "1" -btleplug = { version = "0.11.5", features = ["serde"] } +btleplug = { version = "0.11.8", features = ["serde"] } tokio = { version = "1.38.0", features = ["full"] } futures = "0.3.30" uuid = "1.10.0" diff --git a/src-tauri/Info.plist b/src-tauri/Info.plist new file mode 100644 index 0000000..70c9f80 --- /dev/null +++ b/src-tauri/Info.plist @@ -0,0 +1,8 @@ + + + + + NSBluetoothAlwaysUsageDescription + Request Bluetooth for recovery BLE devices. + + \ No newline at end of file diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 778520e..b251e72 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,7 +4,7 @@ use btleplug::api::bleuuid::uuid_from_u16; use btleplug::api::CentralEvent::{DeviceDisconnected, DeviceDiscovered, DeviceUpdated}; use btleplug::api::{BDAddr, Central, Manager as _, Peripheral as _, ScanFilter}; -use btleplug::platform::{Adapter, Manager as BtleManager, Peripheral, PeripheralId}; +use btleplug::platform::{Adapter, Manager as BtleManager, Peripheral}; use futures::StreamExt; use std::error::Error; use std::sync::Arc; @@ -14,6 +14,7 @@ use tokio::sync::Mutex; #[derive(serde::Serialize, Clone)] struct BleDevice { + peripheral_id: String, name: String, address: BDAddr, rssi: i16, @@ -67,14 +68,17 @@ impl BleConnection { peripheral.is_some() } - pub async fn connect(&self, address: BDAddr, app: &AppHandle) -> Result<(), Box> { + pub async fn connect(&self, peripheral_id: String, app: &AppHandle) -> Result<(), Box> { self.stop_scan().await.unwrap(); let central = self.central.lock().await; let peripheral = central .as_ref() .unwrap() - .peripheral(&PeripheralId::from(address)) - .await?; + .peripherals() + .await? + .into_iter() + .find(|p| p.id().to_string() == peripheral_id) + .ok_or_else(|| "5010")?; peripheral.connect().await?; peripheral.discover_services().await?; // 如果 peripheral.services() 不包含 0x180D 服务,则返回错误 @@ -83,13 +87,18 @@ impl BleConnection { .iter() .any(|s| s.uuid == uuid_from_u16(0x180D)) { - return Err("Peripheral does not have the required service".into()); + return Err("5011".into()); } self.set_peripheral(Some(peripheral)).await; let peripheral = self.peripheral.lock().await; let device = BleDevice { + peripheral_id: peripheral + .as_ref() + .unwrap() + .id() + .to_string(), name: peripheral .as_ref() .unwrap() @@ -106,7 +115,7 @@ impl BleConnection { .await? .unwrap() .rssi - .unwrap(), + .unwrap_or(0) }; let service = peripheral @@ -136,7 +145,7 @@ impl BleConnection { while let Some(notification) = notification_stream.next().await { if notification.uuid == uuid_from_u16(0x2A37) { let value = notification.value; - let heart_rate = value[1] as u16; + let heart_rate = value[0] as u16; app_clone.emit_all("heart-rate", heart_rate).unwrap(); } } @@ -164,27 +173,24 @@ impl BleConnection { tokio::spawn(async move { while let Some(event) = event_stream.next().await { match event { - DeviceDiscovered(peripheral) | DeviceUpdated(peripheral) => { + DeviceDiscovered(peripheral_id) | DeviceUpdated(peripheral_id) => { let p = central_clone .as_ref() .unwrap() - .peripheral(&peripheral) + .peripheral(&peripheral_id) .await .unwrap(); - let device = BleDevice { - name: p - .properties() - .await - .unwrap() - .unwrap() - .local_name - .unwrap_or("Unknown".to_string()), - address: p.address(), - rssi: p.properties().await.unwrap().unwrap().rssi.unwrap(), - }; - app_handle - .emit_all("device-discovered", Some(device)) - .unwrap(); + if let Ok(Some(props)) = p.properties().await { + let name = props.local_name.unwrap_or("Unknown".to_string()); + let rssi = props.rssi.unwrap_or(0); + let device = BleDevice { + peripheral_id: peripheral_id.to_string(), + name, + address: props.address, + rssi, + }; + let _ = app_handle.emit_all("device-discovered", Some(device)); + } } DeviceDisconnected(peripheral) => { let mut p = self_clone.peripheral.lock().await; @@ -256,6 +262,11 @@ async fn is_connected(connection: State<'_, BleConnection>) -> Result) -> Result { let peripheral = connection.peripheral.lock().await; let device = BleDevice { + peripheral_id: peripheral + .as_ref() + .unwrap() + .id() + .to_string(), name: peripheral .as_ref() .unwrap() @@ -274,18 +285,18 @@ async fn get_connected_device(connection: State<'_, BleConnection>) -> Result, app_handle: AppHandle, ) -> Result { - if let Err(e) = connection.connect(address, &app_handle).await { + if let Err(e) = connection.connect(peripheral_id, &app_handle).await { Err(e.to_string()) } else { Ok(true) diff --git a/src/App.vue b/src/App.vue index 501c689..2452112 100644 --- a/src/App.vue +++ b/src/App.vue @@ -32,7 +32,7 @@ listen("device-disconnected", (_) => { - + diff --git a/src/components/ScanningDevice.vue b/src/components/ScanningDevice.vue index f570636..143ecaf 100644 --- a/src/components/ScanningDevice.vue +++ b/src/components/ScanningDevice.vue @@ -1,8 +1,8 @@ diff --git a/src/composables/useErrno.ts b/src/composables/useErrno.ts new file mode 100644 index 0000000..1484fcd --- /dev/null +++ b/src/composables/useErrno.ts @@ -0,0 +1,14 @@ +export const ERRNO: Record = { + 5010: '找不到指定 ID 的设备', + 5011: '设备没有公开的心率服务' +} + +export const useErrno = (errno: string | null | undefined) => { + if (errno) { + const err = ERRNO[Number(errno)] + if (err) { + return err + } + } + return '未知错误' +} \ No newline at end of file diff --git a/src/pages/index.vue b/src/pages/index.vue index bc5c4d7..fe143d8 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -3,6 +3,7 @@ import { invoke } from '@tauri-apps/api/tauri'; import { useBrcatStore } from '../stores'; import { computed, onMounted, ref } from 'vue'; import { useSnackbar } from 'vue3-snackbar'; +import { useErrno } from '../composables/useErrno'; const store = useBrcatStore(); const snackbar = useSnackbar(); @@ -10,14 +11,14 @@ const is_connecting = ref(false); const scanning_devices = computed(() => store.scanning_devices.filter(d => d.name !== 'Unknown')); -async function connect(address: String) { +async function connect(peripheral_id: String) { is_connecting.value = true; store.stopScan(); - invoke('connect', { address }) - .catch(err => { + invoke('connect', { peripheralId: peripheral_id }) + .catch(errno => { snackbar.add({ type: 'error', - text: `连接设备失败: ${err}` + text: useErrno(errno), }); store.startScan(); }).finally(() => { @@ -51,29 +52,24 @@ onMounted(() => { -
+
- + --> +
{
+ :key="device.peripheral_id" :device="device" @connect="connect" />
diff --git a/src/stores/index.ts b/src/stores/index.ts index f624f96..8a60d39 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -5,6 +5,7 @@ import { listen } from "@tauri-apps/api/event"; import { useThrottleFn, useDebounceFn } from "@vueuse/core"; export interface Device { + peripheral_id: string; name: string; address: string; rssi: number; @@ -58,14 +59,16 @@ export const useBrcatStore = defineStore("brcat", () => { }, 2000); function pushDevice(device: Device) { - if (scanning_devices.value.some((d) => d.address === device.address)) { + if (scanning_devices.value.some((d) => d.peripheral_id === device.peripheral_id)) { scanning_devices.value = scanning_devices.value.map((d) => - d.address === device.address ? device : d + d.peripheral_id === device.peripheral_id ? device : d ); } else { scanning_devices.value.push(device); } + console.log(device); + throttledSort(); }