feat: refine settings feedback and controls

This commit is contained in:
objz committed 2026-09-04 15:34:05 +02:00
1 parent 45d9b85abf
commit 17aff8ec6d
8 files changed
+174 -57

No files matched your search

+9
View File
@@ -49,6 +49,15 @@ pub fn push_error(event: ErrorEvent) {
}
}
pub fn push_message(level: Level, message: impl Into<String>) {
push_error(ErrorEvent {
id: 0,
level,
message: message.into(),
pushed_at: Instant::now(),
});
}
#[must_use]
pub fn has_errors() -> bool {
match ERROR_EVENTS.lock() {
+22
View File
@@ -272,6 +272,17 @@ impl App {
}
self.focused
}
Some(confirm_popup::ConfirmTarget::JvmArguments { .. }) => {
self.focused = FocusedArea::InstanceSettings;
let confirmed = self.instance_settings.as_mut().and_then(|state| {
state.clear_jvm_args();
state.confirmed_save()
});
if let Some((updated, desktop)) = confirmed {
self.apply_instance_settings(*updated, desktop, false);
}
self.focused
}
None => FocusedArea::Instances,
};
confirm_popup::clear_pending();
@@ -294,6 +305,9 @@ impl App {
}
FocusedArea::InstanceSettings
}
Some(confirm_popup::ConfirmTarget::JvmArguments { .. }) => {
FocusedArea::InstanceSettings
}
_ => FocusedArea::Instances,
};
confirm_popup::clear_pending();
@@ -735,11 +749,19 @@ impl App {
self.apply_instance_settings(*updated, desktop, false);
}
widgets::popups::instance_settings::Action::ConfirmRuntime { name } => {
error_buffer::push_message(
tracing::Level::WARN,
"Some installed mods may be incompatible",
);
confirm_popup::set_pending(confirm_popup::ConfirmTarget::InstanceRuntime {
name,
});
self.focused = FocusedArea::ConfirmDelete;
}
widgets::popups::instance_settings::Action::ConfirmClearJvmArgs { name } => {
confirm_popup::set_pending(confirm_popup::ConfirmTarget::JvmArguments { name });
self.focused = FocusedArea::ConfirmDelete;
}
}
return Ok(());
}
+54 -1
View File
@@ -658,11 +658,22 @@ fn runtime_settings_use_the_shared_confirmation_popup() {
ui.draw();
assert!(ui.screen().contains("Change runtime"));
assert!(!ui.screen().contains("Target:"));
assert!(ui.screen().contains("Apply this runtime change"));
assert!(
ui.screen()
!ui.screen()
.contains("Some installed mods may be incompatible")
);
assert!(!ui.screen().contains("incompatible."));
assert!(
crate::feedback::errors::ERROR_EVENTS
.lock()
.unwrap()
.iter()
.any(|event| {
event.level == tracing::Level::WARN
&& event.message == "Some installed mods may be incompatible"
})
);
ui.key(KeyCode::Esc);
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
@@ -670,6 +681,48 @@ fn runtime_settings_use_the_shared_confirmation_popup() {
assert_eq!(ui.app.focused, FocusedArea::Settings);
}
#[test]
fn clearing_jvm_arguments_requires_confirmation_and_autosaves() {
let mut ui = UiHarness::new();
ui.add_instance("jvm-clear-test");
ui.key(KeyCode::Char('E'));
ui.app.instance_settings.as_mut().unwrap().draft.jvm_args =
vec!["-XX:+UseG1GC".to_owned(), "-Xss1M".to_owned()];
for _ in 0..6 {
ui.key(KeyCode::Char('j'));
}
ui.key(KeyCode::Char('d'));
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
assert!(matches!(
confirm::pending_target(),
Some(confirm::ConfirmTarget::JvmArguments { name }) if name == "jvm-clear-test"
));
assert_eq!(
ui.app
.instance_settings
.as_ref()
.unwrap()
.draft
.jvm_args
.len(),
2
);
ui.key(KeyCode::Enter);
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
assert!(
ui.app
.instances_state
.selected_instance()
.unwrap()
.jvm_args
.is_empty()
);
}
#[test]
fn instance_settings_validation_errors_use_the_toast_buffer() {
let mut ui = UiHarness::new();
+8 -9
View File
@@ -48,6 +48,9 @@ pub enum ConfirmTarget {
InstanceRuntime {
name: String,
},
JvmArguments {
name: String,
},
}
impl ConfirmTarget {
@@ -55,6 +58,7 @@ impl ConfirmTarget {
match self {
Self::OrphanDependencies { .. } => " Remove unused dependencies ".to_owned(),
Self::InstanceRuntime { .. } => " Change runtime ".to_owned(),
Self::JvmArguments { .. } => " Clear JVM arguments ".to_owned(),
_ => format!(" Delete '{}' ", self.name()),
}
}
@@ -93,9 +97,8 @@ impl ConfirmTarget {
})
.collect::<Vec<_>>()
.join("\n"),
ConfirmTarget::InstanceRuntime { .. } => {
"Some installed mods may be incompatible".to_owned()
}
ConfirmTarget::InstanceRuntime { .. } => "Apply this runtime change".to_owned(),
ConfirmTarget::JvmArguments { .. } => "Remove all JVM arguments".to_owned(),
}
}
@@ -107,6 +110,7 @@ impl ConfirmTarget {
ConfirmTarget::Content { name, .. } => name,
ConfirmTarget::OrphanDependencies { .. } => "unused dependencies",
ConfirmTarget::InstanceRuntime { name, .. } => name,
ConfirmTarget::JvmArguments { name, .. } => name,
}
}
@@ -115,6 +119,7 @@ impl ConfirmTarget {
Self::Content { dependents, .. } if !dependents.is_empty() => " delete anyway",
Self::OrphanDependencies { .. } => " remove all",
Self::InstanceRuntime { .. } => " change",
Self::JvmArguments { .. } => " clear",
_ => " confirm",
}
}
@@ -181,7 +186,6 @@ pub struct ConfirmPopup {
title: String,
body: String,
confirm_label: &'static str,
runtime_confirmation: bool,
}
impl ConfirmPopup {
@@ -190,7 +194,6 @@ impl ConfirmPopup {
title: target.title(),
body: target.body(),
confirm_label: target.confirm_label(),
runtime_confirmation: matches!(target, ConfirmTarget::InstanceRuntime { .. }),
}
}
}
@@ -214,9 +217,7 @@ impl Widget for ConfirmPopup {
let text = theme.text();
let text_dim = theme.text_dim();
let error = theme.error();
let warning = theme.warning();
let body = self.body;
let runtime_confirmation = self.runtime_confirmation;
let styled_list = body.contains("• ");
let popup = PopupFrame {
title,
@@ -233,8 +234,6 @@ impl Widget for ConfirmPopup {
Span::styled("• ", Style::default().fg(accent)),
Span::styled(value.to_owned(), Style::default().fg(text)),
])
} else if runtime_confirmation && line.starts_with("Some installed mods") {
Line::styled(line.to_owned(), Style::default().fg(warning))
} else if line.starts_with('!') {
Line::styled(line.to_owned(), Style::default().fg(error))
} else {
+13 -12
View File
@@ -479,20 +479,21 @@ fn render_picker(frame: &mut Frame, area: Rect, values: &[String], selected: usi
super::select_list::render(items, selected, area, frame.buffer_mut());
}
fn render_java_picker(frame: &mut Frame, area: Rect, state: &State) {
fn render_java_picker(frame: &mut Frame, area: Rect, state: &mut State) {
let theme = THEME.as_ref();
let mut list_area = area;
if let Some(status) = state.java_picker.status() {
let (message, color) = match status {
Ok(message) => (message.to_owned(), theme.text_dim()),
Err(error) => (error, theme.error()),
};
frame.render_widget(
Paragraph::new(message).style(Style::default().fg(color)),
Rect { height: 1, ..area },
);
list_area.y = list_area.y.saturating_add(1);
list_area.height = list_area.height.saturating_sub(1);
if let Some(status) = state.java_picker.take_status() {
match status {
Ok(message) => {
frame.render_widget(
Paragraph::new(message).style(Style::default().fg(theme.text_dim())),
Rect { height: 1, ..area },
);
list_area.y = list_area.y.saturating_add(1);
list_area.height = list_area.height.saturating_sub(1);
}
Err(error) => crate::feedback::errors::push_message(tracing::Level::ERROR, error),
}
}
super::select_list::render(
state.java_picker.items(),
+50 -22
View File
@@ -77,7 +77,7 @@ enum PickerLoad {
Idle,
Loading,
Loaded,
Error(String),
Error,
}
#[derive(Debug, Clone)]
@@ -107,6 +107,7 @@ pub enum Action {
Save(Box<InstanceConfig>, bool),
Error(String),
ConfirmRuntime { name: String },
ConfirmClearJvmArgs { name: String },
OpenRaw,
Close,
}
@@ -361,7 +362,13 @@ impl State {
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner) = match result {
Ok(versions) => LoadState::Loaded(versions),
Err(error) => LoadState::Error(error),
Err(error) => {
crate::feedback::errors::push_message(
tracing::Level::ERROR,
format!("Failed to load game versions: {error}"),
);
LoadState::Error(error)
}
};
crate::feedback::request_redraw();
});
@@ -389,7 +396,13 @@ impl State {
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner) = match result {
Ok(versions) => LoadState::Loaded(versions),
Err(error) => LoadState::Error(error),
Err(error) => {
crate::feedback::errors::push_message(
tracing::Level::ERROR,
format!("Failed to load loader versions: {error}"),
);
LoadState::Error(error)
}
};
crate::feedback::request_redraw();
});
@@ -734,6 +747,11 @@ impl State {
self.apply_default_memory();
}
KeyCode::Char('d') if self.selected == 7 => self.apply_default_resolution(),
KeyCode::Char('d') if self.selected == 6 && !self.draft.jvm_args.is_empty() => {
return Action::ConfirmClearJvmArgs {
name: self.draft.name.clone(),
};
}
KeyCode::Char('c') if self.selected == 7 => {
self.editing = Some(new_text_area(vec![self.value(7)]));
}
@@ -753,6 +771,11 @@ impl State {
.then(|| (Box::new(self.draft.clone()), self.desktop))
}
pub fn clear_jvm_args(&mut self) {
self.draft.jvm_args.clear();
self.error = None;
}
pub fn mark_saved(&mut self, saved: &InstanceConfig, desktop: bool) {
self.original = saved.clone();
self.draft = saved.clone();
@@ -891,6 +914,13 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut State) {
("d", " default"),
("Esc", " back"),
])
} else if state.selected == 6 {
super::keybind_line(&[
("j/k", ""),
("Enter", " edit"),
("d", " clear"),
("Esc", " back"),
])
} else if matches!(state.selected, 0..=2) {
super::keybind_line(&[
("j/k", ""),
@@ -1115,22 +1145,23 @@ fn jvm_row_count(state: &State, width: u16) -> usize {
rows
}
fn render_choice_picker(frame: &mut Frame, area: Rect, state: &State) {
fn render_choice_picker(frame: &mut Frame, area: Rect, state: &mut State) {
let theme = THEME.as_ref();
let mut list_area = area;
if state.choice_picker == Some(ChoicePicker::Java)
&& let Some(status) = state.java_picker.status()
&& let Some(status) = state.java_picker.take_status()
{
let (message, color) = match status {
Ok(message) => (message.to_owned(), theme.text_dim()),
Err(error) => (error, theme.error()),
};
frame.render_widget(
Paragraph::new(message).style(Style::default().fg(color)),
Rect { height: 1, ..area },
);
list_area.y = list_area.y.saturating_add(1);
list_area.height = list_area.height.saturating_sub(1);
match status {
Ok(message) => {
frame.render_widget(
Paragraph::new(message).style(Style::default().fg(theme.text_dim())),
Rect { height: 1, ..area },
);
list_area.y = list_area.y.saturating_add(1);
list_area.height = list_area.height.saturating_sub(1);
}
Err(error) => crate::feedback::errors::push_message(tracing::Level::ERROR, error),
}
}
let items = match state.choice_picker {
Some(ChoicePicker::Java) => state.java_picker.items(),
@@ -1200,7 +1231,7 @@ fn render_version_picker(frame: &mut Frame, area: Rect, state: &State) {
LoadState::Idle => PickerLoad::Idle,
LoadState::Loading => PickerLoad::Loading,
LoadState::Loaded(_) => PickerLoad::Loaded,
LoadState::Error(error) => PickerLoad::Error(error.clone()),
LoadState::Error(_) => PickerLoad::Error,
},
Some(VersionPicker::Loader) => match &*state
.loader_versions
@@ -1210,7 +1241,7 @@ fn render_version_picker(frame: &mut Frame, area: Rect, state: &State) {
LoadState::Idle => PickerLoad::Idle,
LoadState::Loading => PickerLoad::Loading,
LoadState::Loaded(_) => PickerLoad::Loaded,
LoadState::Error(error) => PickerLoad::Error(error.clone()),
LoadState::Error(_) => PickerLoad::Error,
},
None => return,
};
@@ -1219,11 +1250,8 @@ fn render_version_picker(frame: &mut Frame, area: Rect, state: &State) {
Paragraph::new("Loading versions...").style(Style::default().fg(theme.text_dim())),
area,
),
PickerLoad::Error(error) => frame.render_widget(
Paragraph::new(format!(
"Failed to load versions: {error}. Reopen to retry."
))
.style(Style::default().fg(theme.error())),
PickerLoad::Error => frame.render_widget(
Paragraph::new("Reopen to retry").style(Style::default().fg(theme.text_dim())),
area,
),
PickerLoad::Loaded => {
+13 -8
View File
@@ -168,19 +168,23 @@ impl JavaPicker {
.collect()
}
pub(crate) fn status(&self) -> Option<Result<&'static str, String>> {
match &*self
pub(crate) fn take_status(&mut self) -> Option<Result<&'static str, String>> {
let mut load = self
.load
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
{
.unwrap_or_else(std::sync::PoisonError::into_inner);
match &*load {
LoadState::Idle => None,
LoadState::Loading => Some(Ok("Detecting installed Java runtimes…")),
LoadState::Loaded(installations) if installations.is_empty() => {
Some(Ok("No additional Java runtimes found."))
}
LoadState::Loaded(_) => None,
LoadState::Error(error) => Some(Err(error.clone())),
LoadState::Error(error) => {
let error = error.clone();
*load = LoadState::Loaded(Vec::new());
Some(Err(error))
}
}
}
@@ -338,10 +342,11 @@ pub(crate) fn handle_text_area_input(input: &mut TextArea<'_>, key: &KeyEvent) {
pub(crate) fn auto_label() -> Span<'static> {
Span::styled(
"Auto",
" Auto ",
Style::default()
.fg(THEME.as_ref().text_dim())
.add_modifier(Modifier::ITALIC),
.fg(THEME.as_ref().text_bright())
.bg(THEME.as_ref().info())
.add_modifier(Modifier::BOLD),
)
}
+5 -5
View File
@@ -329,10 +329,10 @@ fn render_instance_info(
} else {
value_style
};
let desktop = if crate::instance::desktop::exists(&inst.name) {
"yes"
let shortcut = if crate::instance::desktop::exists(&inst.name) {
"enabled"
} else {
"no"
"disabled"
};
let lines = vec![
Line::from(vec![
@@ -344,8 +344,8 @@ fn render_instance_info(
Span::styled(state.java_label.as_str(), active_style),
]),
Line::from(vec![
Span::styled("Desktop ", label_style),
Span::styled(desktop, active_style),
Span::styled("Shortcut ", label_style),
Span::styled(shortcut, active_style),
]),
];