Mountain/Binary/IPC/InvokeCommand.rs
1//! # InvokeCommand
2//!
3//! Invokes IPC methods for Wind service communication.
4//!
5//! ## RESPONSIBILITIES
6//!
7//! ### Method Invocation
8//! - Accept method invocation requests from frontend
9//! - Delegate to WindServiceHandlers for processing
10//! - Return method execution results
11//! - Handle method parameters validation
12//!
13//! ## ARCHITECTURAL ROLE
14//!
15//! ### Position in Mountain
16//! - IPC wrapper command in Binary subsystem
17//! - Bridge to Wind service handlers
18//!
19//! ### Dependencies
20//! - crate::IPC::WindServiceHandlers: Method execution
21//! - tauri: IPC framework
22//! - serde_json: JSON serialization
23//!
24//! ### Dependents
25//! - Wind frontend: Invokes methods via this command
26//! - Tauri IPC handler: Routes invocation requests
27//!
28//! ## SECURITY
29//!
30//! ### Considerations
31//! - Validate method names to prevent unauthorized access
32//! - Sanitize method parameters before execution
33//! - Restrict access to privileged methods
34//!
35//! ## PERFORMANCE
36//!
37//! ### Considerations
38//! - Method execution varies by implementation
39//! - Consider async for long-running operations
40//! - Rate limiting may be needed for expensive operations
41
42use serde_json::Value;
43use tauri::AppHandle;
44
45/// Invoke IPC methods.
46///
47/// This command accepts method invocation requests from the Wind frontend
48/// and delegates them to the WindServiceHandlers for execution.
49///
50/// # Arguments
51///
52/// * `app_handle` - Tauri application handle
53/// * `method` - Name of the method to invoke
54/// * `params` - JSON object containing method parameters
55///
56/// # Returns
57///
58/// Returns the method execution result as JSON, or an error string.
59///
60/// # Errors
61///
62/// Returns an error if:
63/// - Method does not exist
64/// - Method execution fails
65/// - Parameters are invalid
66#[tauri::command]
67pub async fn MountainIPCInvoke(app_handle:AppHandle, method:String, params:Value) -> Result<Value, String> {
68 // Convert params to Vec<Value> - if params is an array use it, otherwise wrap
69 // in array
70 let args = if params.is_array() {
71 serde_json::from_value(params).map_err(|e| format!("Invalid params array: {}", e))?
72 } else {
73 vec![params]
74 };
75
76 crate::IPC::WindServiceHandlers::mountain_ipc_invoke(app_handle, method, args).await
77}