fix: ignore stale TUI results and show narrow settings
This commit is contained in:
1 parent
0d1cafcb10
commit
75c74333c5
14 files changed
+268
-93
No files matched your search
+28
-3
@@ -48,6 +48,16 @@ impl App {
|
||||
if let Some(state) = self.modpack_versions_state.as_mut() {
|
||||
state.drain_pending();
|
||||
}
|
||||
if self.content_update_popup.as_ref().is_some_and(|update| {
|
||||
update.phase != widgets::content::update::Phase::Applying
|
||||
&& self
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.map(|instance| instance.name.as_str())
|
||||
!= Some(update.instance_name.as_str())
|
||||
}) {
|
||||
self.content_update_popup = None;
|
||||
}
|
||||
let content_update_completed = self.content_update_popup.as_mut().and_then(|update| {
|
||||
update.drain();
|
||||
update.list.request_image_loads(&self.picker);
|
||||
@@ -700,15 +710,21 @@ impl App {
|
||||
let editor = std::env::var("EDITOR")
|
||||
.or_else(|_| std::env::var("VISUAL"))
|
||||
.unwrap_or_else(|_| default_editor.to_owned());
|
||||
let parts = editor_parts(&editor);
|
||||
let Some((program, args)) = parts.split_first() else {
|
||||
tracing::error!("Editor command is empty");
|
||||
return false;
|
||||
};
|
||||
|
||||
let is_tui_editor = editor_runs_in_terminal(&editor);
|
||||
let is_tui_editor = editor_runs_in_terminal(program);
|
||||
|
||||
if is_tui_editor {
|
||||
let _ = stdout().execute(DisableMouseCapture);
|
||||
let _ = stdout().execute(LeaveAlternateScreen);
|
||||
let _ = disable_raw_mode();
|
||||
|
||||
let result = std::process::Command::new(&editor)
|
||||
let result = std::process::Command::new(program)
|
||||
.args(args)
|
||||
.arg(path)
|
||||
.stdin(std::process::Stdio::inherit())
|
||||
.stdout(std::process::Stdio::inherit())
|
||||
@@ -726,7 +742,8 @@ impl App {
|
||||
}
|
||||
true
|
||||
} else {
|
||||
if let Err(e) = std::process::Command::new(&editor)
|
||||
if let Err(e) = std::process::Command::new(program)
|
||||
.args(args)
|
||||
.arg(path)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
@@ -1106,6 +1123,14 @@ fn editor_runs_in_terminal(editor: &str) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
fn editor_parts(editor: &str) -> Vec<&str> {
|
||||
if std::path::Path::new(editor).is_file() {
|
||||
vec![editor]
|
||||
} else {
|
||||
editor.split_whitespace().collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/event.rs"]
|
||||
mod tests;
|
||||
+36
-9
@@ -58,6 +58,17 @@ impl App {
|
||||
}
|
||||
|
||||
pub(super) fn handle_key_event(&mut self, key_event: KeyEvent) -> color_eyre::Result<()> {
|
||||
if self.content_update_popup.as_ref().is_some_and(|update| {
|
||||
update.phase != widgets::content::update::Phase::Applying
|
||||
&& self
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.map(|instance| instance.name.as_str())
|
||||
!= Some(update.instance_name.as_str())
|
||||
}) {
|
||||
self.content_update_popup = None;
|
||||
return Ok(());
|
||||
}
|
||||
if self
|
||||
.content_update_popup
|
||||
.as_ref()
|
||||
@@ -206,7 +217,15 @@ impl App {
|
||||
.accounts
|
||||
.get(index)
|
||||
.map(|account| account.uuid.clone());
|
||||
self.account_state.store.remove(index);
|
||||
if let Err(error) = self.account_state.store.remove(index) {
|
||||
error_buffer::push_message(
|
||||
tracing::Level::ERROR,
|
||||
error.to_string(),
|
||||
);
|
||||
self.focused = FocusedArea::Account;
|
||||
confirm_popup::clear_pending();
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(removed_uuid) = removed_uuid {
|
||||
for instance in &mut self.instances_state.instances {
|
||||
if instance.preferred_account.as_deref()
|
||||
@@ -679,6 +698,12 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::Account
|
||||
&& widgets::account::handle_key(&key_event, &mut self.account_state)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::Account
|
||||
&& let KeyCode::Char('d') = key_event.code
|
||||
&& let Some(index) = self.account_state.list_state.selected
|
||||
@@ -692,12 +717,6 @@ impl App {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::Account
|
||||
&& widgets::account::handle_key(&key_event, &mut self.account_state)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::Settings {
|
||||
let editing_profile = matches!(
|
||||
&self.settings_state.add_mode,
|
||||
@@ -1484,8 +1503,12 @@ impl App {
|
||||
{
|
||||
return;
|
||||
}
|
||||
let state =
|
||||
widgets::content::update::State::checking(kind, target_world.clone(), source_entries);
|
||||
let state = widgets::content::update::State::checking(
|
||||
instance.name.clone(),
|
||||
kind,
|
||||
target_world.clone(),
|
||||
source_entries,
|
||||
);
|
||||
let pending = state.pending.clone();
|
||||
self.content_update_popup = Some(state);
|
||||
tokio::spawn(async move {
|
||||
@@ -1590,6 +1613,10 @@ impl App {
|
||||
let Some(state) = self.content_update_popup.as_mut() else {
|
||||
return;
|
||||
};
|
||||
if state.instance_name != instance.name {
|
||||
self.content_update_popup = None;
|
||||
return;
|
||||
}
|
||||
let Some(plan) = state.plan.as_ref().map(|plan| plan.dependency_plan.clone()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -200,11 +200,10 @@ fn structural_settings_update_repairs_runtime_before_persisting() {
|
||||
.mount(&server)
|
||||
.await;
|
||||
}
|
||||
let asset_index = serde_json::to_vec(&serde_json::json!({"objects": {}})).unwrap();
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/assets.json"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"objects": {}
|
||||
})))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_bytes(asset_index.clone()))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
@@ -252,7 +251,7 @@ fn structural_settings_update_repairs_runtime_before_persisting() {
|
||||
"assetIndex": {
|
||||
"id": "1.21.2",
|
||||
"url": format!("{}/assets.json", server.uri()),
|
||||
"sha1": "unused"
|
||||
"sha1": sha1(&asset_index)
|
||||
},
|
||||
"downloads": {
|
||||
"client": {
|
||||
@@ -364,6 +363,7 @@ fn editor_kind_is_detected_from_the_executable_name() {
|
||||
assert!(editor_runs_in_terminal("/usr/bin/nvim"));
|
||||
assert!(editor_runs_in_terminal("nano"));
|
||||
assert!(!editor_runs_in_terminal("/usr/bin/code"));
|
||||
assert_eq!(editor_parts("nvim -u NONE"), ["nvim", "-u", "NONE"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -666,6 +666,43 @@ fn confirmed_account_delete_updates_the_account_panel() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typing_d_in_offline_account_name_does_not_open_delete_confirmation() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_account("MicrosoftPlayer");
|
||||
ui.app.focused = FocusedArea::Account;
|
||||
|
||||
ui.key(KeyCode::Char('a'));
|
||||
ui.key(KeyCode::Char('o'));
|
||||
ui.key(KeyCode::Char('d'));
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::Account);
|
||||
assert!(matches!(
|
||||
&ui.app.account_state.add_mode,
|
||||
crate::tui::widgets::account::AddMode::OfflineNameInput(name) if name == "d"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn switching_instances_discards_another_instances_update_review() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("A");
|
||||
ui.add_instance("B");
|
||||
let mut update = crate::tui::widgets::content::update::State::checking(
|
||||
"A".to_owned(),
|
||||
ContentKind::Mod,
|
||||
None,
|
||||
Vec::new(),
|
||||
);
|
||||
update.phase = crate::tui::widgets::content::update::Phase::Review;
|
||||
ui.app.content_update_popup = Some(update);
|
||||
ui.app.instances_state.list_state.selected = Some(1);
|
||||
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert!(ui.app.content_update_popup.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_panel_routes_legacy_edit_keys_to_tui_popups() {
|
||||
let mut ui = UiHarness::new();
|
||||
|
||||
@@ -967,7 +967,7 @@ fn streamed_entries_without_icons_are_visible_immediately() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn installed_icon_decode_survives_manifest_binding_and_cache_restore() {
|
||||
async fn installed_icon_decode_survives_manifest_binding() {
|
||||
let mut state = ContentListState::default();
|
||||
state.set_installed_options(
|
||||
&crate::tui::widgets::content::discovery::DiscoveryFilters::default(),
|
||||
@@ -1003,30 +1003,62 @@ async fn installed_icon_decode_survives_manifest_binding_and_cache_restore() {
|
||||
})
|
||||
.await
|
||||
.expect("installed icon decoded after manifest binding");
|
||||
}
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
state.start_load(
|
||||
directory.path(),
|
||||
"other",
|
||||
crate::instance::content::mods::scan_one_mod,
|
||||
"jar",
|
||||
);
|
||||
state.start_load(
|
||||
directory.path(),
|
||||
"main",
|
||||
crate::instance::content::mods::scan_one_mod,
|
||||
"jar",
|
||||
);
|
||||
assert!(state.filtered_indices().is_empty());
|
||||
state.request_image_loads(&picker);
|
||||
#[tokio::test]
|
||||
async fn switching_back_rescans_content_changed_while_inactive() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let first = temp.path().join("first");
|
||||
let second = temp.path().join("second");
|
||||
std::fs::create_dir_all(&first).unwrap();
|
||||
std::fs::create_dir_all(&second).unwrap();
|
||||
std::fs::write(first.join("old.jar"), b"old").unwrap();
|
||||
let mut state = ContentListState::default();
|
||||
let scanner = crate::instance::content::mods::scan_one_mod;
|
||||
state.start_load(&first, "first", scanner, ".jar");
|
||||
tokio::time::timeout(std::time::Duration::from_secs(5), async {
|
||||
while state.filtered_indices().is_empty() {
|
||||
state.drain_image_loads(&picker);
|
||||
while state.loading {
|
||||
state.drain_pending();
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("cached installed icon decoded");
|
||||
.unwrap();
|
||||
assert_eq!(state.entries.len(), 1);
|
||||
|
||||
state.start_load(&second, "second", scanner, ".jar");
|
||||
std::fs::remove_file(first.join("old.jar")).unwrap();
|
||||
std::fs::write(first.join("new.jar"), b"new").unwrap();
|
||||
state.start_load(&first, "first", scanner, ".jar");
|
||||
tokio::time::timeout(std::time::Duration::from_secs(5), async {
|
||||
while state.loading {
|
||||
state.drain_pending();
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(state.entries.len(), 1);
|
||||
assert_eq!(state.entries[0].path, first.join("new.jar"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_watcher_results_cannot_update_a_new_instance() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let mut state = ContentListState::default();
|
||||
let old_slot = state.watcher_diff.clone();
|
||||
state.watch_dir(temp.path().to_owned());
|
||||
*old_slot.lock().unwrap() = Some(super::WatcherDiff {
|
||||
toggled: vec![(
|
||||
"test".to_owned(),
|
||||
false,
|
||||
temp.path().join("test.jar.disabled"),
|
||||
)],
|
||||
removed: Vec::new(),
|
||||
added: Vec::new(),
|
||||
});
|
||||
|
||||
assert!(state.drain_watcher().toggles.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -74,6 +74,7 @@ fn snapshot() -> UpdateSnapshot {
|
||||
#[test]
|
||||
fn update_review_reuses_content_rows() {
|
||||
let mut state = State::checking(
|
||||
"Instance".to_owned(),
|
||||
ContentKind::Mod,
|
||||
None,
|
||||
vec![entry("Example Mod", "mods/example.jar")],
|
||||
@@ -101,6 +102,7 @@ fn update_conflicts_explain_why_the_item_was_not_updated() {
|
||||
.to_owned(),
|
||||
});
|
||||
let mut state = State::checking(
|
||||
"Instance".to_owned(),
|
||||
ContentKind::Mod,
|
||||
None,
|
||||
vec![entry("Example Mod", "mods/example.jar")],
|
||||
|
||||
@@ -3,6 +3,62 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn narrow_settings_shows_the_selected_pane() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf());
|
||||
let instance: InstanceConfig = serde_json::from_value(serde_json::json!({
|
||||
"name": "Test", "game_version": "1.21", "loader": "vanilla",
|
||||
"loader_version": null, "created": "2026-01-01T00:00:00Z", "java_path": "test-java"
|
||||
}))
|
||||
.unwrap();
|
||||
state.java_key = Some("test-java".to_owned());
|
||||
state.java_label = "jdk17".to_owned();
|
||||
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(35, 8)).unwrap();
|
||||
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
render(
|
||||
frame,
|
||||
frame.area(),
|
||||
FocusedArea::Settings,
|
||||
&mut state,
|
||||
Some(&instance),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
let text = terminal
|
||||
.backend()
|
||||
.buffer()
|
||||
.content()
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(text.contains(LOCAL_PROFILE_LABEL));
|
||||
|
||||
state.pane = SettingsPane::Info;
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
render(
|
||||
frame,
|
||||
frame.area(),
|
||||
FocusedArea::Settings,
|
||||
&mut state,
|
||||
Some(&instance),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
let text = terminal
|
||||
.backend()
|
||||
.buffer()
|
||||
.content()
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(text.contains("Memory"));
|
||||
assert!(text.contains("jdk17"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_selected_last_profile_clamps_selection() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -66,7 +66,12 @@ impl AccountState {
|
||||
if let Some(result) = result {
|
||||
match result {
|
||||
AuthResult::Success(account) => {
|
||||
self.store.add(account);
|
||||
if let Err(error) = self.store.add(account) {
|
||||
crate::feedback::errors::push_message(
|
||||
tracing::Level::ERROR,
|
||||
error.to_string(),
|
||||
);
|
||||
}
|
||||
self.add_mode = AddMode::None;
|
||||
if self.list_state.selected.is_none() && !self.store.accounts.is_empty() {
|
||||
self.list_state.selected = Some(0);
|
||||
@@ -116,7 +121,12 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut AccountState) -> bool {
|
||||
if !trimmed.is_empty() {
|
||||
if state.store.has_microsoft_account() {
|
||||
let account = auth::create_offline_account(&trimmed);
|
||||
state.store.add(account);
|
||||
if let Err(error) = state.store.add(account) {
|
||||
crate::feedback::errors::push_message(
|
||||
tracing::Level::ERROR,
|
||||
error.to_string(),
|
||||
);
|
||||
}
|
||||
if state.list_state.selected.is_none() && !state.store.accounts.is_empty() {
|
||||
state.list_state.selected = Some(0);
|
||||
}
|
||||
@@ -169,8 +179,13 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut AccountState) -> bool {
|
||||
true
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if let Some(idx) = state.list_state.selected {
|
||||
state.store.set_active(idx);
|
||||
if let Some(idx) = state.list_state.selected
|
||||
&& let Err(error) = state.store.set_active(idx)
|
||||
{
|
||||
crate::feedback::errors::push_message(
|
||||
tracing::Level::ERROR,
|
||||
error.to_string(),
|
||||
);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -170,12 +170,6 @@ enum ContentStreamUpdate {
|
||||
},
|
||||
}
|
||||
|
||||
struct CachedList {
|
||||
entries: Vec<ContentEntry>,
|
||||
selected: Option<usize>,
|
||||
sort_metadata: HashMap<std::path::PathBuf, FileSortMetadata>,
|
||||
}
|
||||
|
||||
struct FileSortMetadata {
|
||||
name: String,
|
||||
size: Option<u64>,
|
||||
@@ -283,7 +277,6 @@ pub struct ContentListState {
|
||||
display_metadata: HashMap<String, DisplayMetadata>,
|
||||
pub search: crate::tui::widgets::search::SearchState,
|
||||
filter_search: bool,
|
||||
cache: HashMap<String, CachedList>,
|
||||
sort_metadata: RefCell<HashMap<std::path::PathBuf, FileSortMetadata>>,
|
||||
filtered_cache: RefCell<Option<CachedSelection>>,
|
||||
stream_rx: Option<mpsc::Receiver<ContentStreamUpdate>>,
|
||||
@@ -337,7 +330,6 @@ impl Default for ContentListState {
|
||||
display_metadata: HashMap::new(),
|
||||
search: crate::tui::widgets::search::SearchState::default(),
|
||||
filter_search: true,
|
||||
cache: HashMap::new(),
|
||||
sort_metadata: RefCell::new(HashMap::new()),
|
||||
filtered_cache: RefCell::new(None),
|
||||
stream_rx: None,
|
||||
@@ -1303,6 +1295,7 @@ impl ContentListState {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
self._watcher = None;
|
||||
self.watcher_diff = Arc::new(Mutex::new(None));
|
||||
|
||||
let watcher_diff = self.watcher_diff.clone();
|
||||
let ext: &'static str = self.content_ext.unwrap_or(".jar");
|
||||
@@ -1678,8 +1671,6 @@ async fn load_installed_version(
|
||||
impl ContentListState {
|
||||
pub fn forget_instance(&mut self, instance_name: &str) {
|
||||
let world_prefix = format!("{instance_name}:");
|
||||
self.cache
|
||||
.retain(|source, _| source != instance_name && !source.starts_with(&world_prefix));
|
||||
if self
|
||||
.loaded_for
|
||||
.as_deref()
|
||||
@@ -1706,49 +1697,6 @@ impl ContentListState {
|
||||
self.pending_entry_images.clear();
|
||||
self.pending_removals.clear();
|
||||
|
||||
if let Some(prev) = self.loaded_for.take()
|
||||
&& !self.entries.is_empty()
|
||||
{
|
||||
tracing::trace!(
|
||||
"Caching {} content entries for {}",
|
||||
self.entries.len(),
|
||||
prev
|
||||
);
|
||||
self.cache.insert(
|
||||
prev,
|
||||
CachedList {
|
||||
entries: std::mem::take(&mut self.entries),
|
||||
selected: self.list_state.selected,
|
||||
sort_metadata: std::mem::take(self.sort_metadata.get_mut()),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// files modified while another instance was active become a real problem.
|
||||
if let Some(cached) = self.cache.remove(instance_name) {
|
||||
self.entries = cached.entries;
|
||||
self.invalidate_filtered();
|
||||
*self.sort_metadata.get_mut() = cached.sort_metadata;
|
||||
self.pending_entry_images.extend(
|
||||
self.entries
|
||||
.iter()
|
||||
.filter(|entry| entry.icon_bytes.is_some() || entry.provider_icon)
|
||||
.map(|entry| entry.file_stem.clone()),
|
||||
);
|
||||
self.rebuild_display_metadata();
|
||||
self.list_state.selected = cached.selected;
|
||||
self.loading = false;
|
||||
self.stream_rx = None;
|
||||
self.loaded_for = Some(instance_name.to_string());
|
||||
self.update_scrollbar();
|
||||
tracing::debug!(
|
||||
"Restored {} cached content entries for {}",
|
||||
self.entries.len(),
|
||||
instance_name
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let stream = self.start_stream(instance_name);
|
||||
|
||||
let dir = content_dir.to_path_buf();
|
||||
|
||||
@@ -30,6 +30,7 @@ pub enum Phase {
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
pub instance_name: String,
|
||||
pub phase: Phase,
|
||||
pub plan: Option<BulkUpdatePlan>,
|
||||
pub snapshot: Option<UpdateSnapshot>,
|
||||
@@ -44,11 +45,13 @@ pub struct State {
|
||||
|
||||
impl State {
|
||||
pub fn checking(
|
||||
instance_name: String,
|
||||
kind: ContentKind,
|
||||
target_world: Option<(String, PathBuf)>,
|
||||
entries: Vec<ContentEntry>,
|
||||
) -> Self {
|
||||
Self {
|
||||
instance_name,
|
||||
phase: Phase::Checking,
|
||||
plan: None,
|
||||
snapshot: None,
|
||||
|
||||
@@ -66,6 +66,7 @@ impl Default for LogsState {
|
||||
|
||||
impl LogsState {
|
||||
pub fn start_load(&mut self, instances_dir: &Path, instance_name: &str) {
|
||||
self.pending = Arc::new(Mutex::new(None));
|
||||
self.loading = true;
|
||||
self.loaded_for = Some(instance_name.to_string());
|
||||
self.instances_dir_cache = Some(instances_dir.to_path_buf());
|
||||
@@ -149,6 +150,7 @@ impl LogsState {
|
||||
|
||||
let dir = dir.clone();
|
||||
let tag = name.clone();
|
||||
self.pending = Arc::new(Mutex::new(None));
|
||||
let pending = self.pending.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -35,6 +35,7 @@ pub enum WizardStep {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WizardState {
|
||||
request_epoch: u64,
|
||||
pub step: WizardStep,
|
||||
pub name_state: TextState<'static>,
|
||||
pub versions: LoadState<Vec<GameVersion>>,
|
||||
@@ -49,6 +50,7 @@ pub struct WizardState {
|
||||
impl Default for WizardState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
request_epoch: 0,
|
||||
step: WizardStep::Name,
|
||||
name_state: TextState::new().with_focus(FocusState::Focused),
|
||||
versions: LoadState::Idle,
|
||||
@@ -64,7 +66,9 @@ impl Default for WizardState {
|
||||
|
||||
impl WizardState {
|
||||
pub fn reset(&mut self) {
|
||||
let next_epoch = self.request_epoch.wrapping_add(1);
|
||||
*self = WizardState::default();
|
||||
self.request_epoch = next_epoch;
|
||||
}
|
||||
|
||||
pub fn selected_version(&self) -> Option<&GameVersion> {
|
||||
@@ -381,12 +385,17 @@ pub(crate) fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
}
|
||||
|
||||
state.versions = LoadState::Loading;
|
||||
state.request_epoch = state.request_epoch.wrapping_add(1);
|
||||
let epoch = state.request_epoch;
|
||||
let versions_arc = WIZARD_STATE.clone();
|
||||
let loader = state.selected_loader();
|
||||
tokio::spawn(async move {
|
||||
match super::super::version_lists::game_versions(loader).await {
|
||||
Ok(versions) => match versions_arc.lock() {
|
||||
Ok(mut s) => {
|
||||
if s.request_epoch != epoch || !matches!(s.versions, LoadState::Loading) {
|
||||
return;
|
||||
}
|
||||
s.versions = LoadState::Loaded(versions);
|
||||
clamp_version_index(&mut s);
|
||||
}
|
||||
@@ -396,6 +405,9 @@ pub(crate) fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
},
|
||||
Err(e) => match versions_arc.lock() {
|
||||
Ok(mut s) => {
|
||||
if s.request_epoch != epoch || !matches!(s.versions, LoadState::Loading) {
|
||||
return;
|
||||
}
|
||||
s.versions = LoadState::Error(e.to_string());
|
||||
}
|
||||
Err(lock_error) => {
|
||||
@@ -416,11 +428,17 @@ pub(crate) fn ensure_loader_versions_loaded(
|
||||
}
|
||||
|
||||
state.loader_versions = LoadState::Loading;
|
||||
state.request_epoch = state.request_epoch.wrapping_add(1);
|
||||
let epoch = state.request_epoch;
|
||||
let versions_arc = WIZARD_STATE.clone();
|
||||
tokio::spawn(async move {
|
||||
match super::super::version_lists::loader_versions(loader, &game_version).await {
|
||||
Ok(versions) => match versions_arc.lock() {
|
||||
Ok(mut s) => {
|
||||
if s.request_epoch != epoch || !matches!(s.loader_versions, LoadState::Loading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
s.loader_versions = LoadState::Loaded(versions);
|
||||
clamp_loader_version_index(&mut s);
|
||||
}
|
||||
@@ -430,6 +448,10 @@ pub(crate) fn ensure_loader_versions_loaded(
|
||||
},
|
||||
Err(e) => match versions_arc.lock() {
|
||||
Ok(mut s) => {
|
||||
if s.request_epoch != epoch || !matches!(s.loader_versions, LoadState::Loading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
s.loader_versions = LoadState::Error(e.to_string());
|
||||
}
|
||||
Err(lock_error) => {
|
||||
|
||||
@@ -85,6 +85,8 @@ impl Default for ScreenshotsState {
|
||||
|
||||
impl ScreenshotsState {
|
||||
pub fn start_load(&mut self, instances_dir: &Path, instance_name: &str) {
|
||||
self.pending_entries = Arc::new(Mutex::new(None));
|
||||
self.pending_images = Arc::new(Mutex::new(Vec::new()));
|
||||
self.loading = true;
|
||||
self.loaded_for = Some(instance_name.to_string());
|
||||
self.entries.clear();
|
||||
@@ -217,6 +219,7 @@ impl ScreenshotsState {
|
||||
|
||||
pub fn remove_path(&mut self, path: &Path) {
|
||||
self.entries.retain(|entry| entry.path != path);
|
||||
self.pending_images = Arc::new(Mutex::new(Vec::new()));
|
||||
self.protocols.clear();
|
||||
self.requested.clear();
|
||||
|
||||
|
||||
@@ -252,7 +252,10 @@ pub fn render(
|
||||
render_separator(frame, chunks[1], focused, state.pane);
|
||||
render_instance_info(frame, chunks[2], focused, state, instance);
|
||||
} else {
|
||||
render_profile_list(frame, inner, focused, state);
|
||||
match state.pane {
|
||||
SettingsPane::Profile => render_profile_list(frame, inner, focused, state),
|
||||
SettingsPane::Info => render_instance_info(frame, inner, focused, state, instance),
|
||||
}
|
||||
}
|
||||
|
||||
if let AddMode::ProfileName(name) = &state.add_mode {
|
||||
|
||||
Reference in new issue
Block a user