From b15a0a423dcbcfecf119fe5757697ebb8574e7f3 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Fri, 7 Aug 2026 00:45:48 -0600 Subject: [PATCH] tauri: clean up platform-specific BLE branches --- crates/ratspeak-tauri/src/commands/ble.rs | 4 +- .../ratspeak-tauri/src/commands/interfaces.rs | 78 ++++++++++--------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/crates/ratspeak-tauri/src/commands/ble.rs b/crates/ratspeak-tauri/src/commands/ble.rs index 57fbf24..4cbab9b 100644 --- a/crates/ratspeak-tauri/src/commands/ble.rs +++ b/crates/ratspeak-tauri/src/commands/ble.rs @@ -250,9 +250,9 @@ pub async fn submit_ble_rnode_passkey(_passkey: u32) -> AppResult { if rns_interface::ble_rnode::linux_submit_passkey(_passkey) { return Ok(json!({ "ok": true })); } - return Err(AppError::not_found( + Err(AppError::not_found( "No BLE pairing in progress".to_string(), - )); + )) } #[cfg(not(all(feature = "ble", target_os = "linux")))] { diff --git a/crates/ratspeak-tauri/src/commands/interfaces.rs b/crates/ratspeak-tauri/src/commands/interfaces.rs index 05d0e76..b9ead29 100644 --- a/crates/ratspeak-tauri/src/commands/interfaces.rs +++ b/crates/ratspeak-tauri/src/commands/interfaces.rs @@ -136,12 +136,12 @@ async fn ble_platform_probe() -> BlePlatformProbe { ), _ => (true, vec![]), }; - return BlePlatformProbe { + BlePlatformProbe { available, missing, auth_state: Some(auth), permission_required: false, - }; + } } #[cfg(all(feature = "ble", target_os = "android"))] @@ -158,7 +158,7 @@ async fn ble_platform_probe() -> BlePlatformProbe { .collect() }) .unwrap_or_default(); - return BlePlatformProbe { + BlePlatformProbe { available: payload .get("available") .and_then(Value::as_bool) @@ -169,18 +169,20 @@ async fn ble_platform_probe() -> BlePlatformProbe { .get("permission_required") .and_then(Value::as_bool) .unwrap_or(false), - }; + } } // macOS: skip btleplug probe; `Manager::new()` triggers the system // Bluetooth permission prompt prematurely. #[cfg(all(feature = "ble", target_os = "macos"))] - return BlePlatformProbe { - available: true, - missing: vec![], - auth_state: None, - permission_required: false, - }; + { + BlePlatformProbe { + available: true, + missing: vec![], + auth_state: None, + permission_required: false, + } + } #[cfg(all( feature = "ble", @@ -200,12 +202,12 @@ async fn ble_platform_probe() -> BlePlatformProbe { Ok(Err(e)) => (false, vec![e]), Err(_) => (false, vec!["BLE check timed out".to_string()]), }; - return BlePlatformProbe { + BlePlatformProbe { available, missing, auth_state: None, permission_required: false, - }; + } } #[cfg(not(feature = "ble"))] @@ -312,7 +314,9 @@ pub async fn api_serial_ports() -> AppResult { pub async fn api_ble_available() -> AppResult { // Android: bridge BLE is always present; no probe. #[cfg(all(feature = "ble", target_os = "android"))] - return Ok(json!({"available": true, "missing": [], "install_cmd": ""})); + { + Ok(json!({"available": true, "missing": [], "install_cmd": ""})) + } // Linux/BSD desktop keeps its own adapter probe: BlueZ-specific hints the // shared probe does not produce. @@ -328,24 +332,26 @@ pub async fn api_ble_available() -> AppResult { ) .await { - Ok(Ok(true)) => { - return Ok(json!({"available": true, "missing": [], "install_cmd": ""})); - } + Ok(Ok(true)) => Ok(json!({"available": true, "missing": [], "install_cmd": ""})), Ok(Ok(false)) => { #[cfg(target_os = "linux")] - return Ok(json!({ - "available": false, - "missing": [ - "No BLE adapter found. If your machine has Bluetooth, ensure bluetoothd is running: sudo systemctl start bluetooth" - ], - "install_cmd": "", - })); + { + Ok(json!({ + "available": false, + "missing": [ + "No BLE adapter found. If your machine has Bluetooth, ensure bluetoothd is running: sudo systemctl start bluetooth" + ], + "install_cmd": "", + })) + } #[cfg(not(target_os = "linux"))] - return Ok(json!({ - "available": false, - "missing": ["No BLE adapter found"], - "install_cmd": "", - })); + { + Ok(json!({ + "available": false, + "missing": ["No BLE adapter found"], + "install_cmd": "", + })) + } } Ok(Err(e)) => { #[cfg(target_os = "linux")] @@ -367,15 +373,15 @@ pub async fn api_ble_available() -> AppResult { Some(h) => vec![format!("{e} — {h}")], None => vec![e], }; - return Ok(json!({"available": false, "missing": missing, "install_cmd": ""})); + Ok(json!({"available": false, "missing": missing, "install_cmd": ""})) } #[cfg(not(target_os = "linux"))] - return Ok(json!({"available": false, "missing": [e], "install_cmd": ""})); + { + Ok(json!({"available": false, "missing": [e], "install_cmd": ""})) + } } Err(_) => { - return Ok( - json!({"available": false, "missing": ["BLE check timed out"], "install_cmd": ""}), - ); + Ok(json!({"available": false, "missing": ["BLE check timed out"], "install_cmd": ""})) } } @@ -7503,12 +7509,10 @@ mod backbone_args_tests { #[cfg(test)] mod ble_probe_tests { - use super::*; - #[cfg(not(feature = "ble"))] #[tokio::test] async fn ble_probe_without_feature_reports_stub() { - let probe = ble_platform_probe().await; + let probe = super::ble_platform_probe().await; assert!(!probe.available); assert_eq!(probe.missing, vec!["ble feature not compiled".to_string()]); assert_eq!(probe.auth_state, None); @@ -7518,7 +7522,7 @@ mod ble_probe_tests { #[cfg(all(feature = "ble", target_os = "macos"))] #[tokio::test] async fn ble_probe_macos_skips_probe_and_reports_available() { - let probe = ble_platform_probe().await; + let probe = super::ble_platform_probe().await; assert!(probe.available); assert!(probe.missing.is_empty()); assert_eq!(probe.auth_state, None);