Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复扫描状态不正常的问题 #36

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub fn scan_appdata(tx: Sender<(String, u64)>, folder_type: &str) {
}
}
}
// 发送一个特殊标志,表示扫描完成
tx.send(("__SCAN_COMPLETE__".to_string(), 0)).unwrap();
});
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl Default for AppDataCleaner {
move_module: Default::default(),
folder_descriptions: None,
yaml_error_logged: false, // 初始时假定未记录过错误
status: None, // 初始化为 None
//status: None, // 初始化为 None
status: Some("未扫描".to_string()), // 初始化为 "未扫描"
}
}
}
Expand Down Expand Up @@ -114,6 +115,7 @@ impl eframe::App for AppDataCleaner {
self.selected_appdata_folder = folder.to_string();
self.folder_data.clear();
self.is_scanning = false;
self.status = Some("未扫描".to_string()); // 更新状态为 "未扫描"
ui.close_menu();
}
}
Expand All @@ -125,6 +127,7 @@ impl eframe::App for AppDataCleaner {
if ui.button("立即扫描").clicked() && !self.is_scanning {
self.is_scanning = true;
self.folder_data.clear();
self.status = Some("扫描中...".to_string()); // 更新状态为 "扫描中..."

let tx = self.tx.clone().unwrap();
let folder_type = self.selected_appdata_folder.clone();
Expand All @@ -134,14 +137,19 @@ impl eframe::App for AppDataCleaner {

if let Some(rx) = &self.rx {
while let Ok((folder, size)) = rx.try_recv() {
self.folder_data.push((folder, size));
// 检查是否接收到扫描完成标志
if folder == "__SCAN_COMPLETE__" {
self.is_scanning = false;
self.status = Some("扫描完成".to_string()); // 更新状态为 "扫描完成"
} else {
self.folder_data.push((folder, size));
}
}
}

if self.is_scanning {
ui.label("扫描中...");
} else {
ui.label("扫描完成");
// 显示状态
if let Some(status) = &self.status {
ui.label(status);
}

ScrollArea::vertical().show(ui, |ui| {
Expand Down Expand Up @@ -220,6 +228,5 @@ impl eframe::App for AppDataCleaner {

// 显示移动窗口
self.move_module.show_move_window(ctx);

}
}
}