show scan progress
This commit is contained in:
@@ -98,13 +98,32 @@ pub async fn disable_hibernation() -> Result<String, String> {
|
||||
|
||||
// --- 原有逻辑保持 (磁盘树等) ---
|
||||
|
||||
pub async fn run_full_scan(root_path: String, state: &DiskState) {
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct ScanProgress {
|
||||
pub file_count: u64,
|
||||
pub current_path: String,
|
||||
}
|
||||
|
||||
pub async fn run_full_scan(root_path: String, state: &DiskState, app_handle: tauri::AppHandle) {
|
||||
use jwalk::WalkDir;
|
||||
use tauri::Emitter;
|
||||
|
||||
let mut dir_sizes = HashMap::new();
|
||||
let root = Path::new(&root_path);
|
||||
let mut file_count = 0;
|
||||
|
||||
for entry in WalkDir::new(root).skip_hidden(false).into_iter().filter_map(|e| e.ok()) {
|
||||
if entry.file_type.is_file() {
|
||||
file_count += 1;
|
||||
|
||||
// 节流推送进度:每 2000 个文件推送一次,避免 IPC 过载
|
||||
if file_count % 2000 == 0 {
|
||||
let _ = app_handle.emit("scan-progress", ScanProgress {
|
||||
file_count,
|
||||
current_path: entry.parent_path().to_string_lossy().to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let size = entry.metadata().map(|m| m.len()).unwrap_or(0);
|
||||
let mut current_path = entry.parent_path().to_path_buf();
|
||||
while current_path.starts_with(root) {
|
||||
|
||||
Reference in New Issue
Block a user