mxivideo/src-tauri/src/macros.rs

85 lines
2.1 KiB
Rust

/// Macros for creating Python commands with progress support
/// Create a Tauri command that executes a Python action with progress
///
/// This is a simplified version that works with manual parameter construction
#[macro_export]
macro_rules! python_action_command {
(
name: $name:ident,
module: $module:expr,
action: $action:expr,
event: $event:expr
) => {
#[tauri::command]
pub async fn $name(
app: tauri::AppHandle
) -> Result<String, String> {
$crate::python_executor::execute_python_action_with_progress(
app,
$module,
$action,
&[],
$event,
None,
).await
}
};
(
name: $name:ident,
module: $module:expr,
action: $action:expr,
event: $event:expr
) => {
#[tauri::command]
pub async fn $name(
app: tauri::AppHandle
) -> Result<String, String> {
$crate::python_executor::execute_python_action_with_progress(
app,
$module,
$action,
&[],
$event,
None,
).await
}
};
}
/// Helper macro to create simple Python action commands
///
/// # Example
/// ```rust
/// simple_python_command! {
/// name: get_all_templates,
/// module: "python_core.services.template_manager",
/// action: "get_templates",
/// event: "template-list-progress"
/// }
/// ```
#[macro_export]
macro_rules! simple_python_command {
(
name: $name:ident,
module: $module:expr,
action: $action:expr,
event: $event:expr
) => {
#[tauri::command]
pub async fn $name(app: tauri::AppHandle) -> Result<String, String> {
$crate::python_executor::execute_python_action_with_progress(
app,
$module,
$action,
&[],
$event,
None,
).await
}
};
}
// Macros are automatically available when the module is included