fix(content): show installed entries with predecoded icons immediately
This commit is contained in:
1 parent
902b0e9347
commit
d38b0b74b5
2 files changed
+47
-3
No files matched your search
@@ -859,6 +859,46 @@ fn streamed_entries_without_icons_are_visible_immediately() {
|
||||
assert_eq!(state.filtered_indices(), vec![0]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn installed_predecoded_icons_are_visible_on_scan_and_cache_restore() {
|
||||
let mut state = ContentListState::default();
|
||||
state.set_installed_options(
|
||||
&crate::tui::widgets::content::discovery::DiscoveryFilters::default(),
|
||||
5,
|
||||
false,
|
||||
"26.2",
|
||||
false,
|
||||
);
|
||||
let stream = state.start_stream("main");
|
||||
let mut mod_entry = entry("Fabric API");
|
||||
let mut png = std::io::Cursor::new(Vec::new());
|
||||
image::DynamicImage::new_rgba8(1, 1)
|
||||
.write_to(&mut png, image::ImageFormat::Png)
|
||||
.unwrap();
|
||||
mod_entry.icon_bytes = Some(png.into_inner());
|
||||
mod_entry.icon_lines =
|
||||
crate::instance::content::make_icon_pixels(mod_entry.icon_bytes.as_ref().unwrap(), 6, 3);
|
||||
stream.send(mod_entry);
|
||||
state.drain_pending();
|
||||
assert_eq!(state.filtered_indices(), [0]);
|
||||
|
||||
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_eq!(state.filtered_indices(), [0]);
|
||||
assert!(!state.has_pending_icons());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rendering_visible_entries_restores_the_first_selection() {
|
||||
let mut state = ContentListState::default();
|
||||
|
||||
@@ -364,6 +364,10 @@ 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 {
|
||||
pub(crate) fn has_pending_icons(&self) -> bool {
|
||||
!self.pending_entry_images.is_empty()
|
||||
@@ -848,7 +852,7 @@ impl ContentListState {
|
||||
self.sort_metadata.get_mut().remove(&entry.path);
|
||||
self.images_dirty = true;
|
||||
received_count += 1;
|
||||
if entry.icon_bytes.is_some() || entry.provider_icon {
|
||||
if needs_icon_before_showing(&entry) {
|
||||
self.pending_entry_images.insert(entry.file_stem.clone());
|
||||
}
|
||||
self.display_metadata
|
||||
@@ -1172,7 +1176,7 @@ impl ContentListState {
|
||||
self.images_dirty = true;
|
||||
continue;
|
||||
}
|
||||
if entry.icon_bytes.is_some() {
|
||||
if needs_icon_before_showing(&entry) {
|
||||
self.pending_entry_images.insert(entry.file_stem.clone());
|
||||
}
|
||||
self.display_metadata
|
||||
@@ -1696,7 +1700,7 @@ impl ContentListState {
|
||||
self.pending_entry_images.extend(
|
||||
self.entries
|
||||
.iter()
|
||||
.filter(|entry| entry.icon_bytes.is_some())
|
||||
.filter(|entry| needs_icon_before_showing(entry))
|
||||
.map(|entry| entry.file_stem.clone()),
|
||||
);
|
||||
self.rebuild_display_metadata();
|
||||
|
||||
Reference in new issue
Block a user