From ec04132303d1bddba4419a333dfc2ccfb92cada6 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Wed, 19 Nov 2025 01:16:19 +0800 Subject: [PATCH] style: apply code formatting and cleanup - Format TypeScript files with Prettier (App.tsx, EnvWarningBanner.tsx, formatters.ts) - Organize Rust imports and module order alphabetically - Add newline at end of JSON files (en.json, zh.json) - Update Cargo.lock for dependency changes --- src-tauri/Cargo.lock | 111 ++++++++++++++++++++++++ src-tauri/src/commands/env.rs | 4 +- src-tauri/src/commands/mod.rs | 4 +- src-tauri/src/deeplink.rs | 6 +- src-tauri/src/services/env_checker.rs | 9 +- src-tauri/src/services/env_manager.rs | 6 +- src/App.tsx | 23 +++-- src/components/env/EnvWarningBanner.tsx | 7 +- src/i18n/locales/en.json | 2 +- src/i18n/locales/zh.json | 2 +- src/utils/formatters.ts | 2 +- 11 files changed, 150 insertions(+), 26 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0663cc8..12a3653 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -613,6 +613,7 @@ dependencies = [ "serial_test", "tauri", "tauri-build", + "tauri-plugin-deep-link", "tauri-plugin-dialog", "tauri-plugin-log", "tauri-plugin-opener", @@ -625,6 +626,7 @@ dependencies = [ "tokio", "toml 0.8.2", "toml_edit 0.22.27", + "url", "winreg 0.52.0", "zip 2.4.2", ] @@ -711,6 +713,26 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom 0.2.16", + "once_cell", + "tiny-keccak", +] + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -821,6 +843,12 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + [[package]] name = "crypto-common" version = "0.1.6" @@ -1057,6 +1085,15 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "dlv-list" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" +dependencies = [ + "const-random", +] + [[package]] name = "downcast-rs" version = "1.2.1" @@ -1745,6 +1782,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "hashbrown" version = "0.16.0" @@ -1830,6 +1873,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573" + [[package]] name = "httparse" version = "1.10.1" @@ -2901,6 +2950,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-multimap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" +dependencies = [ + "dlv-list", + "hashbrown 0.14.5", +] + [[package]] name = "ordered-stream" version = "0.2.0" @@ -3756,6 +3815,16 @@ dependencies = [ "cc", ] +[[package]] +name = "rust-ini" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "796e8d2b6696392a43bea58116b667fb4c29727dc5abd27d6acf338bb4f688c7" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + [[package]] name = "rust_decimal" version = "1.38.0" @@ -4519,6 +4588,7 @@ dependencies = [ "gtk", "heck 0.5.0", "http", + "http-range", "jni", "libc", "log", @@ -4634,6 +4704,27 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-deep-link" +version = "2.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e82759f7c7d51de3cbde51c04b3f2332de52436ed84541182cd8944b04e9e73" +dependencies = [ + "dunce", + "plist", + "rust-ini", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "tauri-utils", + "thiserror 2.0.17", + "tracing", + "url", + "windows-registry", + "windows-result 0.3.4", +] + [[package]] name = "tauri-plugin-dialog" version = "2.4.0" @@ -4988,6 +5079,15 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinystr" version = "0.8.1" @@ -5917,6 +6017,17 @@ dependencies = [ "windows-link 0.1.3", ] +[[package]] +name = "windows-registry" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a9ed28765efc97bbc954883f4e6796c33a06546ebafacbabee9696967499e" +dependencies = [ + "windows-link 0.1.3", + "windows-result 0.3.4", + "windows-strings 0.4.2", +] + [[package]] name = "windows-result" version = "0.3.4" diff --git a/src-tauri/src/commands/env.rs b/src-tauri/src/commands/env.rs index e1b31a8..8cf9df9 100644 --- a/src-tauri/src/commands/env.rs +++ b/src-tauri/src/commands/env.rs @@ -1,5 +1,7 @@ use crate::services::env_checker::{check_env_conflicts as check_conflicts, EnvConflict}; -use crate::services::env_manager::{delete_env_vars as delete_vars, restore_from_backup, BackupInfo}; +use crate::services::env_manager::{ + delete_env_vars as delete_vars, restore_from_backup, BackupInfo, +}; /// Check environment variable conflicts for a specific app #[tauri::command] diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index 1a4ab63..a98da44 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -1,8 +1,8 @@ #![allow(non_snake_case)] mod config; -mod env; mod deeplink; +mod env; mod import_export; mod mcp; mod misc; @@ -13,8 +13,8 @@ mod settings; pub mod skill; pub use config::*; -pub use env::*; pub use deeplink::*; +pub use env::*; pub use import_export::*; pub use mcp::*; pub use misc::*; diff --git a/src-tauri/src/deeplink.rs b/src-tauri/src/deeplink.rs index 058e43e..86b6a17 100644 --- a/src-tauri/src/deeplink.rs +++ b/src-tauri/src/deeplink.rs @@ -233,11 +233,7 @@ fn build_provider_from_request( // - 去掉首尾下划线 // - 若结果为空,则使用 "custom" let clean_provider_name = { - let raw: String = request - .name - .chars() - .filter(|c| !c.is_control()) - .collect(); + let raw: String = request.name.chars().filter(|c| !c.is_control()).collect(); let lower = raw.to_lowercase(); let mut key: String = lower .chars() diff --git a/src-tauri/src/services/env_checker.rs b/src-tauri/src/services/env_checker.rs index 2a437ce..009b593 100644 --- a/src-tauri/src/services/env_checker.rs +++ b/src-tauri/src/services/env_checker.rs @@ -123,7 +123,9 @@ fn check_shell_configs(keywords: &[&str]) -> Result, String> { let trimmed = line.trim(); // Match patterns like: export VAR=value or VAR=value - if trimmed.starts_with("export ") || (!trimmed.starts_with('#') && trimmed.contains('=')) { + if trimmed.starts_with("export ") + || (!trimmed.starts_with('#') && trimmed.contains('=')) + { let export_line = trimmed.strip_prefix("export ").unwrap_or(trimmed); if let Some(eq_pos) = export_line.find('=') { @@ -134,7 +136,10 @@ fn check_shell_configs(keywords: &[&str]) -> Result, String> { if keywords.iter().any(|k| var_name.to_uppercase().contains(k)) { conflicts.push(EnvConflict { var_name: var_name.to_string(), - var_value: var_value.trim_matches('"').trim_matches('\'').to_string(), + var_value: var_value + .trim_matches('"') + .trim_matches('\'') + .to_string(), source_type: "file".to_string(), source_path: format!("{}:{}", file_path, line_num + 1), }); diff --git a/src-tauri/src/services/env_manager.rs b/src-tauri/src/services/env_manager.rs index 9136985..0ee46da 100644 --- a/src-tauri/src/services/env_manager.rs +++ b/src-tauri/src/services/env_manager.rs @@ -152,8 +152,7 @@ fn delete_single_env(conflict: &EnvConflict) -> Result<(), String> { /// Restore environment variables from backup pub fn restore_from_backup(backup_path: String) -> Result<(), String> { // Read backup file - let content = - fs::read_to_string(&backup_path).map_err(|e| format!("读取备份文件失败: {e}"))?; + let content = fs::read_to_string(&backup_path).map_err(|e| format!("读取备份文件失败: {e}"))?; let backup_info: BackupInfo = serde_json::from_str(&content).map_err(|e| format!("解析备份文件失败: {e}"))?; @@ -218,8 +217,7 @@ fn restore_single_env(conflict: &EnvConflict) -> Result<(), String> { content.push_str(&export_line); // Write back to file - fs::write(file_path, content) - .map_err(|e| format!("写入文件失败 {file_path}: {e}"))?; + fs::write(file_path, content).map_err(|e| format!("写入文件失败 {file_path}: {e}"))?; Ok(()) } diff --git a/src/App.tsx b/src/App.tsx index 3380b08..6402605 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -101,7 +101,10 @@ function App() { setShowEnvBanner(true); } } catch (error) { - console.error("[App] Failed to check environment conflicts on startup:", error); + console.error( + "[App] Failed to check environment conflicts on startup:", + error, + ); } }; @@ -118,17 +121,20 @@ function App() { // 合并新检测到的冲突 setEnvConflicts((prev) => { const existingKeys = new Set( - prev.map((c) => `${c.varName}:${c.sourcePath}`) + prev.map((c) => `${c.varName}:${c.sourcePath}`), ); const newConflicts = conflicts.filter( - (c) => !existingKeys.has(`${c.varName}:${c.sourcePath}`) + (c) => !existingKeys.has(`${c.varName}:${c.sourcePath}`), ); return [...prev, ...newConflicts]; }); setShowEnvBanner(true); } } catch (error) { - console.error("[App] Failed to check environment conflicts on app switch:", error); + console.error( + "[App] Failed to check environment conflicts on app switch:", + error, + ); } }; @@ -240,7 +246,10 @@ function App() { setShowEnvBanner(false); } } catch (error) { - console.error("[App] Failed to re-check conflicts after deletion:", error); + console.error( + "[App] Failed to re-check conflicts after deletion:", + error, + ); } }} /> @@ -371,8 +380,8 @@ function App() { message={ confirmDelete ? t("confirm.deleteProviderMessage", { - name: confirmDelete.name, - }) + name: confirmDelete.name, + }) : "" } onConfirm={() => void handleConfirmDelete()} diff --git a/src/components/env/EnvWarningBanner.tsx b/src/components/env/EnvWarningBanner.tsx index 3ae21d0..76a167f 100644 --- a/src/components/env/EnvWarningBanner.tsx +++ b/src/components/env/EnvWarningBanner.tsx @@ -198,7 +198,8 @@ export function EnvWarningBanner({ {t("env.field.value")}: {conflict.varValue}

- {t("env.field.source")}: {getSourceDescription(conflict)} + {t("env.field.source")}:{" "} + {getSourceDescription(conflict)}

@@ -247,7 +248,9 @@ export function EnvWarningBanner({ {t("env.confirm.title")} -

{t("env.confirm.message", { count: selectedConflicts.size })}

+

+ {t("env.confirm.message", { count: selectedConflicts.size })} +

{t("env.confirm.backupNotice")}

diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index e8c56cb..31c8068 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -710,4 +710,4 @@ "importSuccessDescription": "Provider \"{{name}}\" has been successfully imported", "importError": "Failed to import" } -} \ No newline at end of file +} diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.json index 9ff7776..19905a0 100644 --- a/src/i18n/locales/zh.json +++ b/src/i18n/locales/zh.json @@ -710,4 +710,4 @@ "importSuccessDescription": "供应商 \"{{name}}\" 已成功导入", "importError": "导入失败" } -} \ No newline at end of file +} diff --git a/src/utils/formatters.ts b/src/utils/formatters.ts index 70e3718..0f5a52c 100644 --- a/src/utils/formatters.ts +++ b/src/utils/formatters.ts @@ -35,7 +35,7 @@ export function parseSmartMcpJson(jsonText: string): { } // 如果是键值对片段("key": {...}),包装成完整对象 - if (trimmed.startsWith('"') && !trimmed.startsWith('{')) { + if (trimmed.startsWith('"') && !trimmed.startsWith("{")) { trimmed = `{${trimmed}}`; }