diff --git a/src-tauri/src/cleaner.rs b/src-tauri/src/cleaner.rs index 11c1e21..4bc66bf 100644 --- a/src-tauri/src/cleaner.rs +++ b/src-tauri/src/cleaner.rs @@ -98,13 +98,32 @@ pub async fn disable_hibernation() -> Result { // --- 原有逻辑保持 (磁盘树等) --- -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) { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 935ec56..bb9a6cd 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -14,8 +14,8 @@ async fn start_fast_clean(selected_paths: Vec) -> Result) -> Result<(), String> { - cleaner::run_full_scan("C:\\".to_string(), &state).await; +async fn start_full_disk_scan(state: State<'_, cleaner::DiskState>, app_handle: tauri::AppHandle) -> Result<(), String> { + cleaner::run_full_scan("C:\\".to_string(), &state, app_handle).await; Ok(()) } diff --git a/src/App.vue b/src/App.vue index 0f633a9..6532c2c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,7 @@