Mountain/Binary/IPC/ConfigurationDataCommand.rs
1//! # ConfigurationDataCommand
2//!
3//! Handles configuration data retrieval and saving for Wind frontend.
4//!
5//! ## RESPONSIBILITIES
6//!
7//! ### Configuration Data Access
8//! - Retrieve configuration data for Wind
9//! - Save configuration data from Wind
10//! - Validate configuration structure
11//! - Handle partial updates
12//!
13//! ## ARCHITECTURAL ROLE
14//!
15//! ### Position in Mountain
16//! - IPC wrapper command in Binary subsystem
17//! - Configuration data CRUD endpoint
18//!
19//! ### Dependencies
20//! - crate::IPC::ConfigurationBridge: Data persistence
21//! - tauri: IPC framework
22//! - serde_json: JSON serialization
23//!
24//! ### Dependents
25//! - Wind frontend: Gets and sets configuration data
26//! - Tauri IPC handler: Routes configuration operations
27//!
28//! ## SECURITY
29//!
30//! ### Considerations
31//! - Validate configuration structure on save
32//! - Sanitize user input to prevent injection
33//! - Prevent modification of protected keys
34//!
35//! ## PERFORMANCE
36//!
37//! ### Considerations
38//! - Configuration reads are cached when possible
39//! - Writes trigger persistence, may be slower
40//! - Consider debouncing save operations
41
42use serde_json::Value;
43use tauri::AppHandle;
44
45/// Get configuration data for Wind frontend.
46///
47/// Retrieves the current configuration data for display/editing in Wind.
48///
49/// # Arguments
50///
51/// * `app_handle` - Tauri application handle
52///
53/// # Returns
54///
55/// Returns configuration data as JSON, or an error string.
56///
57/// # Errors
58///
59/// Returns an error if:
60/// - Configuration cannot be loaded
61/// - File system errors occur
62#[tauri::command]
63pub async fn GetConfigurationData(app:AppHandle) -> Result<Value, String> {
64 crate::IPC::ConfigurationBridge::get_configuration_data(app).await
65}
66
67/// Save configuration data from Wind frontend.
68///
69/// Persists configuration data provided by the Wind frontend.
70///
71/// # Arguments
72///
73/// * `app` - Tauri application handle
74/// * `config_data` - JSON object containing configuration data to save
75///
76/// # Returns
77///
78/// Returns success or an error string.
79///
80/// # Errors
81///
82/// Returns an error if:
83/// - Configuration validation fails
84/// - File system errors occur when persisting
85#[tauri::command]
86pub async fn SaveConfigurationData(app:AppHandle, config_data:Value) -> Result<(), String> {
87 crate::IPC::ConfigurationBridge::save_configuration_data(app, config_data).await
88}