Skip to main content

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