封装jsonrpc通信机制

This commit is contained in:
root
2025-07-10 22:26:29 +08:00
parent bda9eb1a6b
commit 920b0462b5
6 changed files with 441 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::python_executor::{execute_python_command, execute_python_with_events};
use crate::python_executor::{execute_python_command, execute_python_action_with_progress};
use tauri::AppHandle;
#[derive(Debug, Deserialize)]
@@ -50,17 +50,16 @@ 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,
];
let params = &[("--source_folder", request.source_folder.as_str())];
// Execute with progress monitoring via Tauri events
execute_python_with_events(app, &args, None, "template-import-progress").await
execute_python_action_with_progress(
app,
"python_core.services.template_manager",
"batch_import",
params,
"template-import-progress",
None,
).await
}
#[tauri::command]
@@ -112,18 +111,18 @@ pub async fn generate_video_with_progress(
prompt: String,
output_path: String,
) -> Result<String, String> {
let args = vec![
"-m".to_string(),
"python_core.ai_video.video_generator".to_string(),
"--image_path".to_string(),
image_path,
"--prompt".to_string(),
prompt,
"--output_path".to_string(),
output_path,
let params = &[
("--image_path", image_path.as_str()),
("--prompt", prompt.as_str()),
("--output_path", output_path.as_str()),
];
// Execute with progress monitoring via Tauri events
// Frontend can listen to "video-generation-progress" event
execute_python_with_events(app, &args, None, "video-generation-progress").await
execute_python_action_with_progress(
app,
"python_core.ai_video.video_generator",
"generate",
params,
"video-generation-progress",
None,
).await
}