From aae64d4d041314b7c31e8372aed511b649c48df7 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Jul 2025 21:21:16 +0800 Subject: [PATCH] template upgrade --- src-tauri/src/commands/template.rs | 51 ++++++++++++++++++++++++++++++ src-tauri/src/lib.rs | 1 + 2 files changed, 52 insertions(+) diff --git a/src-tauri/src/commands/template.rs b/src-tauri/src/commands/template.rs index fbf0000..a4fa89e 100644 --- a/src-tauri/src/commands/template.rs +++ b/src-tauri/src/commands/template.rs @@ -1,11 +1,23 @@ use serde::{Deserialize, Serialize}; use crate::python_executor::execute_python_command; +use tauri::{AppHandle, Emitter}; #[derive(Debug, Deserialize)] pub struct BatchImportRequest { pub source_folder: String, } +#[derive(Debug, Serialize, Clone)] +pub struct ImportProgress { + pub step: String, + pub progress: f64, + pub message: String, + pub current_template: Option, + pub total_templates: Option, + pub processed_templates: Option, + pub timestamp: f64, +} + #[derive(Debug, Serialize)] pub struct TemplateInfo { pub id: String, @@ -39,6 +51,45 @@ pub async fn batch_import_templates(app: tauri::AppHandle, request: BatchImportR execute_python_command(app, &args, None).await } +#[tauri::command] +pub async fn batch_import_templates_with_progress( + app: AppHandle, + request: BatchImportRequest +) -> Result { + let args = vec![ + "-m".to_string(), + "python_core.services.template_manager".to_string(), + "--action".to_string(), + "batch_import".to_string(), + "--source_folder".to_string(), + request.source_folder, + ]; + + // Create a progress callback that emits events to the frontend + let app_clone = app.clone(); + let progress_callback = move |progress: ImportProgress| { + let _ = app_clone.emit("template-import-progress", &progress); + }; + + // Execute with progress monitoring + execute_python_command_with_progress(app, &args, None, progress_callback).await +} + +async fn execute_python_command_with_progress( + app: AppHandle, + args: &[String], + config: Option, + _progress_callback: F, +) -> Result +where + F: Fn(ImportProgress) + Send + 'static, +{ + // For now, we'll use the existing execute_python_command + // and parse progress from JSON-RPC notifications + // TODO: Enhance python_executor to support progress callbacks + execute_python_command(app, args, config).await +} + #[tauri::command] pub async fn get_templates(app: tauri::AppHandle) -> Result { let args = vec![ diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 09abf22..1e476d1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -37,6 +37,7 @@ pub fn run() { commands::select_folder, commands::open_folder, commands::batch_import_templates, + commands::batch_import_templates_with_progress, commands::get_templates, commands::get_template, commands::delete_template