template upgrade

This commit is contained in:
root 2025-07-10 21:21:16 +08:00
parent 7edf8b7335
commit aae64d4d04
2 changed files with 52 additions and 0 deletions

View File

@ -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<String>,
pub total_templates: Option<i32>,
pub processed_templates: Option<i32>,
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<String, String> {
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<F>(
app: AppHandle,
args: &[String],
config: Option<crate::python_executor::PythonExecutorConfig>,
_progress_callback: F,
) -> Result<String, String>
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<String, String> {
let args = vec![

View File

@ -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