fix(content): wait for final installed icons across manifest binding
This commit is contained in:
1 parent
d38b0b74b5
commit
a78bcff171
2 files changed
+41
-17
No files matched your search
@@ -17,10 +17,11 @@ use ratatui::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
ContentListState, PendingContentImage, WatcherEventHandling, available_description_width,
|
ContentListState, ContentStreamOrder, PendingContentImage, WatcherEventHandling,
|
||||||
description_text_width, diff_directory, diff_event_paths, ellipsize, load_provider_metadata,
|
available_description_width, description_text_width, diff_directory, diff_event_paths,
|
||||||
read_dir_stems, right_aligned_footer_spans, square_icon_columns, title_suffix_spans,
|
ellipsize, load_provider_metadata, read_dir_stems, right_aligned_footer_spans,
|
||||||
version_change_spans, watcher_event_handling, world_descriptions, world_game_mode_color,
|
square_icon_columns, title_suffix_spans, version_change_spans, watcher_event_handling,
|
||||||
|
world_descriptions, world_game_mode_color,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn entry(name: &str) -> ContentEntry {
|
fn entry(name: &str) -> ContentEntry {
|
||||||
@@ -644,7 +645,10 @@ fn discovery_stream_shows_each_row_after_its_icon_is_ready() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stale_decoded_icon_does_not_replace_a_new_source_or_new_bytes() {
|
fn stale_decoded_icon_does_not_replace_a_new_source_or_new_bytes() {
|
||||||
let mut state = ContentListState::default();
|
let mut state = ContentListState {
|
||||||
|
stream_order: ContentStreamOrder::Source,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
let mut project = entry("Alpha");
|
let mut project = entry("Alpha");
|
||||||
project.provider_project = Some(crate::instance::ProviderProject {
|
project.provider_project = Some(crate::instance::ProviderProject {
|
||||||
provider: "modrinth".to_owned(),
|
provider: "modrinth".to_owned(),
|
||||||
@@ -860,7 +864,7 @@ fn streamed_entries_without_icons_are_visible_immediately() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn installed_predecoded_icons_are_visible_on_scan_and_cache_restore() {
|
async fn installed_icon_decode_survives_manifest_binding_and_cache_restore() {
|
||||||
let mut state = ContentListState::default();
|
let mut state = ContentListState::default();
|
||||||
state.set_installed_options(
|
state.set_installed_options(
|
||||||
&crate::tui::widgets::content::discovery::DiscoveryFilters::default(),
|
&crate::tui::widgets::content::discovery::DiscoveryFilters::default(),
|
||||||
@@ -880,7 +884,22 @@ async fn installed_predecoded_icons_are_visible_on_scan_and_cache_restore() {
|
|||||||
crate::instance::content::make_icon_pixels(mod_entry.icon_bytes.as_ref().unwrap(), 6, 3);
|
crate::instance::content::make_icon_pixels(mod_entry.icon_bytes.as_ref().unwrap(), 6, 3);
|
||||||
stream.send(mod_entry);
|
stream.send(mod_entry);
|
||||||
state.drain_pending();
|
state.drain_pending();
|
||||||
assert_eq!(state.filtered_indices(), [0]);
|
assert!(state.filtered_indices().is_empty());
|
||||||
|
let picker = ratatui_image::picker::Picker::halfblocks();
|
||||||
|
state.request_image_loads(&picker);
|
||||||
|
state.entries[0].provider_project = Some(crate::instance::ProviderProject {
|
||||||
|
provider: "modrinth".to_owned(),
|
||||||
|
project_id: "fabric-api".to_owned(),
|
||||||
|
version_id: "version".to_owned(),
|
||||||
|
});
|
||||||
|
tokio::time::timeout(std::time::Duration::from_secs(5), async {
|
||||||
|
while state.filtered_indices().is_empty() {
|
||||||
|
state.drain_image_loads(&picker);
|
||||||
|
tokio::task::yield_now().await;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("installed icon decoded after manifest binding");
|
||||||
|
|
||||||
let directory = tempfile::tempdir().unwrap();
|
let directory = tempfile::tempdir().unwrap();
|
||||||
state.start_load(
|
state.start_load(
|
||||||
@@ -895,8 +914,16 @@ async fn installed_predecoded_icons_are_visible_on_scan_and_cache_restore() {
|
|||||||
crate::instance::content::mods::scan_one_mod,
|
crate::instance::content::mods::scan_one_mod,
|
||||||
"jar",
|
"jar",
|
||||||
);
|
);
|
||||||
assert_eq!(state.filtered_indices(), [0]);
|
assert!(state.filtered_indices().is_empty());
|
||||||
assert!(!state.has_pending_icons());
|
state.request_image_loads(&picker);
|
||||||
|
tokio::time::timeout(std::time::Duration::from_secs(5), async {
|
||||||
|
while state.filtered_indices().is_empty() {
|
||||||
|
state.drain_image_loads(&picker);
|
||||||
|
tokio::task::yield_now().await;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("cached installed icon decoded");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -364,10 +364,6 @@ impl Default for ContentListState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn needs_icon_before_showing(entry: &ContentEntry) -> bool {
|
|
||||||
entry.icon_lines.is_none() && (entry.icon_bytes.is_some() || entry.provider_icon)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ContentListState {
|
impl ContentListState {
|
||||||
pub(crate) fn has_pending_icons(&self) -> bool {
|
pub(crate) fn has_pending_icons(&self) -> bool {
|
||||||
!self.pending_entry_images.is_empty()
|
!self.pending_entry_images.is_empty()
|
||||||
@@ -813,7 +809,8 @@ impl ContentListState {
|
|||||||
if let Some(entry) = self.entries.iter_mut().find(|entry| {
|
if let Some(entry) = self.entries.iter_mut().find(|entry| {
|
||||||
entry.file_stem == result.file_stem
|
entry.file_stem == result.file_stem
|
||||||
&& entry.path == result.path
|
&& entry.path == result.path
|
||||||
&& entry.provider_project == result.source
|
&& (matches!(self.stream_order, ContentStreamOrder::Sorted)
|
||||||
|
|| entry.provider_project == result.source)
|
||||||
&& entry.icon_bytes.as_ref() == Some(&result.icon_bytes)
|
&& entry.icon_bytes.as_ref() == Some(&result.icon_bytes)
|
||||||
}) {
|
}) {
|
||||||
self.pending_entry_images.remove(&result.file_stem);
|
self.pending_entry_images.remove(&result.file_stem);
|
||||||
@@ -852,7 +849,7 @@ impl ContentListState {
|
|||||||
self.sort_metadata.get_mut().remove(&entry.path);
|
self.sort_metadata.get_mut().remove(&entry.path);
|
||||||
self.images_dirty = true;
|
self.images_dirty = true;
|
||||||
received_count += 1;
|
received_count += 1;
|
||||||
if needs_icon_before_showing(&entry) {
|
if entry.icon_bytes.is_some() || entry.provider_icon {
|
||||||
self.pending_entry_images.insert(entry.file_stem.clone());
|
self.pending_entry_images.insert(entry.file_stem.clone());
|
||||||
}
|
}
|
||||||
self.display_metadata
|
self.display_metadata
|
||||||
@@ -1176,7 +1173,7 @@ impl ContentListState {
|
|||||||
self.images_dirty = true;
|
self.images_dirty = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if needs_icon_before_showing(&entry) {
|
if entry.icon_bytes.is_some() || entry.provider_icon {
|
||||||
self.pending_entry_images.insert(entry.file_stem.clone());
|
self.pending_entry_images.insert(entry.file_stem.clone());
|
||||||
}
|
}
|
||||||
self.display_metadata
|
self.display_metadata
|
||||||
@@ -1700,7 +1697,7 @@ impl ContentListState {
|
|||||||
self.pending_entry_images.extend(
|
self.pending_entry_images.extend(
|
||||||
self.entries
|
self.entries
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|entry| needs_icon_before_showing(entry))
|
.filter(|entry| entry.icon_bytes.is_some() || entry.provider_icon)
|
||||||
.map(|entry| entry.file_stem.clone()),
|
.map(|entry| entry.file_stem.clone()),
|
||||||
);
|
);
|
||||||
self.rebuild_display_metadata();
|
self.rebuild_display_metadata();
|
||||||
|
|||||||
Reference in new issue
Block a user