From be7b7a2e61d235b1e5944cbc1eccdd79be51c812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 15 Sep 2026 19:58:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E5=8C=96=20DirectProject=20?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把历史末项读取和订阅初始化移入 spawn_blocking,避免同步命令阻塞。 --- .../src-tauri/src/commands.rs | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/commands.rs b/apps/ai-game-creator-shell/src-tauri/src/commands.rs index c3ba2ae6c..3bfb471b6 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/commands.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/commands.rs @@ -5245,23 +5245,27 @@ pub(crate) async fn read_direct_project_conversation( } #[tauri::command] -pub(crate) fn subscribe_direct_project_thread( +pub(crate) async fn subscribe_direct_project_thread( project_path: String, ) -> Result { - let root = Path::new(project_path.trim()); - enforce_project_permission_policy(root, "conversation.read")?; - let (canonical_root, _) = direct_codex_canonical_project_identity(root)?; - let thread_root = canonical_root - .to_str() - .and_then(|value| value.strip_prefix("\\\\?\\")) - .map(Path::new) - .unwrap_or(canonical_root.as_path()); - let thread_id = thread_root.to_string_lossy().into_owned(); - let mut bootstrap = subscribe_direct_thread(&thread_id); - if bootstrap.last_completed_item_id.is_none() { - bootstrap.last_completed_item_id = read_direct_project_last_item_id_at(root)?; - } - Ok(bootstrap) + tauri::async_runtime::spawn_blocking(move || { + let root = Path::new(project_path.trim()); + enforce_project_permission_policy(root, "conversation.read")?; + let (canonical_root, _) = direct_codex_canonical_project_identity(root)?; + let thread_root = canonical_root + .to_str() + .and_then(|value| value.strip_prefix("\\\\?\\")) + .map(Path::new) + .unwrap_or(canonical_root.as_path()); + let thread_id = thread_root.to_string_lossy().into_owned(); + let mut bootstrap = subscribe_direct_thread(&thread_id); + if bootstrap.last_completed_item_id.is_none() { + bootstrap.last_completed_item_id = read_direct_project_last_item_id_at(root)?; + } + Ok(bootstrap) + }) + .await + .map_err(|error| format!("订阅 DirectProject 线程后台任务失败:{error}"))? } #[tauri::command]