删除冗余导入,优化代码结构
This commit is contained in:
@@ -47,11 +47,18 @@ pub fn find_claude_binary(app_handle: &tauri::AppHandle) -> Result<String, Strin
|
|||||||
|row| row.get::<_, String>(0),
|
|row| row.get::<_, String>(0),
|
||||||
) {
|
) {
|
||||||
info!("Found stored claude path in database: {}", stored_path);
|
info!("Found stored claude path in database: {}", stored_path);
|
||||||
|
|
||||||
// Check if the path still exists and works
|
// 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();
|
let mut final_path = stored_path.clone();
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
let mut path_buf = PathBuf::from(&stored_path);
|
let mut path_buf = PathBuf::from(&stored_path);
|
||||||
|
|
||||||
// On Windows, if stored path exists but is not executable (shell script), try .cmd version
|
// On Windows, if stored path exists but is not executable (shell script), try .cmd version
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
if path_buf.exists() && !stored_path.ends_with(".cmd") && !stored_path.ends_with(".exe") {
|
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<String, Strin
|
|||||||
let cmd_path_buf = PathBuf::from(&cmd_path);
|
let cmd_path_buf = PathBuf::from(&cmd_path);
|
||||||
if cmd_path_buf.exists() {
|
if cmd_path_buf.exists() {
|
||||||
if let Ok(_) = get_claude_version(&cmd_path) {
|
if let Ok(_) = get_claude_version(&cmd_path) {
|
||||||
final_path = cmd_path.clone();
|
final_path = cmd_path;
|
||||||
path_buf = cmd_path_buf;
|
path_buf = cmd_path_buf;
|
||||||
info!("Using .cmd version instead of shell script: {}", cmd_path);
|
info!("Using .cmd version instead of shell script: {}", final_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if path_buf.exists() && path_buf.is_file() {
|
if path_buf.exists() && path_buf.is_file() {
|
||||||
return Ok(final_path);
|
return Ok(final_path);
|
||||||
} else {
|
} else {
|
||||||
warn!("Stored claude path no longer exists: {}", stored_path);
|
warn!("Stored claude path no longer exists: {}", stored_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check user preference
|
// Check user preference
|
||||||
let preference = conn.query_row(
|
let preference = conn.query_row(
|
||||||
"SELECT value FROM app_settings WHERE key = 'claude_installation_preference'",
|
"SELECT value FROM app_settings WHERE key = 'claude_installation_preference'",
|
||||||
[],
|
[],
|
||||||
|row| row.get::<_, String>(0),
|
|row| row.get::<_, String>(0),
|
||||||
).unwrap_or_else(|_| "system".to_string());
|
).unwrap_or_else(|_| "system".to_string());
|
||||||
|
|
||||||
info!("User preference for Claude installation: {}", preference);
|
info!("User preference for Claude installation: {}", preference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +213,7 @@ fn find_which_installations() -> Vec<ClaudeInstallation> {
|
|||||||
// Process each line (Windows 'where' can return multiple paths)
|
// Process each line (Windows 'where' can return multiple paths)
|
||||||
for line in output_str.lines() {
|
for line in output_str.lines() {
|
||||||
let mut path = line.trim().to_string();
|
let mut path = line.trim().to_string();
|
||||||
|
|
||||||
if path.is_empty() {
|
if path.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -445,10 +452,10 @@ fn get_claude_version(path: &str) -> Result<Option<String>, String> {
|
|||||||
/// Extract version string from command output
|
/// Extract version string from command output
|
||||||
fn extract_version_from_output(stdout: &[u8]) -> Option<String> {
|
fn extract_version_from_output(stdout: &[u8]) -> Option<String> {
|
||||||
let output_str = String::from_utf8_lossy(stdout);
|
let output_str = String::from_utf8_lossy(stdout);
|
||||||
|
|
||||||
// Debug log the raw output
|
// Debug log the raw output
|
||||||
debug!("Raw version output: {:?}", output_str);
|
debug!("Raw version output: {:?}", output_str);
|
||||||
|
|
||||||
// Use regex to directly extract version pattern (e.g., "1.0.41")
|
// Use regex to directly extract version pattern (e.g., "1.0.41")
|
||||||
// This pattern matches:
|
// This pattern matches:
|
||||||
// - One or more digits, followed by
|
// - One or more digits, followed by
|
||||||
@@ -458,7 +465,7 @@ fn extract_version_from_output(stdout: &[u8]) -> Option<String> {
|
|||||||
// - One or more digits
|
// - One or more digits
|
||||||
// - Optionally followed by pre-release/build metadata
|
// - 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()?;
|
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(captures) = version_regex.captures(&output_str) {
|
||||||
if let Some(version_match) = captures.get(1) {
|
if let Some(version_match) = captures.get(1) {
|
||||||
let version = version_match.as_str().to_string();
|
let version = version_match.as_str().to_string();
|
||||||
@@ -466,7 +473,7 @@ fn extract_version_from_output(stdout: &[u8]) -> Option<String> {
|
|||||||
return Some(version);
|
return Some(version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("No version found in output");
|
debug!("No version found in output");
|
||||||
None
|
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
|
/// This ensures commands like Claude can find Node.js and other dependencies
|
||||||
pub fn create_command_with_env(program: &str) -> Command {
|
pub fn create_command_with_env(program: &str) -> Command {
|
||||||
let mut cmd = Command::new(program);
|
let mut cmd = Command::new(program);
|
||||||
|
|
||||||
info!("Creating command for: {}", program);
|
info!("Creating command for: {}", program);
|
||||||
|
|
||||||
// Inherit essential environment variables from parent process
|
// Inherit essential environment variables from parent process
|
||||||
@@ -574,7 +581,7 @@ pub fn create_command_with_env(program: &str) -> Command {
|
|||||||
cmd.env(&key, &value);
|
cmd.env(&key, &value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log proxy-related environment variables for debugging
|
// Log proxy-related environment variables for debugging
|
||||||
info!("Command will use proxy settings:");
|
info!("Command will use proxy settings:");
|
||||||
if let Ok(http_proxy) = std::env::var("HTTP_PROXY") {
|
if let Ok(http_proxy) = std::env::var("HTTP_PROXY") {
|
||||||
|
@@ -5,7 +5,7 @@ use tauri::{AppHandle, Emitter, State};
|
|||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use anyhow::Result;
|
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};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@@ -45,7 +45,8 @@ import { SplitPane } from "@/components/ui/split-pane";
|
|||||||
import { WebviewPreview } from "./WebviewPreview";
|
import { WebviewPreview } from "./WebviewPreview";
|
||||||
import { FileExplorerPanelEnhanced } from "./FileExplorerPanelEnhanced";
|
import { FileExplorerPanelEnhanced } from "./FileExplorerPanelEnhanced";
|
||||||
import { GitPanelEnhanced } from "./GitPanelEnhanced";
|
import { GitPanelEnhanced } from "./GitPanelEnhanced";
|
||||||
import { FileEditorEnhanced } from "./FileEditorEnhanced";
|
// 动态导入 FileEditorEnhanced 以减少初始包大小
|
||||||
|
const FileEditorEnhanced = React.lazy(() => import("./FileEditorEnhanced"));
|
||||||
import { SlashCommandsManager } from "./SlashCommandsManager";
|
import { SlashCommandsManager } from "./SlashCommandsManager";
|
||||||
import type { ClaudeStreamMessage } from "./AgentExecution";
|
import type { ClaudeStreamMessage } from "./AgentExecution";
|
||||||
import { useVirtualizer } from "@tanstack/react-virtual";
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
||||||
@@ -1904,11 +1905,17 @@ export const ClaudeCodeSession: React.FC<ClaudeCodeSessionProps> = ({
|
|||||||
<div className={cn("h-full w-full", layout.activeView === 'terminal' ? 'hidden' : 'block')}>
|
<div className={cn("h-full w-full", layout.activeView === 'terminal' ? 'hidden' : 'block')}>
|
||||||
{layout.activeView === 'editor' && layout.editingFile ? (
|
{layout.activeView === 'editor' && layout.editingFile ? (
|
||||||
// 文件编辑器视图
|
// 文件编辑器视图
|
||||||
<FileEditorEnhanced
|
<React.Suspense fallback={
|
||||||
filePath={layout.editingFile}
|
<div className="flex items-center justify-center h-full">
|
||||||
onClose={closeFileEditor}
|
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
||||||
className="h-full"
|
</div>
|
||||||
/>
|
}>
|
||||||
|
<FileEditorEnhanced
|
||||||
|
filePath={layout.editingFile}
|
||||||
|
onClose={closeFileEditor}
|
||||||
|
className="h-full"
|
||||||
|
/>
|
||||||
|
</React.Suspense>
|
||||||
) : layout.activeView === 'preview' && layout.previewUrl ? (
|
) : layout.activeView === 'preview' && layout.previewUrl ? (
|
||||||
// 预览视图
|
// 预览视图
|
||||||
<SplitPane
|
<SplitPane
|
||||||
|
@@ -51,10 +51,17 @@ export default defineConfig(async () => ({
|
|||||||
'react-vendor': ['react', 'react-dom'],
|
'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'],
|
'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'],
|
'editor-vendor': ['@uiw/react-md-editor'],
|
||||||
|
'monaco-editor': ['monaco-editor', '@monaco-editor/react'],
|
||||||
'syntax-vendor': ['react-syntax-highlighter'],
|
'syntax-vendor': ['react-syntax-highlighter'],
|
||||||
|
// Animation and motion
|
||||||
|
'framer-motion': ['framer-motion'],
|
||||||
// Tauri and other utilities
|
// 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'],
|
'utils': ['date-fns', 'clsx', 'tailwind-merge'],
|
||||||
|
// Charts and visualization
|
||||||
|
'recharts': ['recharts'],
|
||||||
|
// Virtual scrolling
|
||||||
|
'virtual': ['@tanstack/react-virtual'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user