optimize: terminal spawn lifecycle to eliminate output race condition

Move PTY spawn from context layer to view layer so event subscription
happens before spawn, preventing loss of initial terminal output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
xintaofei
2026-04-02 13:55:38 +08:00
parent d0e0aad525
commit b2d10fa008
8 changed files with 143 additions and 60 deletions

View File

@@ -69,11 +69,14 @@ pub(crate) fn prepare_credential_env(
pub async fn terminal_spawn(
working_dir: String,
initial_command: Option<String>,
terminal_id: Option<String>,
manager: State<'_, TerminalManager>,
app_handle: tauri::AppHandle,
window: tauri::WebviewWindow,
) -> Result<String, TerminalError> {
let terminal_id = uuid::Uuid::new_v4().to_string();
let terminal_id = terminal_id
.filter(|id| !id.is_empty() && id.len() <= 256)
.unwrap_or_else(|| uuid::Uuid::new_v4().to_string());
let app_data_dir = app_handle
.path()