Mountain/Binary/IPC/
MessageReceiveCommand.rs

1//! # MessageReceiveCommand
2//!
3//! Handles receiving messages from Wind through IPC.
4//!
5//! ## RESPONSIBILITIES
6//!
7//! ### Message Reception
8//! - Receive JSON messages from Wind frontend
9//! - Parse and validate message structure
10//! - Delegate to TauriIPCServer for message processing
11//! - Return success/error response to caller
12//!
13//! ## ARCHITECTURAL ROLE
14//!
15//! ### Position in Mountain
16//! - IPC wrapper command in Binary subsystem
17//! - Bridge between frontend and IPC server
18//!
19//! ### Dependencies
20//! - crate::IPC::TauriIPCServer: Message processing
21//! - tauri: IPC framework
22//! - serde_json: JSON parsing
23//!
24//! ### Dependents
25//! - Wind frontend: Sends messages via this command
26//! - Tauri IPC handler: Routes messages to this command
27//!
28//! ## SECURITY
29//!
30//! ### Considerations
31//! - Validate JSON structure before processing
32//! - Malformed JSON should not crash the application
33//! - Messages may contain user input; proper parsing required
34//!
35//! ## PERFORMANCE
36//!
37//! ### Considerations
38//! - JSON parsing has some overhead but is fast for typical messages
39//! - Async execution doesn't block main thread
40//! - Consider message batching for high-frequency updates
41
42use serde_json::Value;
43use tauri::AppHandle;
44
45/// Receive messages from Wind through IPC.
46///
47/// This command accepts JSON messages from the Wind frontend and delegates
48/// them to the TauriIPCServer for processing. The message is first parsed
49/// to ensure it has the correct structure.
50///
51/// # Arguments
52///
53/// * `app_handle` - Tauri application handle
54/// * `message` - JSON value containing the message from Wind
55///
56/// # Returns
57///
58/// Returns a JSON response on success, or an error string on failure.
59///
60/// # Errors
61///
62/// Returns an error if:
63/// - JSON message cannot be parsed into the expected structure
64/// - TauriIPCServer processing fails
65#[tauri::command]
66pub async fn MountainIPCReceiveMessage(app_handle:AppHandle, message:Value) -> Result<Value, String> {
67	crate::IPC::TauriIPCServer::mountain_ipc_receive_message(
68		app_handle,
69		serde_json::from_value(message).map_err(|e| e.to_string())?,
70	)
71	.await?;
72	Ok(Value::Null)
73}