fix: polling noice on log and cache for scanning java version
This commit is contained in:
1 parent
7e5ff7f75f
commit
b5d98e5e8a
3 files changed
+47
-12
No files matched your search
+2
-2
@@ -238,7 +238,7 @@ pub fn detect_java_path() -> String {
|
||||
let java_name = if cfg!(windows) { "java.exe" } else { "java" };
|
||||
let bin = std::path::Path::new(&java_home).join("bin").join(java_name);
|
||||
if bin.exists() {
|
||||
tracing::debug!("Detected Java from JAVA_HOME: {}", bin.display());
|
||||
tracing::trace!("Detected Java from JAVA_HOME: {}", bin.display());
|
||||
return bin.to_string_lossy().to_string();
|
||||
}
|
||||
tracing::warn!(
|
||||
@@ -249,7 +249,7 @@ pub fn detect_java_path() -> String {
|
||||
}
|
||||
match which::which("java") {
|
||||
Ok(path) => {
|
||||
tracing::debug!("Detected Java from PATH: {}", path.display());
|
||||
tracing::trace!("Detected Java from PATH: {}", path.display());
|
||||
path.to_string_lossy().to_string()
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
+29
-8
@@ -91,10 +91,14 @@ pub fn init() -> WorkerGuard {
|
||||
)
|
||||
.with(
|
||||
tui_logger::TuiTracingSubscriberLayer.with_filter(filter_fn(|metadata| {
|
||||
should_record_app_log(metadata.target())
|
||||
should_record_app_log(metadata.target(), *metadata.level())
|
||||
})),
|
||||
)
|
||||
.with(StatusLayer::new(error_buffer::ERROR_EVENTS.clone()))
|
||||
.with(
|
||||
StatusLayer::new(error_buffer::ERROR_EVENTS.clone()).with_filter(filter_fn(
|
||||
|metadata| should_record_app_log(metadata.target(), *metadata.level()),
|
||||
)),
|
||||
)
|
||||
.init();
|
||||
|
||||
guard
|
||||
@@ -127,11 +131,11 @@ impl<S: Subscriber> Layer<S> for StatusLayer {
|
||||
Level::TRACE => "TRACE",
|
||||
};
|
||||
let now = chrono::Local::now().format("%H:%M:%S");
|
||||
if should_record_app_log(target) {
|
||||
if should_record_app_log(target, level) {
|
||||
push_app_log(format!("{now}:{level_str}:{target}: {}", visitor.message));
|
||||
}
|
||||
|
||||
if level <= Level::WARN && should_record_app_log(target) {
|
||||
if level <= Level::WARN && should_record_app_log(target, level) {
|
||||
error_buffer::push_error(ErrorEvent {
|
||||
id: 0,
|
||||
level,
|
||||
@@ -142,8 +146,12 @@ impl<S: Subscriber> Layer<S> for StatusLayer {
|
||||
}
|
||||
}
|
||||
|
||||
fn should_record_app_log(target: &str) -> bool {
|
||||
target != MINECRAFT_LOG_TARGET
|
||||
fn should_record_app_log(target: &str, level: Level) -> bool {
|
||||
if target == MINECRAFT_LOG_TARGET {
|
||||
return false;
|
||||
}
|
||||
|
||||
target == "rmcl" || target.starts_with("rmcl::") || level <= Level::WARN
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -178,11 +186,24 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn minecraft_events_are_not_general_app_logs() {
|
||||
assert!(!should_record_app_log(MINECRAFT_LOG_TARGET));
|
||||
assert!(!should_record_app_log(MINECRAFT_LOG_TARGET, Level::ERROR));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rmcl_events_are_general_app_logs() {
|
||||
assert!(should_record_app_log("rmcl::instance::manager"));
|
||||
assert!(should_record_app_log(
|
||||
"rmcl::instance::manager",
|
||||
Level::TRACE
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dependency_debug_events_are_not_general_app_logs() {
|
||||
assert!(!should_record_app_log("log", Level::DEBUG));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dependency_warnings_are_general_app_logs() {
|
||||
assert!(should_record_app_log("notify", Level::WARN));
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ pub struct SettingsState {
|
||||
meta_dir: PathBuf,
|
||||
active_profile: Option<String>,
|
||||
instance_name: Option<String>,
|
||||
java_key: Option<String>,
|
||||
java_source: Option<String>,
|
||||
java_label: String,
|
||||
}
|
||||
@@ -67,6 +68,7 @@ impl SettingsState {
|
||||
meta_dir,
|
||||
active_profile: None,
|
||||
instance_name: None,
|
||||
java_key: None,
|
||||
java_source: None,
|
||||
java_label: "unknown".to_string(),
|
||||
};
|
||||
@@ -110,12 +112,14 @@ impl SettingsState {
|
||||
self.select_active();
|
||||
}
|
||||
|
||||
let java_source = instance.map(effective_java_path);
|
||||
if self.java_source != java_source {
|
||||
let java_key = instance.map(java_path_key);
|
||||
if self.java_key != java_key {
|
||||
let java_source = instance.map(effective_java_path);
|
||||
self.java_label = java_source
|
||||
.as_deref()
|
||||
.map(java_version_label)
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
self.java_key = java_key;
|
||||
self.java_source = java_source;
|
||||
}
|
||||
}
|
||||
@@ -130,6 +134,16 @@ fn add_active_profile(profiles: &mut Vec<String>, active_profile: Option<&str>)
|
||||
}
|
||||
}
|
||||
|
||||
fn java_path_key(instance: &InstanceConfig) -> String {
|
||||
instance
|
||||
.java_path
|
||||
.as_deref()
|
||||
.filter(|path| !path.is_empty())
|
||||
.or_else(|| SETTINGS.paths.effective_java_path())
|
||||
.unwrap_or("<auto>")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn effective_java_path(instance: &InstanceConfig) -> String {
|
||||
instance
|
||||
.java_path
|
||||
|
||||
Reference in new issue
Block a user