template upgrade
This commit is contained in:
parent
7edf8b7335
commit
aae64d4d04
|
|
@ -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![
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue