Mountain/Binary/IPC/WorkbenchConfigurationCommand.rs
1//! # WorkbenchConfigurationCommand
2//!
3//! Provides the initial workbench configuration to the Sky frontend via IPC.
4//!
5//! ## RESPONSIBILITIES
6//!
7//! ### Configuration Retrieval
8//! - Handle IPC requests for workbench configuration
9//! - Construct sandbox configuration from initialization data
10//! - Validate configuration construction with proper error handling
11//! - Return JSON configuration payload to frontend
12//!
13//! ## ARCHITECTURAL ROLE
14//!
15//! ### Position in Mountain
16//! - IPC bridge command in Binary subsystem
17//! - Frontend-facing API for initial workspace setup
18//!
19//! ### Dependencies
20//! - crate::ProcessManagement::InitializationData: Configuration construction
21//! - crate::ApplicationState: Application state management
22//! - tauri: IPC framework
23//! - serde_json: JSON serialization
24//! - log: Logging framework
25//!
26//! ### Dependents
27//! - Sky frontend: Requests workbench configuration on load
28//! - Tauri IPC handler: Routes requests to this command
29//!
30//! ## SECURITY
31//!
32//! ### Considerations
33//! - Configuration data may contain workspace paths; ensure they are validated
34//! - No user input is processed beyond initial workspace argument
35//! - Error messages should not leak sensitive information
36//!
37//! ## PERFORMANCE
38//!
39//! ### Considerations
40//! - Configuration construction involves file I/O; should be fast
41//! - Consider caching if configuration becomes expensive to compute
42//! - Async execution won't block main thread
43
44use std::sync::Arc;
45
46use log::debug;
47use tauri::{AppHandle, State};
48use serde_json::Value;
49
50use crate::{ApplicationState::ApplicationState, ProcessManagement::InitializationData};
51
52/// Provides the initial workbench configuration to the Sky frontend.
53///
54/// This command is called by the frontend during initialization to receive
55/// the sandbox configuration including workspace folders, settings, and
56/// other application state needed to bootstrap the UI.
57///
58/// # Arguments
59///
60/// * `ApplicationHandle` - Tauri application handle for accessing system
61/// resources
62/// * `State` - Global application state containing workspace information
63///
64/// # Returns
65///
66/// Returns a JSON object containing the workbench configuration on success,
67/// or a string error message on failure.
68///
69/// # Errors
70///
71/// Returns an error string if:
72/// - Configuration construction fails (file system errors, JSON parsing)
73/// - State locking fails (concurrent access issues)
74#[tauri::command]
75pub async fn MountainGetWorkbenchConfiguration(
76 ApplicationHandle:AppHandle,
77 State:State<'_, Arc<ApplicationState>>,
78) -> Result<Value, String> {
79 debug!("[IPC] [WorkbenchConfig] Request received.");
80
81 debug!("[IPC] [WorkbenchConfig] Constructing sandbox configuration...");
82
83 let Config = InitializationData::ConstructSandboxConfiguration(&ApplicationHandle, State.inner())
84 .await
85 .map_err(|Error| {
86 debug!("[IPC] [WorkbenchConfig] Failed: {}", Error);
87 Error.to_string()
88 })?;
89
90 debug!("[IPC] [WorkbenchConfig] Success. Returning payload.");
91
92 Ok(Config)
93}