Skip to content

Commit d276d12

Browse files
refactor(Mountain): Enhance debug logging and refine effect system
- **Debug Logging**: Added colored trace-level logging for debug builds in `Binary.rs` to improve development visibility, formatting Mountain logs with application context and level-specific colors - **Tauri Configuration**: Enabled `any_thread()` mode for Windows/Linux in Tauri builder to resolve potential runtime constraints - **Terminal Provider**: Removed unnecessary `mut` qualifiers from PTY variables in `TerminalProvider.rs` as they aren't mutated after creation - **Effect System**: Updated `box_effect` in `EffectCreation.rs` to: - Require `MountainEnvironment` instead of `MountainRunTime` for context resolution - Add `From<CommonError>` bound to error types for improved interoperability - Remove obsolete comment about effect mappings These changes strengthen Mountain's core infrastructure: 1. Debug logging aids development while maintaining release-mode minimalism 2. Thread configuration prevents potential Tauri runtime issues 3. Terminal implementation adheres to Rust's ownership best practices 4. Effect system now properly leverages the `Environment` trait from `Common` crate, ensuring correct dependency resolution through `Requires` trait 5. Error handling alignment supports the standardized gRPC error system refined in recent commits
1 parent 3b69c26 commit d276d12

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

Source/Binary.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,32 @@ fn InitializeLogging() {
3030
// This is unsafe but only runs once at startup.
3131
unsafe { std::env::set_var("RUST_LOG", LogLevel) };
3232
}
33-
env_logger::init();
33+
34+
#[cfg(debug_assertions)]
35+
{
36+
env_logger::Builder::new()
37+
.filter_level(log::LevelFilter::Trace)
38+
.format(|Buffer, Record| {
39+
use std::io::Write;
40+
41+
use colored::Colorize;
42+
writeln!(
43+
Buffer,
44+
"[{}] [{}]: {}",
45+
"Mountain".red(),
46+
match Record.level() {
47+
log::Level::Error => "ERROR".red().bold(),
48+
log::Level::Warn => "WARN".yellow().bold(),
49+
log::Level::Info => "INFO".green(),
50+
log::Level::Debug => "DEBUG".blue(),
51+
log::Level::Trace => "TRACE".magenta(),
52+
},
53+
Record.args()
54+
)
55+
})
56+
.try_init()
57+
.expect("Failed to initialize env_logger. Another logger might be active.");
58+
}
3459
}
3560

3661
/// The main asynchronous function that sets up and runs the application.
@@ -51,8 +76,14 @@ pub fn Fn() {
5176
let SchedulerForShutdown = Arc::new(Scheduler);
5277
let SchedulerForRunTime = SchedulerForShutdown.clone();
5378

79+
#[allow(unused_mut)]
5480
let mut Builder = tauri::Builder::default();
5581

82+
#[cfg(any(windows, target_os = "linux"))]
83+
{
84+
Builder = Builder.any_thread();
85+
}
86+
5687
Builder
5788
.manage(ApplicationState::default())
5889
.setup(move |Application| {

Source/Environment/TerminalProvider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl TerminalProvider for MountainEnvironment {
4747
let mut TerminalState = TerminalStateDTO::Create(TerminalIdentifier, Name.clone(), &OptionsValue, DefaultShell);
4848

4949
let PtySystem = NativePtySystem::default();
50-
let mut PtyPair = PtySystem
50+
let PtyPair = PtySystem
5151
.openpty(PtySize::default())
5252
.map_err(|e| CommonError::IPCError { Description:format!("Failed to open PTY: {}", e) })?;
5353

@@ -57,7 +57,7 @@ impl TerminalProvider for MountainEnvironment {
5757
Command.cwd(CWD);
5858
}
5959

60-
let mut ChildProcess = PtyPair
60+
let ChildProcess = PtyPair
6161
.slave
6262
.spawn_command(Command)
6363
.map_err(|e| CommonError::IPCError { Description:format!("Failed to spawn shell process: {}", e) })?;

Source/Track/EffectCreation.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ use std::{future::Future, pin::Pin, sync::Arc};
1111
use Common::{
1212
self,
1313
Effect::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime as ApplicationRunTimeTrait},
14+
Environment::Requires::Requires,
1415
Error::CommonError::CommonError,
1516
};
1617
use serde_json::{Value, from_value};
1718
use tauri::{AppHandle, Runtime};
1819

19-
use crate::RunTime::ApplicationRunTime::ApplicationRunTime as MountainRunTime;
20+
use crate::{
21+
Environment::MountainEnvironment::MountainEnvironment,
22+
RunTime::ApplicationRunTime::ApplicationRunTime as MountainRunTime,
23+
};
2024

2125
/// A type alias for a boxed, runnable effect. This is the "type-erased" unit of
2226
/// work.
@@ -43,8 +47,8 @@ fn box_effect<C, O, E>(effect:ActionEffect<Arc<C>, E, O>) -> MappedEffect
4347
where
4448
C: ?Sized + Send + Sync + 'static,
4549
O: serde::Serialize + Send + Sync + 'static,
46-
E: Into<CommonError> + Send + Sync + 'static,
47-
MountainRunTime: Common::Environment::Requires::Requires<C>, {
50+
E: Into<CommonError> + From<CommonError> + Send + Sync + 'static,
51+
MountainEnvironment: Requires<C>, {
4852
Box::new(move |runtime:Arc<MountainRunTime>| {
4953
Box::pin(async move {
5054
let result = runtime.Run(effect).await;
@@ -126,7 +130,6 @@ pub fn CreateEffectForRequest<R:Runtime>(
126130
box_effect(Common::UserInterface::ShowOpenDialog::ShowOpenDialog(Options))
127131
},
128132

129-
// ... Add mappings for all other effects here ...
130133
_ => return Err(format!("No ActionEffect mapping found for method: {}", Method)),
131134
};
132135

0 commit comments

Comments
 (0)