From c6dac023c9cc56c9bbb82abde5c8803aa2edaa08 Mon Sep 17 00:00:00 2001 From: baiqing Date: Wed, 29 Apr 2026 21:21:08 +0800 Subject: [PATCH] =?UTF-8?q?style(tauri):=20rustfmt=20=E6=95=B4=E7=90=86?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/src-tauri/src/asr/volcengine.rs | 6 +-- openless -all/app/src-tauri/src/hotkey.rs | 11 ++-- openless -all/app/src-tauri/src/insertion.rs | 4 +- .../app/src-tauri/src/persistence.rs | 52 ++++++++++++------- openless -all/app/src-tauri/src/types.rs | 6 ++- 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/openless -all/app/src-tauri/src/asr/volcengine.rs b/openless -all/app/src-tauri/src/asr/volcengine.rs index 73092e29..91ab2b8a 100644 --- a/openless -all/app/src-tauri/src/asr/volcengine.rs +++ b/openless -all/app/src-tauri/src/asr/volcengine.rs @@ -449,10 +449,8 @@ impl AudioConsumer for VolcengineStreamingASR { if st.pending_audio.len() < TARGET_AUDIO_CHUNK_BYTES { None } else { - let chunk: Vec = st - .pending_audio - .drain(..TARGET_AUDIO_CHUNK_BYTES) - .collect(); + let chunk: Vec = + st.pending_audio.drain(..TARGET_AUDIO_CHUNK_BYTES).collect(); let seq = st.next_sequence; st.next_sequence += 1; st.bytes_sent += chunk.len(); diff --git a/openless -all/app/src-tauri/src/hotkey.rs b/openless -all/app/src-tauri/src/hotkey.rs index 0ff1acc4..4d0f3516 100644 --- a/openless -all/app/src-tauri/src/hotkey.rs +++ b/openless -all/app/src-tauri/src/hotkey.rs @@ -39,10 +39,7 @@ impl HotkeyMonitor { /// the OS-level hook installed (CGEventTap on macOS / rdev::listen otherwise). /// Returns Err if installation failed (typically Accessibility not granted on macOS), /// so the caller can schedule a retry instead of silently dropping events. - pub fn start( - binding: HotkeyBinding, - tx: Sender, - ) -> anyhow::Result { + pub fn start(binding: HotkeyBinding, tx: Sender) -> anyhow::Result { let shared = Arc::new(Shared { binding: RwLock::new(binding), trigger_held: AtomicBool::new(false), @@ -293,9 +290,9 @@ mod platform { match trigger { HotkeyTrigger::LeftControl | HotkeyTrigger::RightControl => FLAG_MASK_CONTROL, HotkeyTrigger::RightCommand => FLAG_MASK_COMMAND, - HotkeyTrigger::LeftOption - | HotkeyTrigger::RightOption - | HotkeyTrigger::RightAlt => FLAG_MASK_ALTERNATE, + HotkeyTrigger::LeftOption | HotkeyTrigger::RightOption | HotkeyTrigger::RightAlt => { + FLAG_MASK_ALTERNATE + } HotkeyTrigger::Fn => FLAG_MASK_SECONDARY_FN, } } diff --git a/openless -all/app/src-tauri/src/insertion.rs b/openless -all/app/src-tauri/src/insertion.rs index 58f9ef02..266d3f05 100644 --- a/openless -all/app/src-tauri/src/insertion.rs +++ b/openless -all/app/src-tauri/src/insertion.rs @@ -68,7 +68,9 @@ fn simulate_paste() -> Result<(), String> { use enigo::{Direction, Enigo, Key, Keyboard, Settings}; let mut enigo = Enigo::new(&Settings::default()).map_err(|e| e.to_string())?; let modifier = Key::Control; - enigo.key(modifier, Direction::Press).map_err(|e| e.to_string())?; + enigo + .key(modifier, Direction::Press) + .map_err(|e| e.to_string())?; let press_v = enigo.key(Key::Unicode('v'), Direction::Click); let release_modifier = enigo.key(modifier, Direction::Release); if let Err(e) = release_modifier { diff --git a/openless -all/app/src-tauri/src/persistence.rs b/openless -all/app/src-tauri/src/persistence.rs index 2f1ecfd7..14245102 100644 --- a/openless -all/app/src-tauri/src/persistence.rs +++ b/openless -all/app/src-tauri/src/persistence.rs @@ -70,8 +70,7 @@ fn data_dir() -> Result { } fn ensure_dir(dir: &Path) -> Result<()> { - fs::create_dir_all(dir) - .with_context(|| format!("create dir failed: {}", dir.display()))?; + fs::create_dir_all(dir).with_context(|| format!("create dir failed: {}", dir.display()))?; Ok(()) } @@ -83,8 +82,7 @@ fn atomic_write(path: &Path, contents: &[u8]) -> Result<()> { let tmp_path = path.with_extension("tmp"); fs::write(&tmp_path, contents) .with_context(|| format!("write tmp failed: {}", tmp_path.display()))?; - fs::rename(&tmp_path, path) - .with_context(|| format!("rename failed: {}", path.display()))?; + fs::rename(&tmp_path, path).with_context(|| format!("rename failed: {}", path.display()))?; Ok(()) } @@ -92,8 +90,7 @@ fn read_or_default Deserialize<'de> + Default>(path: &Path) -> Resul if !path.exists() { return Ok(T::default()); } - let bytes = fs::read(path) - .with_context(|| format!("read failed: {}", path.display()))?; + let bytes = fs::read(path).with_context(|| format!("read failed: {}", path.display()))?; if bytes.is_empty() { return Ok(T::default()); } @@ -133,7 +130,9 @@ struct CredsRoot { providers: CredsProviders, } -fn credsroot_default_version() -> u32 { 1 } +fn credsroot_default_version() -> u32 { + 1 +} #[derive(Debug, Serialize, Deserialize, Clone)] struct CredsActive { @@ -152,8 +151,12 @@ impl Default for CredsActive { } } -fn creds_default_asr() -> String { "volcengine".into() } -fn creds_default_llm() -> String { "ark".into() } +fn creds_default_asr() -> String { + "volcengine".into() +} +fn creds_default_llm() -> String { + "ark".into() +} #[derive(Debug, Serialize, Deserialize, Default, Clone)] struct CredsProviders { @@ -215,7 +218,11 @@ impl CredsLlmEntry { && self.baseURL.as_deref().unwrap_or("").is_empty() && self.model.as_deref().unwrap_or("").is_empty() && self.temperature.is_none() - && self.extraHeaders.as_ref().map(|h| h.is_empty()).unwrap_or(true) + && self + .extraHeaders + .as_ref() + .map(|h| h.is_empty()) + .unwrap_or(true) } } @@ -225,19 +232,22 @@ fn credentials_path() -> Result { #[cfg(target_os = "windows")] { let appdata = std::env::var("APPDATA").context("APPDATA not set")?; - return Ok(PathBuf::from(appdata).join("OpenLess").join(LEGACY_CREDS_FILE)); + return Ok(PathBuf::from(appdata) + .join("OpenLess") + .join(LEGACY_CREDS_FILE)); } #[cfg(not(target_os = "windows"))] { let home = std::env::var("HOME").context("HOME not set")?; - Ok(PathBuf::from(home).join(LEGACY_CREDS_DIR).join(LEGACY_CREDS_FILE)) + Ok(PathBuf::from(home) + .join(LEGACY_CREDS_DIR) + .join(LEGACY_CREDS_FILE)) } } fn ensure_credentials_dir(path: &Path) -> Result<()> { if let Some(dir) = path.parent() { - fs::create_dir_all(dir) - .with_context(|| format!("create dir {} failed", dir.display()))?; + fs::create_dir_all(dir).with_context(|| format!("create dir {} failed", dir.display()))?; // 0700 on parent so other users can't peek #[cfg(unix)] { @@ -279,8 +289,7 @@ fn save_credentials(root: &CredsRoot) -> Result<()> { let json = serde_json::to_vec_pretty(&cleaned).context("encode credentials failed")?; let tmp = path.with_extension("json.tmp"); fs::write(&tmp, &json).with_context(|| format!("write {} failed", tmp.display()))?; - fs::rename(&tmp, &path) - .with_context(|| format!("rename to {} failed", path.display()))?; + fs::rename(&tmp, &path).with_context(|| format!("rename to {} failed", path.display()))?; #[cfg(unix)] { use std::os::unix::fs::PermissionsExt; @@ -294,7 +303,9 @@ fn lookup_account(root: &CredsRoot, account: CredentialAccount) -> Option| s.as_ref().filter(|v| !v.is_empty()).cloned(); match account { - CredentialAccount::VolcengineAppKey => asr.and_then(|e| pick(&e.appKey).or_else(|| pick(&e.apiKey))), + CredentialAccount::VolcengineAppKey => { + asr.and_then(|e| pick(&e.appKey).or_else(|| pick(&e.apiKey))) + } CredentialAccount::VolcengineAccessKey => asr.and_then(|e| pick(&e.accessKey)), CredentialAccount::VolcengineResourceId => asr.and_then(|e| pick(&e.resourceId)), CredentialAccount::ArkApiKey => llm.and_then(|e| pick(&e.apiKey)), @@ -570,7 +581,11 @@ impl CredentialsVault { pub fn set(account: CredentialAccount, value: &str) -> Result<()> { let mut root = load_credentials(); - let v = if value.is_empty() { None } else { Some(value.to_string()) }; + let v = if value.is_empty() { + None + } else { + Some(value.to_string()) + }; write_account(&mut root, account, v); save_credentials(&root) } @@ -593,4 +608,3 @@ impl CredentialsVault { } } } - diff --git a/openless -all/app/src-tauri/src/types.rs b/openless -all/app/src-tauri/src/types.rs index 7fdaa8c8..ef98afa6 100644 --- a/openless -all/app/src-tauri/src/types.rs +++ b/openless -all/app/src-tauri/src/types.rs @@ -71,7 +71,9 @@ pub struct DictionaryEntry { pub created_at: String, } -fn default_true() -> bool { true } +fn default_true() -> bool { + true +} #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -160,7 +162,7 @@ pub enum CapsuleState { #[serde(rename_all = "camelCase")] pub struct CapsulePayload { pub state: CapsuleState, - pub level: f32, // 0..1 RMS + pub level: f32, // 0..1 RMS pub elapsed_ms: u64, pub message: Option, pub inserted_chars: Option,