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 tauri::{AppHandle, State};
47use serde_json::Value;
48
49use crate::{
50 ApplicationState::State::ApplicationState::ApplicationState,
51 ProcessManagement::InitializationData,
52 dev_log,
53};
54
55/// Provides the initial workbench configuration to the Sky frontend.
56///
57/// This command is called by the frontend during initialization to receive
58/// the sandbox configuration including workspace folders, settings, and
59/// other application state needed to bootstrap the UI.
60///
61/// # Arguments
62///
63/// * `ApplicationHandle` - Tauri application handle for accessing system
64/// resources
65/// * `State` - Global application state containing workspace information
66///
67/// # Returns
68///
69/// Returns a JSON object containing the workbench configuration on success,
70/// or a string error message on failure.
71///
72/// # Errors
73///
74/// Returns an error string if:
75/// - Configuration construction fails (file system errors, JSON parsing)
76/// - State locking fails (concurrent access issues)
77#[tauri::command]
78pub async fn MountainGetWorkbenchConfiguration(
79 ApplicationHandle:AppHandle,
80 State:State<'_, Arc<ApplicationState>>,
81) -> Result<Value, String> {
82 dev_log!("ipc", "[IPC] [WorkbenchConfig] Request received.");
83
84 dev_log!("ipc", "[IPC] [WorkbenchConfig] Constructing sandbox configuration...");
85
86 let Config = InitializationData::ConstructSandboxConfiguration(&ApplicationHandle, State.inner())
87 .await
88 .map_err(|Error| {
89 dev_log!("ipc", "[IPC] [WorkbenchConfig] Failed: {}", Error);
90 Error.to_string()
91 })?;
92
93 dev_log!("ipc", "[IPC] [WorkbenchConfig] Success. Returning payload.");
94
95 Ok(Config)
96}