fix(content): stabilize indexing progress

This commit is contained in:
objz committed 2026-07-25 12:44:52 +02:00
1 parent 0a930a4f86
commit 32a5868894
11 files changed
+151 -39

No files matched your search

+22 -9
View File
@@ -199,11 +199,8 @@ pub fn set_sub_action(text: impl Into<String>) {
pub fn clear() {
match PROGRESS.lock() {
Ok(mut state) => {
state.current_action = None;
state.progress = None;
state.sub_action = None;
state.tasks.clear();
state.legacy_active = false;
refresh_visible(&mut state);
crate::tui::request_redraw();
}
Err(e) => {
@@ -212,6 +209,12 @@ pub fn clear() {
}
}
pub fn is_active() -> bool {
PROGRESS
.lock()
.is_ok_and(|state| state.current_action.is_some())
}
#[cfg(test)]
mod tests {
use super::*;
@@ -256,10 +259,20 @@ mod tests {
assert!(!is_active());
clear();
}
}
pub fn is_active() -> bool {
PROGRESS
.lock()
.is_ok_and(|state| state.current_action.is_some())
#[test]
fn clearing_legacy_progress_keeps_owned_tasks() {
let _guard = TEST_LOCK.lock().unwrap();
clear();
let task = ProgressTask::start("indexing");
set_action("legacy download");
clear();
let state = PROGRESS.lock().unwrap();
assert_eq!(state.current_action.as_deref(), Some("indexing"));
drop(state);
task.finish();
clear();
}
}
+1
View File
@@ -600,6 +600,7 @@ pub(crate) fn project_entry(
description: project.description,
enabled: true,
icon_bytes: project.icon_bytes,
provider_icon: true,
path: PathBuf::from(project.id),
icon_lines: Some(crate::instance::content::mods::fallback_icon()),
}
+26 -6
View File
@@ -199,6 +199,11 @@ impl ContentListState {
.filter(|record| record.kind == kind)
else {
if entry.provider_project.take().is_some() {
if entry.provider_icon {
entry.icon_bytes = None;
entry.icon_lines = Some(crate::instance::content::mods::fallback_icon());
entry.provider_icon = false;
}
changed = true;
}
continue;
@@ -208,6 +213,11 @@ impl ContentListState {
_ => None,
};
if entry.provider_project != project {
if entry.provider_icon {
entry.icon_bytes = None;
entry.icon_lines = Some(crate::instance::content::mods::fallback_icon());
entry.provider_icon = false;
}
entry.provider_project = project.clone();
changed = true;
}
@@ -219,6 +229,7 @@ impl ContentListState {
{
entry.icon_bytes = Some(bytes.clone());
entry.icon_lines = Some(lines);
entry.provider_icon = true;
changed = true;
}
}
@@ -408,7 +419,7 @@ impl ContentListState {
.iter_mut()
.find(|existing| existing.file_stem == entry.file_stem)
{
if entry.icon_bytes.is_none() {
if entry.icon_bytes.is_none() && !existing.provider_icon {
entry.icon_bytes = existing.icon_bytes.take();
entry.icon_lines = existing.icon_lines.take();
}
@@ -443,6 +454,7 @@ impl ContentListState {
.find(|entry| entry.file_stem == file_stem && entry.path == path)
{
entry.icon_bytes = Some(bytes);
entry.provider_icon = true;
self.requested_images.remove(&file_stem);
self.images_dirty = true;
}
@@ -1570,7 +1582,11 @@ fn available_description_width(
has_icon: bool,
) -> usize {
let selector_and_scrollbar = 2;
let icon_and_gap = has_icon.then_some(rendered_icon_columns + 1).unwrap_or(0);
let icon_and_gap = if has_icon {
rendered_icon_columns + 1
} else {
0
};
row_width.saturating_sub(selector_and_scrollbar + icon_and_gap)
}
@@ -1592,9 +1608,11 @@ fn right_aligned_footer_spans(
footer_label: &str,
footer_style: Style,
) -> Vec<Span<'static>> {
let description_width = has_description
.then(|| Span::raw(description).width())
.unwrap_or(0);
let description_width = if has_description {
Span::raw(description).width()
} else {
0
};
let footer_width = Span::raw(footer_label).width();
let padding = available_width.saturating_sub(description_width + footer_width);
vec![
@@ -1734,7 +1752,8 @@ fn diff_event_paths(
} else {
let removed_stems = known_map
.iter()
.filter_map(|(stem, (known_path, _))| (known_path == path).then(|| stem.clone()))
.filter(|(_, (known_path, _))| known_path == path)
.map(|(stem, _)| stem.clone())
.collect::<Vec<_>>();
for stem in removed_stems {
known_map.remove(&stem);
@@ -1863,6 +1882,7 @@ mod tests {
description: String::new(),
enabled: true,
icon_bytes: None,
provider_icon: false,
path: PathBuf::from(name.to_lowercase()),
icon_lines: None,
}