diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs index a2f0728c4..00221e9a8 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/persistence.rs @@ -159,6 +159,12 @@ pub fn read_separation_state(path: &Path) -> Result { Ok(state) } +pub async fn read_separation_state_async(path: PathBuf) -> Result { + tokio::task::spawn_blocking(move || read_separation_state(&path)) + .await + .map_err(|error| format!("读取 separation state 任务失败:{error}"))? +} + pub fn separation_dto(state: &SeparationState) -> SeparationDTO { app_log!( "ui_separation.dto bound_nodes={} problematic_nodes={} remaining_trees={}", diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs index fb1c1e4dd..7a24146fc 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/workflow/mod.rs @@ -9,7 +9,7 @@ pub use patch::apply_batch_patch; use self::batch::next_image_batch_with_size; use super::model::*; use super::persistence::{ - project_relative_path, read_separation_state, separation_dto, separation_sidecar_dir, + project_relative_path, read_separation_state_async, separation_dto, separation_sidecar_dir, separation_state_path, write_separation_state, }; use super::prompt::gen_extract_prompt; @@ -42,7 +42,13 @@ pub(crate) async fn separate_ui_impl( ); error })?; - fs::create_dir_all(&sidecar).map_err(|error| { + tokio::task::spawn_blocking({ + let sidecar = sidecar.clone(); + move || fs::create_dir_all(sidecar) + }) + .await + .map_err(|error| format!("创建 separation sidecar 任务失败:{error}"))? + .map_err(|error| { app_log!( "ui_separation.error stage=sidecar_create asset_id={} error={error}", asset_id @@ -53,13 +59,15 @@ pub(crate) async fn separate_ui_impl( let restored = state_path.exists(); let mut separation = if restored { app_log!("ui_separation.state_restore.start asset_id={asset_id}"); - read_separation_state(&state_path).map_err(|error| { - app_log!( - "ui_separation.error stage=state_restore asset_id={} error={error}", - asset_id - ); - error - })? + read_separation_state_async(state_path.clone()) + .await + .map_err(|error| { + app_log!( + "ui_separation.error stage=state_restore asset_id={} error={error}", + asset_id + ); + error + })? } else { app_log!("ui_separation.state_construct.start asset_id={asset_id}"); super::tree::construct_separation_state(&state)