Expand description
Legacy Wind Service Handlers.
§Wind Service Handlers - Cross-Language Service Bridge
File Responsibilities: This module provides the direct mapping layer between Wind’s TypeScript service invocations and Mountain’s Rust service implementations. It acts as the critical translation layer that enables Wind to request operations from Mountain through Tauri’s IPC mechanism.
Architectural Role in Wind-Mountain Connection:
The WindServiceHandlers module implements the concrete command handlers that process IPC invocations from Wind. It serves as the single entry point for all Wind->Mountain service requests:
- Command Mapping: Maps Wind’s TypeScript service methods to Rust implementations
- Type Conversion: Converts between JSON/TypeScript types and Rust types
- Validation: Validates all inputs before forwarding to Mountain services
- Error Handling: Provides comprehensive error messages back to Wind
- Service Integration: Connects to Mountain’s internal service architecture
Handled Command Categories:
1. Configuration Commands:
configuration:get- Retrieve configuration valuesconfiguration:update- Update configuration values
2. File System Commands:
file:read- Read file contentsfile:write- Write to filesfile:stat- Get file metadatafile:exists- Check file existencefile:delete- Delete files or directoriesfile:copy- Copy filesfile:move- Move/rename filesfile:mkdir- Create directoriesfile:readdir- Read directory contentsfile:readBinary- Read binary filesfile:writeBinary- Write binary files
3. Storage Commands:
storage:get- Retrieve persistent storage valuesstorage:set- Store persistent values
4. Environment Commands:
environment:get- Get environment variables
5. Native Host Commands:
native:showItemInFolder- Reveal file in system file managernative:openExternal- Open URLs in external browser
6. Workbench Commands:
workbench:getConfiguration- Get complete workbench configuration
7. IPC Status Commands:
mountain_get_status- Get overall IPC system statusmountain_get_configuration- Get Mountain configuration snapshotmountain_get_services_status- Get status of all Mountain servicesmountain_get_state- Get current application state
Communication Pattern:
Wind (TypeScript)
|
| app.handle.invoke('command', args)
v
Tauri Bridge (IPC)
|
| mountain_ipc_invoke(command, args)
v
WindServiceHandlers
|
| Type conversion + validation
v
Mountain Services (Rust)
|
| Execute operation
v
Return Result<serde_json::Value>Type Conversion Strategy (TypeScript <-> Rust):
Primitive Types:
- TypeScript
string↔ RustString/&str - TypeScript
number↔ Rustf64/i32/u32 - TypeScript
boolean↔ Rustbool - TypeScript
null↔ RustOption::<T>::None
Complex Types:
- TypeScript
object↔ Rustserde_json::Value/HashMap - TypeScript
Array<T>↔ RustVec<T> - TypeScript custom interfaces ↔ Rust structs with Serialize/Deserialize
Example Type Conversion:
// Wind (TypeScript)
interface FileReadOptions {
encoding: 'utf8' | 'binary';
withBOM: boolean;
}
const result = await invoke('file:read', {
path: '/path/to/file.txt',
options: { encoding: 'utf8', withBOM: false }
});// Mountain (Rust)
args.get(0).and_then(|v| v.as_str()) // Extract path
args.get(1).and_then(|v| v.as_object()) // Extract options
// ... validation, processing, return ResultDefensive Error Handling:
Each handler implements comprehensive error handling:
-
Input Validation:
- Check parameter presence
- Validate parameter types
- Validate value ranges and formats
-
Service Error Handling:
- Catch and translate service errors
- Provide detailed error messages
- Include context for debugging
-
Error Response Format:
Error("Failed to read file: Permission denied (path: /etc/passwd)") Comprehensive Error Messages:
- Include operation that failed
- Include relevant parameters (paths, keys, etc.)
- Include the underlying cause
- Format:
"Failed to <operation>: <cause> (context: <value>)"
Service Integration Pattern:
Handlers use Mountain’s dependency injection system via Requires trait:
let provider: Arc<dyn ConfigurationProvider> = runtime.Environment.Require();
provider.GetConfigurationValue(...).await?;This provides:
- Loose coupling between handlers and services
- Testable architecture (can mock services)
- Centralized service lifecycle management
Command Registration:
All handlers are automatically registered when included in Tauri’s invoke_handler:
.invoke_handler(tauri::generate_handler![
mountain_ipc_invoke,
// ... other commands
])Functions§
- handle_
configuration_ 🔒get - Handler for configuration get requests
- handle_
configuration_ 🔒update - Handler for configuration update requests
- handle_
environment_ 🔒get - Handler for environment get requests
- handle_
file_ 🔒copy - Handler for file copy requests
- handle_
file_ 🔒delete - Handler for file delete requests
- handle_
file_ 🔒exists - Handler for file exists requests
- handle_
file_ 🔒mkdir - Handler for directory creation requests
- handle_
file_ 🔒move - Handler for file move requests
- handle_
file_ 🔒read - Handler for file read requests
- handle_
file_ 🔒read_ binary - Handler for binary file read requests
- handle_
file_ 🔒readdir - Handler for directory reading requests
- handle_
file_ 🔒stat - Handler for file stat requests
- handle_
file_ 🔒write - Handler for file write requests
- handle_
file_ 🔒write_ binary - Handler for binary file write requests
- handle_
open_ 🔒external - Handler for opening external URLs
- handle_
show_ 🔒item_ in_ folder - Handler for showing items in folder
- handle_
storage_ 🔒get - Handler for storage get requests
- handle_
storage_ 🔒set - Handler for storage set requests
- handle_
workbench_ 🔒configuration - Handler for workbench configuration requests
- mountain_
ipc_ invoke - Handler for Wind’s MainProcessService.invoke() calls Maps Tauri IPC commands to Mountain’s internal command system
- register_
wind_ ipc_ handlers - Register all Wind IPC command handlers