feat(scan): 阶段1 实时显示当前扫描的目录与文件

- walker: ProgressFn 签名增加 Option<&Path> 文件参数;每个文件命中时回调

- runner: on_progress 把当前文件写入 current_file 共享槽

- home: 阶段1 卡片新增 📄 当前文件:xxx 实时显示
This commit is contained in:
2026-06-10 12:27:53 +08:00
parent 7e256c426f
commit ce6c8b70f4
3 changed files with 29 additions and 2 deletions

View File

@@ -73,10 +73,14 @@ pub async fn run(
let scan_scanned_cb = Arc::clone(&scan_scanned);
let scan_found_cb = Arc::clone(&scan_found);
let scan_dir_cb = Arc::clone(&scan_current_dir);
let mut on_progress = |_scanned: usize, found: usize, dir: &std::path::Path| {
let cur_file_cb = Arc::clone(&current_file);
let mut on_progress = |_scanned: usize, found: usize, dir: &std::path::Path, file: Option<&std::path::Path>| {
scan_scanned_cb.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
scan_found_cb.store(found, std::sync::atomic::Ordering::Relaxed);
if let Ok(mut g) = scan_dir_cb.lock() { *g = dir.display().to_string(); }
if let Some(f) = file {
if let Ok(mut g) = cur_file_cb.lock() { *g = Some(f.display().to_string()); }
}
};
let candidates = walker::walk(&cfg.scan, &cancel, |s| push_log(s.to_string()), &mut on_progress);
let scan_ms = scan_started.elapsed().as_millis();

View File

@@ -11,7 +11,8 @@ use crate::scan::filter;
/// - scanned_so_far: 已扫描的文件总数(仅候选类型)
/// - found_so_far: 当前累计已收纳的候选数
/// - current_dir: 当前正在扫描的目录路径
pub type ProgressFn<'a> = &'a mut dyn FnMut(usize, usize, &Path);
/// - current_file: 当前正在评估的文件路径(若是目录则为 None
pub type ProgressFn<'a> = &'a mut dyn FnMut(usize, usize, &Path, Option<&Path>);
/// 遍历全盘,输出满足条件的文件路径
pub fn walk(
@@ -58,6 +59,7 @@ pub fn walk(
scanned.load(Ordering::Relaxed),
found.load(Ordering::Relaxed),
p,
None,
);
}
}
@@ -65,6 +67,15 @@ pub fn walk(
}
scanned.fetch_add(1, Ordering::Relaxed);
// 先把当前文件(及所在目录)回调给 UI便于实时显示
let parent = p.parent().unwrap_or(p);
progress(
scanned.load(Ordering::Relaxed),
found.load(Ordering::Relaxed),
parent,
Some(p),
);
if filter::is_whitelisted(p, &s.whitelist) { continue; }
if !s.include_hidden && filter::is_hidden(p) { continue; }
if !s.include_system && filter::is_system(p) { continue; }

View File

@@ -94,6 +94,18 @@ pub fn draw(ui: &mut egui::Ui, app: &mut App) {
});
}
}
// 当前文件(仅在扫描阶段显示当前正在评估的文件)
if is_scanning {
if let Ok(cur) = app.current_file.lock() {
if let Some(f) = cur.as_ref() {
ui.add_space(2.0);
ui.horizontal(|ui| {
ui.label("📄 当前文件:");
ui.label(egui::RichText::new(shorten_path(f, 100)).monospace().color(material::PRIMARY_DARK));
});
}
}
}
});
ui.add_space(6.0);