feat: autosave settings changes
This commit is contained in:
1 parent
6ce48b640a
commit
fa6220649f
5 files changed
+130
-159
No files matched your search
+20
-40
@@ -268,18 +268,10 @@ impl App {
|
||||
.as_mut()
|
||||
.and_then(|state| state.confirmed_save());
|
||||
if let Some((updated, desktop)) = confirmed {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
self.apply_instance_settings(*updated, desktop, true);
|
||||
}
|
||||
self.focused
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::DiscardInstanceSettings) => {
|
||||
self.instance_settings = None;
|
||||
self.pre_overlay_focused
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::DiscardLauncherSettings) => {
|
||||
self.global_settings = None;
|
||||
self.pre_overlay_focused
|
||||
}
|
||||
None => FocusedArea::Instances,
|
||||
};
|
||||
confirm_popup::clear_pending();
|
||||
@@ -296,13 +288,12 @@ impl App {
|
||||
Some(confirm_popup::ConfirmTarget::ConfigProfile { .. }) => {
|
||||
FocusedArea::Settings
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::InstanceRuntime { .. })
|
||||
| Some(confirm_popup::ConfirmTarget::DiscardInstanceSettings) => {
|
||||
Some(confirm_popup::ConfirmTarget::InstanceRuntime { .. }) => {
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
state.cancel_runtime_change();
|
||||
}
|
||||
FocusedArea::InstanceSettings
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::DiscardLauncherSettings) => {
|
||||
FocusedArea::GlobalSettings
|
||||
}
|
||||
_ => FocusedArea::Instances,
|
||||
};
|
||||
confirm_popup::clear_pending();
|
||||
@@ -675,12 +666,6 @@ impl App {
|
||||
self.global_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
widgets::popups::global_settings::Action::ConfirmClose => {
|
||||
confirm_popup::set_pending(
|
||||
confirm_popup::ConfirmTarget::DiscardLauncherSettings,
|
||||
);
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
widgets::popups::global_settings::Action::OpenRaw(path) => {
|
||||
self.pending_editor = Some(path);
|
||||
self.global_settings = None;
|
||||
@@ -692,8 +677,7 @@ impl App {
|
||||
.and_then(|()| crate::config::theme::apply_theme(theme, border));
|
||||
match result {
|
||||
Ok(()) => {
|
||||
self.global_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
Err(error) => error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
@@ -732,7 +716,7 @@ impl App {
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
widgets::popups::instance_settings::Action::Save(updated, desktop) => {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
self.apply_instance_settings(*updated, desktop, false);
|
||||
}
|
||||
widgets::popups::instance_settings::Action::ConfirmRuntime { name, from, to } => {
|
||||
confirm_popup::set_pending(confirm_popup::ConfirmTarget::InstanceRuntime {
|
||||
@@ -742,12 +726,6 @@ impl App {
|
||||
});
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
widgets::popups::instance_settings::Action::ConfirmClose => {
|
||||
confirm_popup::set_pending(
|
||||
confirm_popup::ConfirmTarget::DiscardInstanceSettings,
|
||||
);
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
@@ -2050,6 +2028,7 @@ impl App {
|
||||
&mut self,
|
||||
updated: crate::instance::models::InstanceConfig,
|
||||
desktop: bool,
|
||||
close: bool,
|
||||
) {
|
||||
let Some(previous) = self.instances_state.selected_instance().cloned() else {
|
||||
return;
|
||||
@@ -2068,8 +2047,10 @@ impl App {
|
||||
return;
|
||||
}
|
||||
self.spawn_instance_settings_update(previous, updated, desktop);
|
||||
self.instance_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
if close {
|
||||
self.instance_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2089,15 +2070,14 @@ impl App {
|
||||
});
|
||||
}
|
||||
self.instances_state
|
||||
.replace_instance(&previous.name, updated);
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::INFO,
|
||||
message: format!("Updated instance '{}'", previous.name),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
self.instance_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
.replace_instance(&previous.name, updated.clone());
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
state.mark_saved(&updated, desktop);
|
||||
}
|
||||
if close {
|
||||
self.instance_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
}
|
||||
Err(error) => error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
|
||||
+19
-12
@@ -607,11 +607,12 @@ fn settings_panel_routes_legacy_edit_keys_to_tui_popups() {
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("-Xfoo"));
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
assert_eq!(
|
||||
ui.app.instances_state.selected_instance().unwrap().jvm_args,
|
||||
["-Xfoo"]
|
||||
);
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Discard changes"));
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||
|
||||
ui.key(KeyCode::Char('g'));
|
||||
@@ -644,7 +645,10 @@ fn runtime_settings_use_the_shared_confirmation_popup() {
|
||||
.draft
|
||||
.game_version = "1.21.2".to_owned();
|
||||
|
||||
ui.key(KeyCode::Char('s'));
|
||||
for _ in 0..4 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Char('l'));
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
assert!(matches!(
|
||||
@@ -653,17 +657,12 @@ fn runtime_settings_use_the_shared_confirmation_popup() {
|
||||
));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Change runtime"));
|
||||
assert!(ui.screen().contains("Runtime files will be downloaded"));
|
||||
assert!(ui.screen().contains("downloaded before applying"));
|
||||
assert!(ui.screen().contains("Installed mods may not load"));
|
||||
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
ui.key(KeyCode::Esc);
|
||||
assert!(matches!(
|
||||
confirm::pending_target(),
|
||||
Some(confirm::ConfirmTarget::DiscardInstanceSettings)
|
||||
));
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||
}
|
||||
|
||||
@@ -698,6 +697,15 @@ fn settings_use_java_memory_and_resolution_controls() {
|
||||
.as_deref(),
|
||||
Some("1G")
|
||||
);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_min
|
||||
.as_deref(),
|
||||
Some("1G")
|
||||
);
|
||||
|
||||
for _ in 0..3 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
@@ -711,7 +719,6 @@ fn settings_use_java_memory_and_resolution_controls() {
|
||||
assert!(ui.screen().contains("custom"));
|
||||
ui.key(KeyCode::Esc);
|
||||
ui.key(KeyCode::Esc);
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
ui.key(KeyCode::Char('G'));
|
||||
for _ in 0..4 {
|
||||
|
||||
@@ -50,8 +50,6 @@ pub enum ConfirmTarget {
|
||||
from: String,
|
||||
to: String,
|
||||
},
|
||||
DiscardInstanceSettings,
|
||||
DiscardLauncherSettings,
|
||||
}
|
||||
|
||||
impl ConfirmTarget {
|
||||
@@ -59,9 +57,6 @@ impl ConfirmTarget {
|
||||
match self {
|
||||
Self::OrphanDependencies { .. } => " Remove unused dependencies ".to_owned(),
|
||||
Self::InstanceRuntime { .. } => " Change runtime ".to_owned(),
|
||||
Self::DiscardInstanceSettings | Self::DiscardLauncherSettings => {
|
||||
" Discard changes ".to_owned()
|
||||
}
|
||||
_ => format!(" Delete '{}' ", self.name()),
|
||||
}
|
||||
}
|
||||
@@ -101,14 +96,8 @@ impl ConfirmTarget {
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
ConfirmTarget::InstanceRuntime { from, to, .. } => format!(
|
||||
"{from} → {to}\nRuntime files will be downloaded before saving.\n! Installed mods may not load and can be incompatible with the new runtime."
|
||||
"{from} → {to}\nRuntime files will be downloaded before applying the change.\n! Installed mods may not load and can be incompatible with the new runtime."
|
||||
),
|
||||
ConfirmTarget::DiscardInstanceSettings => {
|
||||
"Unsaved instance settings will be lost.".to_owned()
|
||||
}
|
||||
ConfirmTarget::DiscardLauncherSettings => {
|
||||
"Unsaved launcher settings will be lost.".to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +109,6 @@ impl ConfirmTarget {
|
||||
ConfirmTarget::Content { name, .. } => name,
|
||||
ConfirmTarget::OrphanDependencies { .. } => "unused dependencies",
|
||||
ConfirmTarget::InstanceRuntime { name, .. } => name,
|
||||
ConfirmTarget::DiscardInstanceSettings => "instance settings",
|
||||
ConfirmTarget::DiscardLauncherSettings => "launcher settings",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +117,6 @@ impl ConfirmTarget {
|
||||
Self::Content { dependents, .. } if !dependents.is_empty() => " delete anyway",
|
||||
Self::OrphanDependencies { .. } => " remove all",
|
||||
Self::InstanceRuntime { .. } => " change",
|
||||
Self::DiscardInstanceSettings | Self::DiscardLauncherSettings => " discard",
|
||||
_ => " confirm",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ pub struct State {
|
||||
selected: usize,
|
||||
editing: Option<TextArea<'static>>,
|
||||
error: Option<String>,
|
||||
config_dirty: bool,
|
||||
save_pending: bool,
|
||||
themes: Vec<String>,
|
||||
theme_picker: bool,
|
||||
theme_index: usize,
|
||||
@@ -42,7 +42,6 @@ pub struct State {
|
||||
pub enum Action {
|
||||
None,
|
||||
Save(Box<Config>, String, BorderStyle),
|
||||
ConfirmClose,
|
||||
OpenRaw(std::path::PathBuf),
|
||||
Close,
|
||||
}
|
||||
@@ -61,7 +60,7 @@ impl State {
|
||||
selected: 0,
|
||||
editing: None,
|
||||
error: None,
|
||||
config_dirty: false,
|
||||
save_pending: false,
|
||||
themes,
|
||||
theme_picker: false,
|
||||
theme_index,
|
||||
@@ -119,7 +118,7 @@ impl State {
|
||||
if memory_kib(&value) > memory_kib(&self.config.defaults.memory_max) {
|
||||
self.config.defaults.memory_max = value;
|
||||
}
|
||||
self.config_dirty = true;
|
||||
self.save_pending = true;
|
||||
}
|
||||
3 => {
|
||||
let value = normalize_memory_value(value).unwrap();
|
||||
@@ -127,11 +126,11 @@ impl State {
|
||||
if memory_kib(&value) < memory_kib(&self.config.defaults.memory_min) {
|
||||
self.config.defaults.memory_min = value;
|
||||
}
|
||||
self.config_dirty = true;
|
||||
self.save_pending = true;
|
||||
}
|
||||
4 => {
|
||||
self.config.paths.java_path = (!value.is_empty()).then(|| value.to_owned());
|
||||
self.config_dirty = true;
|
||||
self.save_pending = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -147,6 +146,8 @@ impl State {
|
||||
) {
|
||||
self.error = Some(error.to_string());
|
||||
self.theme.theme = previous;
|
||||
} else if self.theme.theme != previous {
|
||||
self.save_pending = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +185,8 @@ impl State {
|
||||
) {
|
||||
self.error = Some(error.to_string());
|
||||
self.theme.border_style = previous;
|
||||
} else if self.theme.border_style != previous {
|
||||
self.save_pending = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +204,7 @@ impl State {
|
||||
KeyCode::Esc | KeyCode::Char('h') | KeyCode::Left => self.java_picker_open = false,
|
||||
KeyCode::Char('a') => {
|
||||
if self.config.paths.java_path.take().is_some() {
|
||||
self.config_dirty = true;
|
||||
self.save_pending = true;
|
||||
}
|
||||
self.java_picker_open = false;
|
||||
}
|
||||
@@ -220,7 +223,7 @@ impl State {
|
||||
JavaChoice::Installation(path) => {
|
||||
if self.config.paths.java_path.as_deref() != Some(&path) {
|
||||
self.config.paths.java_path = Some(path);
|
||||
self.config_dirty = true;
|
||||
self.save_pending = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,21 +251,24 @@ impl State {
|
||||
self.config.defaults.memory_min = value;
|
||||
}
|
||||
}
|
||||
self.config_dirty = true;
|
||||
self.save_pending = true;
|
||||
self.error = None;
|
||||
}
|
||||
|
||||
fn validate_before_save(&mut self) -> bool {
|
||||
self.error = None;
|
||||
let min = memory_kib(&self.config.defaults.memory_min);
|
||||
let max = memory_kib(&self.config.defaults.memory_max);
|
||||
if min.zip(max).is_some_and(|(min, max)| min > max) {
|
||||
self.error = Some("minimum memory cannot exceed maximum memory".to_owned());
|
||||
}
|
||||
self.error.is_none()
|
||||
}
|
||||
|
||||
pub fn handle_key(&mut self, key: &KeyEvent) -> Action {
|
||||
let action = self.handle_key_inner(key);
|
||||
if matches!(action, Action::None) && self.save_pending && self.editing.is_none() {
|
||||
self.save_pending = false;
|
||||
return Action::Save(
|
||||
Box::new(self.config.clone()),
|
||||
self.theme.theme.clone(),
|
||||
self.theme.border_style.clone(),
|
||||
);
|
||||
}
|
||||
action
|
||||
}
|
||||
|
||||
fn handle_key_inner(&mut self, key: &KeyEvent) -> Action {
|
||||
if self.java_picker_open {
|
||||
self.handle_java_picker_key(key);
|
||||
return Action::None;
|
||||
@@ -301,26 +307,12 @@ impl State {
|
||||
},
|
||||
KeyCode::Char('a') if self.selected == 4 => {
|
||||
if self.config.paths.java_path.take().is_some() {
|
||||
self.config_dirty = true;
|
||||
self.save_pending = true;
|
||||
}
|
||||
}
|
||||
KeyCode::Char('c') if self.selected == 4 => {
|
||||
self.editing = Some(new_text_area(vec![self.value(4)]));
|
||||
}
|
||||
KeyCode::Char('s') => {
|
||||
if self.validate_before_save() {
|
||||
return Action::Save(
|
||||
Box::new(self.config.clone()),
|
||||
self.theme.theme.clone(),
|
||||
self.theme.border_style.clone(),
|
||||
);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('E') if self.config_dirty => {
|
||||
self.error = Some(
|
||||
"save or discard launcher defaults before opening the raw file".to_owned(),
|
||||
);
|
||||
}
|
||||
KeyCode::Char('E') => {
|
||||
let file = if self.selected <= 1 {
|
||||
"theme.toml"
|
||||
@@ -329,7 +321,6 @@ impl State {
|
||||
};
|
||||
return Action::OpenRaw(crate::config::get_config_path().join(file));
|
||||
}
|
||||
KeyCode::Esc if self.config_dirty => return Action::ConfirmClose,
|
||||
KeyCode::Esc => return Action::Close,
|
||||
_ => {}
|
||||
}
|
||||
@@ -413,25 +404,18 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut State) {
|
||||
} else if state.theme_picker {
|
||||
super::keybind_line(&[("h", " back"), ("Enter", " select")])
|
||||
} else if matches!(state.selected, 2 | 3) {
|
||||
super::keybind_line(&[
|
||||
("h/l", " adjust"),
|
||||
("Enter", " exact"),
|
||||
("s", " save"),
|
||||
("Esc", " back"),
|
||||
])
|
||||
super::keybind_line(&[("h/l", " adjust"), ("Enter", " exact"), ("Esc", " back")])
|
||||
} else if state.selected == 4 {
|
||||
super::keybind_line(&[
|
||||
("Enter", " runtimes"),
|
||||
("a", " auto"),
|
||||
("c", " custom"),
|
||||
("s", " save"),
|
||||
("Esc", " back"),
|
||||
])
|
||||
} else {
|
||||
super::keybind_line(&[
|
||||
("j/k", ""),
|
||||
("Enter", " edit"),
|
||||
("s", " save"),
|
||||
("E", " raw"),
|
||||
("Esc", " back"),
|
||||
])
|
||||
@@ -594,7 +578,10 @@ mod tests {
|
||||
let mut state = State::new();
|
||||
state.selected = 2;
|
||||
let original = state.config.defaults.memory_min.clone();
|
||||
state.handle_key(&KeyEvent::from(KeyCode::Char('l')));
|
||||
assert!(matches!(
|
||||
state.handle_key(&KeyEvent::from(KeyCode::Char('l'))),
|
||||
Action::Save(..)
|
||||
));
|
||||
assert_ne!(state.config.defaults.memory_min, original);
|
||||
assert!(state.editing.is_none());
|
||||
|
||||
|
||||
@@ -110,7 +110,6 @@ pub enum Action {
|
||||
from: String,
|
||||
to: String,
|
||||
},
|
||||
ConfirmClose,
|
||||
OpenRaw,
|
||||
Close,
|
||||
}
|
||||
@@ -617,6 +616,42 @@ impl State {
|
||||
}
|
||||
|
||||
pub fn handle_key(&mut self, key: &KeyEvent) -> Action {
|
||||
let before = self.draft.clone();
|
||||
let desktop_before = self.desktop;
|
||||
let action = self.handle_key_inner(key);
|
||||
if !matches!(action, Action::None)
|
||||
|| before == self.draft && desktop_before == self.desktop
|
||||
|| !self.dirty()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
if self.runtime_changed() {
|
||||
if self.draft.loader != ModLoader::Vanilla
|
||||
&& self
|
||||
.draft
|
||||
.loader_version
|
||||
.as_deref()
|
||||
.is_none_or(str::is_empty)
|
||||
{
|
||||
return Action::None;
|
||||
}
|
||||
if !self.validate_before_save() {
|
||||
return Action::None;
|
||||
}
|
||||
return Action::ConfirmRuntime {
|
||||
name: self.draft.name.clone(),
|
||||
from: runtime_label(&self.original),
|
||||
to: runtime_label(&self.draft),
|
||||
};
|
||||
}
|
||||
if self.validate_before_save() {
|
||||
Action::Save(Box::new(self.draft.clone()), self.desktop)
|
||||
} else {
|
||||
Action::None
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_key_inner(&mut self, key: &KeyEvent) -> Action {
|
||||
if self.choice_picker.is_some() {
|
||||
self.handle_choice_key(key);
|
||||
return Action::None;
|
||||
@@ -657,25 +692,7 @@ impl State {
|
||||
KeyCode::Char('c') if self.selected == 3 => {
|
||||
self.editing = Some(new_text_area(vec![self.value(3)]));
|
||||
}
|
||||
KeyCode::Char('s') if self.dirty() => {
|
||||
if self.validate_before_save() {
|
||||
if self.runtime_changed() {
|
||||
return Action::ConfirmRuntime {
|
||||
name: self.draft.name.clone(),
|
||||
from: runtime_label(&self.original),
|
||||
to: runtime_label(&self.draft),
|
||||
};
|
||||
} else {
|
||||
return Action::Save(Box::new(self.draft.clone()), self.desktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Char('E') if self.dirty() => {
|
||||
self.error =
|
||||
Some("save or discard draft changes before opening the raw file".to_owned());
|
||||
}
|
||||
KeyCode::Char('E') => return Action::OpenRaw,
|
||||
KeyCode::Esc if self.dirty() => return Action::ConfirmClose,
|
||||
KeyCode::Esc => return Action::Close,
|
||||
_ => {}
|
||||
}
|
||||
@@ -686,6 +703,21 @@ impl State {
|
||||
self.validate_before_save()
|
||||
.then(|| (Box::new(self.draft.clone()), self.desktop))
|
||||
}
|
||||
|
||||
pub fn mark_saved(&mut self, saved: &InstanceConfig, desktop: bool) {
|
||||
self.original = saved.clone();
|
||||
self.draft = saved.clone();
|
||||
self.original_desktop = desktop;
|
||||
self.desktop = desktop;
|
||||
self.error = None;
|
||||
}
|
||||
|
||||
pub fn cancel_runtime_change(&mut self) {
|
||||
self.draft.game_version = self.original.game_version.clone();
|
||||
self.draft.loader = self.original.loader;
|
||||
self.draft.loader_version = self.original.loader_version.clone();
|
||||
self.error = None;
|
||||
}
|
||||
}
|
||||
|
||||
fn runtime_label(config: &InstanceConfig) -> String {
|
||||
@@ -816,7 +848,6 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut State) {
|
||||
("h/l", " adjust"),
|
||||
("Enter", " exact"),
|
||||
("d", " default"),
|
||||
("s", " save"),
|
||||
("Esc", " back"),
|
||||
])
|
||||
} else if state.selected == 3 {
|
||||
@@ -824,7 +855,6 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut State) {
|
||||
("Enter", " runtimes"),
|
||||
("a", " auto"),
|
||||
("c", " custom"),
|
||||
("s", " save"),
|
||||
("Esc", " back"),
|
||||
])
|
||||
} else if state.selected == 7 {
|
||||
@@ -832,14 +862,12 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut State) {
|
||||
("l", " presets"),
|
||||
("Enter", " custom"),
|
||||
("d", " default"),
|
||||
("s", " save"),
|
||||
("Esc", " back"),
|
||||
])
|
||||
} else {
|
||||
super::keybind_line(&[
|
||||
("j/k", ""),
|
||||
("Enter", " edit"),
|
||||
("s", " save"),
|
||||
("E", " raw"),
|
||||
("Esc", " back"),
|
||||
])
|
||||
@@ -974,20 +1002,15 @@ fn field_line(state: &State, index: usize, label: &str) -> Line<'static> {
|
||||
} else {
|
||||
state.display_value(index)
|
||||
};
|
||||
let dirty = field_dirty(state, index);
|
||||
let mut spans = vec![
|
||||
Span::styled(
|
||||
if selected { "▶ " } else { " " },
|
||||
Style::default().fg(theme.accent()),
|
||||
),
|
||||
Span::styled(
|
||||
format!("{label:<16}"),
|
||||
format!("{label:<18}"),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
),
|
||||
Span::styled(
|
||||
if dirty { "* " } else { " " },
|
||||
Style::default().fg(theme.accent()),
|
||||
),
|
||||
Span::styled(
|
||||
value,
|
||||
Style::default()
|
||||
@@ -1083,21 +1106,6 @@ fn jvm_row_count(state: &State, width: u16) -> usize {
|
||||
rows
|
||||
}
|
||||
|
||||
fn field_dirty(state: &State, index: usize) -> bool {
|
||||
match index {
|
||||
0 => state.draft.game_version != state.original.game_version,
|
||||
1 => state.draft.loader != state.original.loader,
|
||||
2 => state.draft.loader_version != state.original.loader_version,
|
||||
3 => state.draft.java_path != state.original.java_path,
|
||||
4 => state.draft.memory_min != state.original.memory_min,
|
||||
5 => state.draft.memory_max != state.original.memory_max,
|
||||
6 => state.draft.jvm_args != state.original.jvm_args,
|
||||
7 => state.draft.resolution != state.original.resolution,
|
||||
8 => state.desktop != state.original_desktop,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn render_choice_picker(frame: &mut Frame, area: Rect, state: &State) {
|
||||
let theme = THEME.as_ref();
|
||||
let mut list_area = area;
|
||||
@@ -1310,10 +1318,13 @@ mod tests {
|
||||
fn runtime_changes_require_confirmation_before_save() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let mut state = State::new(&instance(), temp.path());
|
||||
state.draft.game_version = "1.21.2".to_owned();
|
||||
*state.loader_versions.lock().unwrap() = LoadState::Loaded(vec!["0.16.15".to_owned()]);
|
||||
state.picker = Some(VersionPicker::Loader);
|
||||
state.picker_initialized = true;
|
||||
state.picker_index = 0;
|
||||
|
||||
assert!(matches!(
|
||||
state.handle_key(&KeyEvent::from(KeyCode::Char('s'))),
|
||||
state.handle_key(&KeyEvent::from(KeyCode::Enter)),
|
||||
Action::ConfirmRuntime { .. }
|
||||
));
|
||||
assert!(state.confirmed_save().is_some());
|
||||
@@ -1349,9 +1360,9 @@ mod tests {
|
||||
let mut config = instance();
|
||||
config.config_sync_profile = Some("shared".to_owned());
|
||||
let mut state = State::new(&config, temp.path());
|
||||
state.desktop = !state.desktop;
|
||||
state.selected = 8;
|
||||
|
||||
let Action::Save(config, _) = state.handle_key(&KeyEvent::from(KeyCode::Char('s'))) else {
|
||||
let Action::Save(config, _) = state.handle_key(&KeyEvent::from(KeyCode::Enter)) else {
|
||||
panic!("expected settings save");
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user