后端代码优化

This commit is contained in:
xintaofei
2026-03-29 18:55:47 +08:00
parent 080a16f26c
commit a7f628ee21
10 changed files with 39 additions and 7 deletions

View File

@@ -8,13 +8,16 @@ use tauri::State;
use crate::acp::binary_cache;
use crate::acp::error::AcpError;
#[cfg(feature = "tauri-runtime")]
use crate::acp::manager::ConnectionManager;
use crate::acp::preflight::{self, PreflightResult};
use crate::acp::registry;
use crate::acp::types::{
AcpAgentInfo, AgentSkillContent, AgentSkillItem, AgentSkillLayout, AgentSkillLocation,
AgentSkillScope, AgentSkillsListResult, ConnectionInfo, ForkResultInfo, PromptInputBlock,
AgentSkillScope, AgentSkillsListResult,
};
#[cfg(feature = "tauri-runtime")]
use crate::acp::types::{ConnectionInfo, ForkResultInfo, PromptInputBlock};
use crate::db::service::agent_setting_service;
use crate::db::AppDatabase;
use crate::models::agent::AgentType;

View File

@@ -1,8 +1,12 @@
use std::collections::{HashMap, HashSet};
use crate::app_error::AppCommandError;
#[cfg(feature = "tauri-runtime")]
use crate::db::entities::conversation;
use crate::db::service::{conversation_service, folder_service, import_service};
use crate::db::service::{conversation_service, folder_service};
#[cfg(feature = "tauri-runtime")]
use crate::db::service::import_service;
#[cfg(feature = "tauri-runtime")]
use crate::db::AppDatabase;
use crate::models::*;
use crate::parsers::claude::ClaudeParser;

View File

@@ -1,10 +1,16 @@
#[cfg(feature = "tauri-runtime")]
use crate::db::error::DbError;
#[cfg(feature = "tauri-runtime")]
use crate::db::service::folder_command_service;
#[cfg(feature = "tauri-runtime")]
use crate::db::AppDatabase;
#[cfg(feature = "tauri-runtime")]
use crate::models::FolderCommandInfo;
use std::path::Path;
#[cfg(feature = "tauri-runtime")]
use tokio::sync::Mutex;
#[cfg(feature = "tauri-runtime")]
static BOOTSTRAP_FOLDER_COMMANDS_LOCK: Mutex<()> = Mutex::const_new(());
pub(crate) fn load_package_scripts_as_commands(folder_path: &str) -> Vec<(String, String)> {

View File

@@ -18,10 +18,13 @@ use walkdir::WalkDir;
use tauri::Manager;
use crate::app_error::AppCommandError;
#[cfg(feature = "tauri-runtime")]
use crate::db::error::DbError;
use crate::db::service::folder_service;
use crate::db::AppDatabase;
use crate::models::{FolderDetail, FolderHistoryEntry, GitCredentials, OpenedConversation};
use crate::models::GitCredentials;
#[cfg(feature = "tauri-runtime")]
use crate::models::{FolderDetail, FolderHistoryEntry, OpenedConversation};
use crate::web::event_bridge::EventEmitter;
/// Configure a git command for remote operations:

View File

@@ -4,12 +4,15 @@ use tauri::State;
use crate::app_error::AppCommandError;
use crate::db::service::app_metadata_service;
#[cfg(feature = "tauri-runtime")]
use crate::db::AppDatabase;
use crate::models::{SystemLanguageSettings, SystemProxySettings};
#[cfg(feature = "tauri-runtime")]
use crate::network::proxy;
const SYSTEM_PROXY_SETTINGS_KEY: &str = "system_proxy_settings";
const SYSTEM_LANGUAGE_SETTINGS_KEY: &str = "system_language_settings";
#[cfg(feature = "tauri-runtime")]
const LANGUAGE_SETTINGS_UPDATED_EVENT: &str = "app://language-settings-updated";
fn normalize_proxy_settings(

View File

@@ -6,9 +6,13 @@ use tauri::Manager;
use tauri::State;
use crate::git_credential;
#[cfg(feature = "tauri-runtime")]
use crate::terminal::error::TerminalError;
#[cfg(feature = "tauri-runtime")]
use crate::terminal::manager::{SpawnOptions, TerminalManager};
#[cfg(feature = "tauri-runtime")]
use crate::terminal::types::TerminalInfo;
#[cfg(feature = "tauri-runtime")]
use crate::web::event_bridge::EventEmitter;
/// Build extra env vars for the terminal session.

View File

@@ -4,12 +4,15 @@ use tauri::State;
use crate::app_error::AppCommandError;
use crate::db::service::app_metadata_service;
#[cfg(feature = "tauri-runtime")]
use crate::db::AppDatabase;
use crate::models::{
GitDetectResult, GitHubAccountsSettings, GitHubTokenValidation, GitSettings,
};
use crate::models::GitDetectResult;
#[cfg(feature = "tauri-runtime")]
use crate::models::GitHubAccountsSettings;
use crate::models::{GitHubTokenValidation, GitSettings};
const GIT_SETTINGS_KEY: &str = "git_settings";
#[cfg(feature = "tauri-runtime")]
const GITHUB_ACCOUNTS_KEY: &str = "github_accounts";
// ---------------------------------------------------------------------------
@@ -170,6 +173,7 @@ pub async fn update_git_settings(
// GitHub accounts
// ---------------------------------------------------------------------------
#[cfg(feature = "tauri-runtime")]
async fn load_github_accounts(
conn: &sea_orm::DatabaseConnection,
) -> Result<GitHubAccountsSettings, AppCommandError> {

View File

@@ -1,4 +1,5 @@
use std::ffi::{OsStr, OsString};
#[cfg(feature = "tauri-runtime")]
use std::path::PathBuf;
use std::process::Command;
@@ -88,6 +89,7 @@ where
/// child processes) can find node/npm/npx without any special handling.
///
/// Call once at startup, after `fix_path_env::fix()`.
#[cfg(feature = "tauri-runtime")]
pub fn ensure_node_in_path() {
// Already reachable — nothing to do.
if which::which("node").is_ok() {
@@ -107,6 +109,7 @@ pub fn ensure_node_in_path() {
/// Search common Node.js version manager directories for a `node` binary and
/// return the containing bin directory.
#[cfg(feature = "tauri-runtime")]
fn find_node_bin_dir(home: &std::path::Path) -> Option<PathBuf> {
let mut candidates: Vec<PathBuf> = Vec::new();
@@ -175,6 +178,7 @@ fn find_node_bin_dir(home: &std::path::Path) -> Option<PathBuf> {
}
/// Prepend a directory to the process `PATH` environment variable.
#[cfg(feature = "tauri-runtime")]
fn prepend_to_path(dir: &std::path::Path) {
let sep = if cfg!(windows) { ";" } else { ":" };
let current = std::env::var_os("PATH").unwrap_or_default();

View File

@@ -22,7 +22,7 @@ pub struct StartWebServerParams {
pub async fn start_web_server(
Extension(state): Extension<Arc<AppState>>,
Json(params): Json<StartWebServerParams>,
Json(_params): Json<StartWebServerParams>,
) -> Result<Json<WebServerInfo>, AppCommandError> {
// In web mode, the server is already running (this handler itself is served by it).
// This endpoint is mainly useful in Tauri mode. Return current status as a noop.

View File

@@ -122,6 +122,7 @@ pub fn get_local_addresses(port: u16) -> Vec<String> {
// ── Core logic (shared by Tauri commands and web handlers) ──
#[allow(dead_code)]
pub(crate) async fn do_start_web_server_with_state(
app_state: Arc<AppState>,
static_dir: PathBuf,