show scan progress

This commit is contained in:
Julian Freeman
2026-03-03 16:27:43 -04:00
parent 8efbb3ebc4
commit 39e2f41aab
3 changed files with 50 additions and 6 deletions

View File

@@ -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) {

View File

@@ -14,8 +14,8 @@ async fn start_fast_clean(selected_paths: Vec<String>) -> Result<cleaner::CleanR
}
#[tauri::command]
async fn start_full_disk_scan(state: State<'_, cleaner::DiskState>) -> 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(())
}