From 50cce7a22c5314355b58a9838b7bbddbea27ae72 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Sun, 7 Sep 2025 23:23:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/claude_binary.rs | 35 +++++++++++++++++----------- src-tauri/src/commands/terminal.rs | 2 +- src/components/ClaudeCodeSession.tsx | 19 ++++++++++----- vite.config.ts | 9 ++++++- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src-tauri/src/claude_binary.rs b/src-tauri/src/claude_binary.rs index 315658c..7ca336c 100644 --- a/src-tauri/src/claude_binary.rs +++ b/src-tauri/src/claude_binary.rs @@ -47,11 +47,18 @@ pub fn find_claude_binary(app_handle: &tauri::AppHandle) -> Result(0), ) { info!("Found stored claude path in database: {}", stored_path); - + // Check if the path still exists and works + #[cfg(not(target_os = "windows"))] + let final_path = stored_path.clone(); + #[cfg(not(target_os = "windows"))] + let path_buf = PathBuf::from(&stored_path); + + #[cfg(target_os = "windows")] let mut final_path = stored_path.clone(); + #[cfg(target_os = "windows")] let mut path_buf = PathBuf::from(&stored_path); - + // On Windows, if stored path exists but is not executable (shell script), try .cmd version #[cfg(target_os = "windows")] if path_buf.exists() && !stored_path.ends_with(".cmd") && !stored_path.ends_with(".exe") { @@ -62,28 +69,28 @@ pub fn find_claude_binary(app_handle: &tauri::AppHandle) -> Result(0), ).unwrap_or_else(|_| "system".to_string()); - + info!("User preference for Claude installation: {}", preference); } } @@ -206,7 +213,7 @@ fn find_which_installations() -> Vec { // Process each line (Windows 'where' can return multiple paths) for line in output_str.lines() { let mut path = line.trim().to_string(); - + if path.is_empty() { continue; } @@ -445,10 +452,10 @@ fn get_claude_version(path: &str) -> Result, String> { /// Extract version string from command output fn extract_version_from_output(stdout: &[u8]) -> Option { let output_str = String::from_utf8_lossy(stdout); - + // Debug log the raw output debug!("Raw version output: {:?}", output_str); - + // Use regex to directly extract version pattern (e.g., "1.0.41") // This pattern matches: // - One or more digits, followed by @@ -458,7 +465,7 @@ fn extract_version_from_output(stdout: &[u8]) -> Option { // - One or more digits // - Optionally followed by pre-release/build metadata let version_regex = regex::Regex::new(r"(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?)").ok()?; - + if let Some(captures) = version_regex.captures(&output_str) { if let Some(version_match) = captures.get(1) { let version = version_match.as_str().to_string(); @@ -466,7 +473,7 @@ fn extract_version_from_output(stdout: &[u8]) -> Option { return Some(version); } } - + debug!("No version found in output"); None } @@ -546,7 +553,7 @@ fn compare_versions(a: &str, b: &str) -> Ordering { /// This ensures commands like Claude can find Node.js and other dependencies pub fn create_command_with_env(program: &str) -> Command { let mut cmd = Command::new(program); - + info!("Creating command for: {}", program); // Inherit essential environment variables from parent process @@ -574,7 +581,7 @@ pub fn create_command_with_env(program: &str) -> Command { cmd.env(&key, &value); } } - + // Log proxy-related environment variables for debugging info!("Command will use proxy settings:"); if let Ok(http_proxy) = std::env::var("HTTP_PROXY") { diff --git a/src-tauri/src/commands/terminal.rs b/src-tauri/src/commands/terminal.rs index 7041d02..9bfca01 100644 --- a/src-tauri/src/commands/terminal.rs +++ b/src-tauri/src/commands/terminal.rs @@ -5,7 +5,7 @@ use tauri::{AppHandle, Emitter, State}; use tokio::sync::Mutex; use uuid::Uuid; use anyhow::Result; -use portable_pty::{native_pty_system, CommandBuilder, PtySize, PtyPair, Child, MasterPty}; +use portable_pty::{native_pty_system, CommandBuilder, PtySize, Child, MasterPty}; use std::io::{Read, Write}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/components/ClaudeCodeSession.tsx b/src/components/ClaudeCodeSession.tsx index 9cd2424..bf76956 100644 --- a/src/components/ClaudeCodeSession.tsx +++ b/src/components/ClaudeCodeSession.tsx @@ -45,7 +45,8 @@ import { SplitPane } from "@/components/ui/split-pane"; import { WebviewPreview } from "./WebviewPreview"; import { FileExplorerPanelEnhanced } from "./FileExplorerPanelEnhanced"; import { GitPanelEnhanced } from "./GitPanelEnhanced"; -import { FileEditorEnhanced } from "./FileEditorEnhanced"; +// 动态导入 FileEditorEnhanced 以减少初始包大小 +const FileEditorEnhanced = React.lazy(() => import("./FileEditorEnhanced")); import { SlashCommandsManager } from "./SlashCommandsManager"; import type { ClaudeStreamMessage } from "./AgentExecution"; import { useVirtualizer } from "@tanstack/react-virtual"; @@ -1904,11 +1905,17 @@ export const ClaudeCodeSession: React.FC = ({
{layout.activeView === 'editor' && layout.editingFile ? ( // 文件编辑器视图 - + +
+
+ }> + + ) : layout.activeView === 'preview' && layout.previewUrl ? ( // 预览视图 ({ 'react-vendor': ['react', 'react-dom'], 'ui-vendor': ['@radix-ui/react-dialog', '@radix-ui/react-dropdown-menu', '@radix-ui/react-select', '@radix-ui/react-tabs', '@radix-ui/react-tooltip', '@radix-ui/react-switch', '@radix-ui/react-popover'], 'editor-vendor': ['@uiw/react-md-editor'], + 'monaco-editor': ['monaco-editor', '@monaco-editor/react'], 'syntax-vendor': ['react-syntax-highlighter'], + // Animation and motion + 'framer-motion': ['framer-motion'], // Tauri and other utilities - 'tauri': ['@tauri-apps/api', '@tauri-apps/plugin-dialog', '@tauri-apps/plugin-shell'], + 'tauri': ['@tauri-apps/api', '@tauri-apps/plugin-dialog', '@tauri-apps/plugin-shell', '@tauri-apps/plugin-fs', '@tauri-apps/plugin-clipboard-manager'], 'utils': ['date-fns', 'clsx', 'tailwind-merge'], + // Charts and visualization + 'recharts': ['recharts'], + // Virtual scrolling + 'virtual': ['@tanstack/react-virtual'], }, }, },