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
@@ -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