From a052af0060827432642d903ba17ec75724b7a56c Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Wed, 4 Feb 2026 10:44:45 +0800 Subject: [PATCH] style: format code and apply clippy lint fixes --- src-tauri/src/commands/misc.rs | 2 +- src-tauri/src/commands/mod.rs | 4 +- src-tauri/src/lib.rs | 2 +- .../src/session_manager/providers/claude.rs | 14 ++---- .../src/session_manager/providers/codex.rs | 23 +++------- .../src/session_manager/providers/utils.rs | 6 +-- src-tauri/src/session_manager/terminal/mod.rs | 14 +++--- src/App.tsx | 44 ++++++++++--------- src/components/common/AppCountBar.tsx | 5 ++- src/components/common/AppToggleGroup.tsx | 14 +++--- src/components/common/ListItemRow.tsx | 5 ++- src/components/mcp/UnifiedMcpPanel.tsx | 9 +++- src/components/sessions/SessionItem.tsx | 4 +- .../sessions/SessionManagerPage.tsx | 28 ++++++------ .../sessions/SessionMessageItem.tsx | 2 +- src/components/sessions/SessionToc.tsx | 4 +- src/components/sessions/utils.ts | 9 ++-- src/components/skills/UnifiedSkillsPanel.tsx | 19 ++++---- src/components/ui/scroll-area.tsx | 2 +- src/components/ui/tooltip.tsx | 2 +- src/config/appConfig.tsx | 33 ++++++++++---- src/hooks/useSessionSearch.ts | 4 +- src/lib/api/sessions.ts | 2 +- src/lib/api/skills.ts | 11 +---- 24 files changed, 135 insertions(+), 127 deletions(-) diff --git a/src-tauri/src/commands/misc.rs b/src-tauri/src/commands/misc.rs index 9a75b0e1c..8e6da2bb4 100644 --- a/src-tauri/src/commands/misc.rs +++ b/src-tauri/src/commands/misc.rs @@ -755,7 +755,7 @@ fn launch_macos_open_app( let output = cmd .output() - .map_err(|e| format!("启动 {} 失败: {e}", app_name))?; + .map_err(|e| format!("启动 {app_name} 失败: {e}"))?; if !output.status.success() { let stderr = String::from_utf8_lossy(&output.stderr); diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index df5e47d25..ff81fde2e 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -12,8 +12,8 @@ mod plugin; mod prompt; mod provider; mod proxy; -mod settings; mod session_manager; +mod settings; pub mod skill; mod stream_check; mod usage; @@ -30,8 +30,8 @@ pub use plugin::*; pub use prompt::*; pub use provider::*; pub use proxy::*; -pub use settings::*; pub use session_manager::*; +pub use settings::*; pub use skill::*; pub use stream_check::*; pub use usage::*; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f244e0506..5dd10a152 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -20,8 +20,8 @@ mod prompt_files; mod provider; mod provider_defaults; mod proxy; -mod session_manager; mod services; +mod session_manager; mod settings; mod store; mod tray; diff --git a/src-tauri/src/session_manager/providers/claude.rs b/src-tauri/src/session_manager/providers/claude.rs index 48101d3e0..b953c015d 100644 --- a/src-tauri/src/session_manager/providers/claude.rs +++ b/src-tauri/src/session_manager/providers/claude.rs @@ -55,17 +55,12 @@ pub fn load_messages(path: &Path) -> Result, String> { .and_then(Value::as_str) .unwrap_or("unknown") .to_string(); - let content = message - .get("content") - .map(extract_text) - .unwrap_or_default(); + let content = message.get("content").map(extract_text).unwrap_or_default(); if content.trim().is_empty() { continue; } - let ts = value - .get("timestamp") - .and_then(parse_timestamp_to_ms); + let ts = value.get("timestamp").and_then(parse_timestamp_to_ms); messages.push(SessionMessage { role, content, ts }); } @@ -127,10 +122,7 @@ fn parse_session(path: &Path) -> Option { None => continue, }; - let text = message - .get("content") - .map(extract_text) - .unwrap_or_default(); + let text = message.get("content").map(extract_text).unwrap_or_default(); if text.trim().is_empty() { continue; } diff --git a/src-tauri/src/session_manager/providers/codex.rs b/src-tauri/src/session_manager/providers/codex.rs index 4cff72915..6c2b62b58 100644 --- a/src-tauri/src/session_manager/providers/codex.rs +++ b/src-tauri/src/session_manager/providers/codex.rs @@ -2,8 +2,8 @@ use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::{Path, PathBuf}; -use serde_json::Value; use regex::Regex; +use serde_json::Value; use crate::codex_config::get_codex_config_dir; use crate::session_manager::{SessionMessage, SessionMeta}; @@ -60,17 +60,12 @@ pub fn load_messages(path: &Path) -> Result, String> { .and_then(Value::as_str) .unwrap_or("unknown") .to_string(); - let content = payload - .get("content") - .map(extract_text) - .unwrap_or_default(); + let content = payload.get("content").map(extract_text).unwrap_or_default(); if content.trim().is_empty() { continue; } - let ts = value - .get("timestamp") - .and_then(parse_timestamp_to_ms); + let ts = value.get("timestamp").and_then(parse_timestamp_to_ms); messages.push(SessionMessage { role, content, ts }); } @@ -139,10 +134,7 @@ fn parse_session(path: &Path) -> Option { continue; } - let text = payload - .get("content") - .map(extract_text) - .unwrap_or_default(); + let text = payload.get("content").map(extract_text).unwrap_or_default(); if text.trim().is_empty() { continue; } @@ -174,10 +166,9 @@ fn parse_session(path: &Path) -> Option { fn infer_session_id_from_filename(path: &Path) -> Option { let file_name = path.file_name()?.to_string_lossy(); - let re = Regex::new( - r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", - ) - .ok()?; + let re = + Regex::new(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}") + .ok()?; re.find(&file_name).map(|mat| mat.as_str().to_string()) } diff --git a/src-tauri/src/session_manager/providers/utils.rs b/src-tauri/src/session_manager/providers/utils.rs index 5e8c43877..76408ea35 100644 --- a/src-tauri/src/session_manager/providers/utils.rs +++ b/src-tauri/src/session_manager/providers/utils.rs @@ -13,7 +13,7 @@ pub fn extract_text(content: &Value) -> String { Value::String(text) => text.to_string(), Value::Array(items) => items .iter() - .filter_map(|item| extract_text_from_item(item)) + .filter_map(extract_text_from_item) .filter(|text| !text.trim().is_empty()) .collect::>() .join("\n"), @@ -68,10 +68,10 @@ pub fn path_basename(value: &str) -> Option { if trimmed.is_empty() { return None; } - let normalized = trimmed.trim_end_matches(|c| c == '/' || c == '\\'); + let normalized = trimmed.trim_end_matches(['/', '\\']); let last = normalized .split(['/', '\\']) - .last() + .next_back() .filter(|segment| !segment.is_empty())?; Some(last.to_string()) } diff --git a/src-tauri/src/session_manager/terminal/mod.rs b/src-tauri/src/session_manager/terminal/mod.rs index 799fa6552..f4d93adda 100644 --- a/src-tauri/src/session_manager/terminal/mod.rs +++ b/src-tauri/src/session_manager/terminal/mod.rs @@ -32,9 +32,8 @@ fn launch_macos_terminal(command: &str, cwd: Option<&str>) -> Result<(), String> let script = format!( r#"tell application "Terminal" activate - do script "{}" -end tell"#, - escaped + do script "{escaped}" +end tell"# ); let status = Command::new("osascript") @@ -59,10 +58,9 @@ fn launch_iterm(command: &str, cwd: Option<&str>) -> Result<(), String> { activate create window with default profile tell current session of current window - write text "{}" + write text "{escaped}" end tell -end tell"#, - escaped +end tell"# ); let status = Command::new("osascript") @@ -88,7 +86,7 @@ fn launch_ghostty(command: &str, cwd: Option<&str>) -> Result<(), String> { // Note: The user's error output didn't show the working dir arg failure, so we assume flag is okay or we stick to compatible ones. // Documentation says --working-directory is supported in CLI. let work_dir_arg = if let Some(dir) = cwd { - format!("--working-directory={}", dir) + format!("--working-directory={dir}") } else { "".to_string() }; @@ -251,7 +249,7 @@ fn build_shell_command(command: &str, cwd: Option<&str>) -> String { fn shell_escape(value: &str) -> String { let escaped = value.replace('\\', "\\\\").replace('"', "\\\""); - format!("\"{}\"", escaped) + format!("\"{escaped}\"") } fn escape_osascript(value: &str) -> String { diff --git a/src/App.tsx b/src/App.tsx index a11487d2f..de9c6881c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -175,7 +175,7 @@ function App() { // 当前应用代理实际使用的供应商 ID(从 active_targets 中获取) const activeProviderId = useMemo(() => { const target = proxyStatus?.active_targets?.find( - (t) => t.app_type === activeApp + (t) => t.app_type === activeApp, ); return target?.provider_id; }, [proxyStatus?.active_targets, activeApp]); @@ -208,7 +208,7 @@ function App() { if (event.appType === activeApp) { await refetch(); } - } + }, ); } catch (error) { console.error("[App] Failed to subscribe provider switch event", error); @@ -242,7 +242,7 @@ function App() { } catch (error) { console.error( "[App] Failed to subscribe universal-provider-synced event", - error + error, ); } }; @@ -270,7 +270,7 @@ function App() { } catch (error) { console.error( "[App] Failed to check environment conflicts on startup:", - error + error, ); } }; @@ -286,7 +286,7 @@ function App() { if (migrated) { toast.success( t("migration.success", { defaultValue: "配置迁移成功" }), - { closeButton: true } + { closeButton: true }, ); } } catch (error) { @@ -302,7 +302,7 @@ function App() { const checkSkillsMigration = async () => { try { const result = await invoke<{ count: number; error?: string } | null>( - "get_skills_migration_result" + "get_skills_migration_result", ); if (result?.error) { toast.error(t("migration.skillsFailed"), { @@ -336,10 +336,10 @@ 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]; }); @@ -351,7 +351,7 @@ function App() { } catch (error) { console.error( "[App] Failed to check environment conflicts on app switch:", - error + error, ); } }; @@ -433,7 +433,7 @@ function App() { t("notifications.removeFromConfigSuccess", { defaultValue: "已从配置移除", }), - { closeButton: true } + { closeButton: true }, ); } else { // Delete from database @@ -445,7 +445,7 @@ function App() { // Generate a unique provider key for OpenCode duplication const generateUniqueOpencodeKey = ( originalKey: string, - existingKeys: string[] + existingKeys: string[], ): string => { const baseKey = `${originalKey}-copy`; @@ -487,7 +487,7 @@ function App() { const existingKeys = Object.keys(providers); duplicatedProvider.providerKey = generateUniqueOpencodeKey( provider.id, - existingKeys + existingKeys, ); } @@ -498,7 +498,7 @@ function App() { (p) => p.sortIndex !== undefined && p.sortIndex >= newSortIndex! && - p.id !== provider.id + p.id !== provider.id, ) .map((p) => ({ id: p.id, @@ -514,7 +514,7 @@ function App() { toast.error( t("provider.sortUpdateFailed", { defaultValue: "排序更新失败", - }) + }), ); return; // 如果排序更新失败,不继续添加 } @@ -532,7 +532,7 @@ function App() { toast.success( t("provider.terminalOpened", { defaultValue: "终端已打开", - }) + }), ); } catch (error) { console.error("[App] Failed to open terminal", error); @@ -540,7 +540,7 @@ function App() { toast.error( t("provider.terminalOpenFailed", { defaultValue: "打开终端失败", - }) + (errorMessage ? `: ${errorMessage}` : "") + }) + (errorMessage ? `: ${errorMessage}` : ""), ); } }; @@ -721,7 +721,7 @@ function App() { } catch (error) { console.error( "[App] Failed to re-check conflicts after deletion:", - error + error, ); } }} @@ -755,7 +755,9 @@ function App() { size="icon" onClick={() => setCurrentView( - currentView === "skillsDiscovery" ? "skills" : "providers" + currentView === "skillsDiscovery" + ? "skills" + : "providers", ) } className="mr-2 rounded-lg" @@ -788,7 +790,7 @@ function App() { "text-xl font-semibold transition-colors", isProxyRunning && isCurrentAppTakeoverActive ? "text-emerald-500 hover:text-emerald-600 dark:text-emerald-400 dark:hover:text-emerald-300" - : "text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300" + : "text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300", )} > CC Switch @@ -934,7 +936,7 @@ function App() { "transition-all duration-300 ease-in-out overflow-hidden", isCurrentAppTakeoverActive ? "opacity-100 max-w-[100px] scale-100" - : "opacity-0 max-w-0 scale-75 pointer-events-none" + : "opacity-0 max-w-0 scale-75 pointer-events-none", )} > @@ -962,7 +964,7 @@ function App() { "transition-all duration-200 ease-in-out overflow-hidden", hasSkillsSupport ? "opacity-100 w-8 scale-100 px-2" - : "opacity-0 w-0 scale-75 pointer-events-none px-0 -ml-1" + : "opacity-0 w-0 scale-75 pointer-events-none px-0 -ml-1", )} title={t("skills.manage")} > diff --git a/src/components/common/AppCountBar.tsx b/src/components/common/AppCountBar.tsx index 3045e68ed..295d8e24c 100644 --- a/src/components/common/AppCountBar.tsx +++ b/src/components/common/AppCountBar.tsx @@ -8,7 +8,10 @@ interface AppCountBarProps { counts: Record; } -export const AppCountBar: React.FC = ({ totalLabel, counts }) => { +export const AppCountBar: React.FC = ({ + totalLabel, + counts, +}) => { return (
diff --git a/src/components/common/AppToggleGroup.tsx b/src/components/common/AppToggleGroup.tsx index 27d77bd7c..0f18f7fc9 100644 --- a/src/components/common/AppToggleGroup.tsx +++ b/src/components/common/AppToggleGroup.tsx @@ -12,7 +12,10 @@ interface AppToggleGroupProps { onToggle: (app: AppId, enabled: boolean) => void; } -export const AppToggleGroup: React.FC = ({ apps, onToggle }) => { +export const AppToggleGroup: React.FC = ({ + apps, + onToggle, +}) => { return (
{APP_IDS.map((app) => { @@ -25,16 +28,17 @@ export const AppToggleGroup: React.FC = ({ apps, onToggle } type="button" onClick={() => onToggle(app, !enabled)} className={`w-7 h-7 rounded-lg flex items-center justify-center transition-all ${ - enabled - ? activeClass - : "opacity-35 hover:opacity-70" + enabled ? activeClass : "opacity-35 hover:opacity-70" }`} > {icon} -

{label}{enabled ? " ✓" : ""}

+

+ {label} + {enabled ? " ✓" : ""} +

); diff --git a/src/components/common/ListItemRow.tsx b/src/components/common/ListItemRow.tsx index 8d0c54fd4..90ec303bd 100644 --- a/src/components/common/ListItemRow.tsx +++ b/src/components/common/ListItemRow.tsx @@ -5,7 +5,10 @@ interface ListItemRowProps { children: React.ReactNode; } -export const ListItemRow: React.FC = ({ isLast, children }) => { +export const ListItemRow: React.FC = ({ + isLast, + children, +}) => { return (
= ({
- {name} + + {name} + {docsUrl && (
{description && ( -

+

{description}

)} diff --git a/src/components/sessions/SessionItem.tsx b/src/components/sessions/SessionItem.tsx index 14bf601de..15de67e65 100644 --- a/src/components/sessions/SessionItem.tsx +++ b/src/components/sessions/SessionItem.tsx @@ -40,7 +40,7 @@ export function SessionItem({ "w-full text-left rounded-lg px-3 py-2.5 transition-all group", isSelected ? "bg-primary/10 border border-primary/30" - : "hover:bg-muted/60 border border-transparent" + : "hover:bg-muted/60 border border-transparent", )} >
@@ -62,7 +62,7 @@ export function SessionItem({
diff --git a/src/components/sessions/SessionManagerPage.tsx b/src/components/sessions/SessionManagerPage.tsx index b446b2e15..ad0825e55 100644 --- a/src/components/sessions/SessionManagerPage.tsx +++ b/src/components/sessions/SessionManagerPage.tsx @@ -56,7 +56,7 @@ export function SessionManagerPage() { const messagesEndRef = useRef(null); const messageRefs = useRef>(new Map()); const [activeMessageIndex, setActiveMessageIndex] = useState( - null + null, ); const [tocDialogOpen, setTocDialogOpen] = useState(false); const [isSearchOpen, setIsSearchOpen] = useState(false); @@ -83,7 +83,7 @@ export function SessionManagerPage() { } const exists = selectedKey ? filteredSessions.some( - (session) => getSessionKey(session) === selectedKey + (session) => getSessionKey(session) === selectedKey, ) : false; if (!exists) { @@ -95,7 +95,7 @@ export function SessionManagerPage() { if (!selectedKey) return null; return ( filteredSessions.find( - (session) => getSessionKey(session) === selectedKey + (session) => getSessionKey(session) === selectedKey, ) || null ); }, [filteredSessions, selectedKey]); @@ -103,7 +103,7 @@ export function SessionManagerPage() { const { data: messages = [], isLoading: isLoadingMessages } = useSessionMessagesQuery( selectedSession?.providerId, - selectedSession?.sourcePath + selectedSession?.sourcePath, ); // 提取用户消息用于目录 @@ -147,7 +147,7 @@ export function SessionManagerPage() { } catch (error) { toast.error( extractErrorMessage(error) || - t("common.error", { defaultValue: "Copy failed" }) + t("common.error", { defaultValue: "Copy failed" }), ); } }; @@ -158,7 +158,7 @@ export function SessionManagerPage() { if (!isMac()) { await handleCopy( selectedSession.resumeCommand, - t("sessionManager.resumeCommandCopied") + t("sessionManager.resumeCommandCopied"), ); return; } @@ -240,14 +240,16 @@ export function SessionManagerPage() { setIsSearchOpen(true); setTimeout( () => searchInputRef.current?.focus(), - 0 + 0, ); }} > - {t("sessionManager.searchSessions")} + + {t("sessionManager.searchSessions")} +