style(tauri): rustfmt 整理后端模块

This commit is contained in:
baiqing committed 2026-04-29 21:21:08 +08:00
1 parent 67ff808c9c
commit c6dac023c9
5 files changed
+46 -33

No files matched your search

@@ -449,10 +449,8 @@ impl AudioConsumer for VolcengineStreamingASR {
if st.pending_audio.len() < TARGET_AUDIO_CHUNK_BYTES {
None
} else {
let chunk: Vec<u8> = st
.pending_audio
.drain(..TARGET_AUDIO_CHUNK_BYTES)
.collect();
let chunk: Vec<u8> =
st.pending_audio.drain(..TARGET_AUDIO_CHUNK_BYTES).collect();
let seq = st.next_sequence;
st.next_sequence += 1;
st.bytes_sent += chunk.len();
+4 -7
View File
@@ -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<HotkeyEvent>,
) -> anyhow::Result<Self> {
pub fn start(binding: HotkeyBinding, tx: Sender<HotkeyEvent>) -> anyhow::Result<Self> {
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,
}
}
+3 -1
View File
@@ -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 {
+33 -19
View File
@@ -70,8 +70,7 @@ fn data_dir() -> Result<PathBuf> {
}
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<T: for<'de> 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<PathBuf> {
#[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<String
let llm = root.providers.llm.get(&root.active.llm);
let pick = |s: &Option<String>| 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 {
}
}
}
+4 -2
View File
@@ -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<String>,
pub inserted_chars: Option<u32>,