Compare commits
10 Commits
8efbb3ebc4
...
v0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
278a574b4f | ||
|
|
351b0b7fa0 | ||
|
|
e7ac620302 | ||
|
|
92adfd7a2e | ||
|
|
0c77149c9e | ||
|
|
91936aab19 | ||
|
|
5cd6210dd2 | ||
|
|
6a61e36c21 | ||
|
|
33a1dfa27b | ||
|
|
39e2f41aab |
121
src-tauri/Cargo.lock
generated
121
src-tauri/Cargo.lock
generated
@@ -2112,6 +2112,15 @@ version = "0.1.14"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ntapi"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-conv"
|
name = "num-conv"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -3491,6 +3500,20 @@ dependencies = [
|
|||||||
"syn 2.0.117",
|
"syn 2.0.117",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sysinfo"
|
||||||
|
version = "0.33.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fc858248ea01b66f19d8e8a6d55f41deaf91e9d495246fd01368d99935c6c01"
|
||||||
|
dependencies = [
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
"memchr",
|
||||||
|
"ntapi",
|
||||||
|
"rayon",
|
||||||
|
"windows 0.57.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "system-deps"
|
name = "system-deps"
|
||||||
version = "6.2.2"
|
version = "6.2.2"
|
||||||
@@ -3538,7 +3561,7 @@ dependencies = [
|
|||||||
"tao-macros",
|
"tao-macros",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"url",
|
"url",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-version",
|
"windows-version",
|
||||||
"x11-dl",
|
"x11-dl",
|
||||||
@@ -3609,7 +3632,7 @@ dependencies = [
|
|||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"window-vibrancy",
|
"window-vibrancy",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3710,7 +3733,7 @@ dependencies = [
|
|||||||
"tauri-plugin",
|
"tauri-plugin",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"url",
|
"url",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"zbus",
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3736,7 +3759,7 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3762,7 +3785,7 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"wry",
|
"wry",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3929,11 +3952,25 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
|
"parking_lot",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
"socket2",
|
"socket2",
|
||||||
|
"tokio-macros",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-macros"
|
||||||
|
version = "2.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.18"
|
version = "0.7.18"
|
||||||
@@ -4527,10 +4564,10 @@ checksum = "7130243a7a5b33c54a444e54842e6a9e133de08b5ad7b5861cd8ed9a6a5bc96a"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"webview2-com-macros",
|
"webview2-com-macros",
|
||||||
"webview2-com-sys",
|
"webview2-com-sys",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-implement",
|
"windows-implement 0.60.2",
|
||||||
"windows-interface",
|
"windows-interface 0.59.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4551,7 +4588,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "381336cfffd772377d291702245447a5251a2ffa5bad679c99e61bc48bacbf9c"
|
checksum = "381336cfffd772377d291702245447a5251a2ffa5bad679c99e61bc48bacbf9c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4563,10 +4600,13 @@ dependencies = [
|
|||||||
"jwalk",
|
"jwalk",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"sysinfo",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-plugin-opener",
|
"tauri-plugin-opener",
|
||||||
|
"tokio",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4615,6 +4655,16 @@ dependencies = [
|
|||||||
"windows-version",
|
"windows-version",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.57.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core 0.57.0",
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows"
|
name = "windows"
|
||||||
version = "0.61.3"
|
version = "0.61.3"
|
||||||
@@ -4637,14 +4687,26 @@ dependencies = [
|
|||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.57.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
|
||||||
|
dependencies = [
|
||||||
|
"windows-implement 0.57.0",
|
||||||
|
"windows-interface 0.57.0",
|
||||||
|
"windows-result 0.1.2",
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.61.2"
|
version = "0.61.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-implement",
|
"windows-implement 0.60.2",
|
||||||
"windows-interface",
|
"windows-interface 0.59.3",
|
||||||
"windows-link 0.1.3",
|
"windows-link 0.1.3",
|
||||||
"windows-result 0.3.4",
|
"windows-result 0.3.4",
|
||||||
"windows-strings 0.4.2",
|
"windows-strings 0.4.2",
|
||||||
@@ -4656,8 +4718,8 @@ version = "0.62.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-implement",
|
"windows-implement 0.60.2",
|
||||||
"windows-interface",
|
"windows-interface 0.59.3",
|
||||||
"windows-link 0.2.1",
|
"windows-link 0.2.1",
|
||||||
"windows-result 0.4.1",
|
"windows-result 0.4.1",
|
||||||
"windows-strings 0.5.1",
|
"windows-strings 0.5.1",
|
||||||
@@ -4674,6 +4736,17 @@ dependencies = [
|
|||||||
"windows-threading",
|
"windows-threading",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-implement"
|
||||||
|
version = "0.57.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-implement"
|
name = "windows-implement"
|
||||||
version = "0.60.2"
|
version = "0.60.2"
|
||||||
@@ -4685,6 +4758,17 @@ dependencies = [
|
|||||||
"syn 2.0.117",
|
"syn 2.0.117",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-interface"
|
||||||
|
version = "0.57.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-interface"
|
name = "windows-interface"
|
||||||
version = "0.59.3"
|
version = "0.59.3"
|
||||||
@@ -4718,6 +4802,15 @@ dependencies = [
|
|||||||
"windows-link 0.1.3",
|
"windows-link 0.1.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-result"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-result"
|
name = "windows-result"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
@@ -5155,7 +5248,7 @@ dependencies = [
|
|||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webkit2gtk-sys",
|
"webkit2gtk-sys",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-version",
|
"windows-version",
|
||||||
"x11-dl",
|
"x11-dl",
|
||||||
|
|||||||
@@ -25,4 +25,14 @@ serde_json = "1"
|
|||||||
chrono = "0.4.44"
|
chrono = "0.4.44"
|
||||||
walkdir = "2.5.0"
|
walkdir = "2.5.0"
|
||||||
jwalk = "0.8.1"
|
jwalk = "0.8.1"
|
||||||
|
sysinfo = "0.33.1"
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
windows-sys = { version = "0.59", features = [
|
||||||
|
"Win32_System_Memory",
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_System_ProcessStatus",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_Security",
|
||||||
|
"Win32_System_SystemInformation"
|
||||||
|
] }
|
||||||
|
|
||||||
|
|||||||
@@ -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 jwalk::WalkDir;
|
||||||
|
use tauri::Emitter;
|
||||||
|
|
||||||
let mut dir_sizes = HashMap::new();
|
let mut dir_sizes = HashMap::new();
|
||||||
let root = Path::new(&root_path);
|
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()) {
|
for entry in WalkDir::new(root).skip_hidden(false).into_iter().filter_map(|e| e.ok()) {
|
||||||
if entry.file_type.is_file() {
|
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 size = entry.metadata().map(|m| m.len()).unwrap_or(0);
|
||||||
let mut current_path = entry.parent_path().to_path_buf();
|
let mut current_path = entry.parent_path().to_path_buf();
|
||||||
while current_path.starts_with(root) {
|
while current_path.starts_with(root) {
|
||||||
@@ -346,3 +365,204 @@ fn clean_directory_contents(path: &Path, filter_days: Option<u64>) -> (u64, u32,
|
|||||||
}
|
}
|
||||||
(freed, success, fail)
|
(freed, success, fail)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 浏览器清理逻辑 ---
|
||||||
|
|
||||||
|
const BROWSER_CACHE_DIRS: &[&str] = &[
|
||||||
|
"Cache",
|
||||||
|
"Code Cache",
|
||||||
|
"GPUCache",
|
||||||
|
"Media Cache",
|
||||||
|
"Service Worker/CacheStorage",
|
||||||
|
"Service Worker/ScriptCache",
|
||||||
|
"GrShaderCache",
|
||||||
|
"DawnCache",
|
||||||
|
"File System",
|
||||||
|
"blob_storage"
|
||||||
|
];
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone)]
|
||||||
|
pub struct BrowserProfile {
|
||||||
|
pub name: String,
|
||||||
|
pub path_name: String,
|
||||||
|
pub cache_size: u64,
|
||||||
|
pub cache_size_str: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct BrowserScanResult {
|
||||||
|
pub profiles: Vec<BrowserProfile>,
|
||||||
|
pub total_size: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum BrowserType {
|
||||||
|
Chrome,
|
||||||
|
Edge,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BrowserType {
|
||||||
|
fn get_user_data_path(&self) -> Result<std::path::PathBuf, String> {
|
||||||
|
let local_app_data = std::env::var("LOCALAPPDATA").map_err(|_| "无法获取 LocalAppData 路径")?;
|
||||||
|
let base = std::path::Path::new(&local_app_data);
|
||||||
|
match self {
|
||||||
|
BrowserType::Chrome => Ok(base.join("Google\\Chrome\\User Data")),
|
||||||
|
BrowserType::Edge => Ok(base.join("Microsoft\\Edge\\User Data")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_browser_scan(browser: BrowserType) -> Result<BrowserScanResult, String> {
|
||||||
|
let user_data_path = browser.get_user_data_path()?;
|
||||||
|
let local_state_path = user_data_path.join("Local State");
|
||||||
|
|
||||||
|
let mut profiles = Vec::new();
|
||||||
|
let mut total_bytes = 0;
|
||||||
|
|
||||||
|
if local_state_path.exists() {
|
||||||
|
let content = fs::read_to_string(local_state_path).map_err(|e| e.to_string())?;
|
||||||
|
let v: serde_json::Value = serde_json::from_str(&content).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
if let Some(info_cache) = v.get("profile").and_then(|p| p.get("info_cache")).and_then(|i| i.as_object()) {
|
||||||
|
for (dir_name, info) in info_cache {
|
||||||
|
let profile_display_name = info.get("name").and_then(|n| n.as_str()).unwrap_or(dir_name);
|
||||||
|
let profile_path = user_data_path.join(dir_name);
|
||||||
|
|
||||||
|
if profile_path.exists() {
|
||||||
|
let mut size = 0;
|
||||||
|
// 扫描配置的缓存目录
|
||||||
|
for sub in BROWSER_CACHE_DIRS {
|
||||||
|
let target = profile_path.join(sub);
|
||||||
|
if target.exists() {
|
||||||
|
size += get_dir_size_simple(&target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total_bytes += size;
|
||||||
|
profiles.push(BrowserProfile {
|
||||||
|
name: profile_display_name.to_string(),
|
||||||
|
path_name: dir_name.clone(),
|
||||||
|
cache_size: size,
|
||||||
|
cache_size_str: format_size(size),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(BrowserScanResult {
|
||||||
|
profiles,
|
||||||
|
total_size: format_size(total_bytes),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_dir_size_simple(path: &std::path::Path) -> u64 {
|
||||||
|
walkdir::WalkDir::new(path)
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|e| e.ok())
|
||||||
|
.filter(|e| e.file_type().is_file())
|
||||||
|
.map(|e| e.metadata().map(|m| m.len()).unwrap_or(0))
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_browser_clean(browser: BrowserType, profile_paths: Vec<String>) -> Result<CleanResult, String> {
|
||||||
|
let user_data_path = browser.get_user_data_path()?;
|
||||||
|
let mut total_freed = 0;
|
||||||
|
let mut success_count = 0;
|
||||||
|
let mut fail_count = 0;
|
||||||
|
|
||||||
|
for profile_dir in profile_paths {
|
||||||
|
let profile_path = user_data_path.join(&profile_dir);
|
||||||
|
if profile_path.exists() {
|
||||||
|
// 清理配置的缓存目录
|
||||||
|
for sub in BROWSER_CACHE_DIRS {
|
||||||
|
let target = profile_path.join(sub);
|
||||||
|
if target.exists() {
|
||||||
|
let (f, s, fl) = clean_directory_contents(&target, None);
|
||||||
|
total_freed += f;
|
||||||
|
success_count += s;
|
||||||
|
fail_count += fl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(CleanResult {
|
||||||
|
total_freed: format_size(total_freed),
|
||||||
|
success_count,
|
||||||
|
fail_count,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 内存清理逻辑 ---
|
||||||
|
|
||||||
|
use sysinfo::{System, ProcessesToUpdate};
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone)]
|
||||||
|
pub struct MemoryStats {
|
||||||
|
pub total: u64,
|
||||||
|
pub used: u64,
|
||||||
|
pub free: u64,
|
||||||
|
pub percent: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 获取当前系统内存状态
|
||||||
|
pub fn get_memory_stats() -> MemoryStats {
|
||||||
|
let mut sys = System::new_all();
|
||||||
|
sys.refresh_memory();
|
||||||
|
|
||||||
|
let total = sys.total_memory();
|
||||||
|
let used = sys.used_memory();
|
||||||
|
let free = total.saturating_sub(used);
|
||||||
|
let percent = (used as f32 / total as f32) * 100.0;
|
||||||
|
|
||||||
|
MemoryStats { total, used, free, percent }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 执行内存压缩 (Empty Working Set)
|
||||||
|
pub async fn run_memory_clean() -> Result<u64, String> {
|
||||||
|
use windows_sys::Win32::System::ProcessStatus::EmptyWorkingSet;
|
||||||
|
use windows_sys::Win32::System::Threading::{OpenProcess, PROCESS_QUERY_INFORMATION, PROCESS_SET_QUOTA};
|
||||||
|
use windows_sys::Win32::Foundation::CloseHandle;
|
||||||
|
|
||||||
|
let before = get_memory_stats().used;
|
||||||
|
|
||||||
|
let mut sys = System::new_all();
|
||||||
|
sys.refresh_processes(ProcessesToUpdate::All, true);
|
||||||
|
|
||||||
|
for (pid, _) in sys.processes() {
|
||||||
|
let pid_u32 = pid.as_u32();
|
||||||
|
unsafe {
|
||||||
|
let handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_QUOTA, 0, pid_u32);
|
||||||
|
if handle != std::ptr::null_mut() {
|
||||||
|
EmptyWorkingSet(handle);
|
||||||
|
CloseHandle(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 给系统一点点时间反应
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||||
|
|
||||||
|
let after = get_memory_stats().used;
|
||||||
|
let freed = before.saturating_sub(after);
|
||||||
|
Ok(freed)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 深度内存清理 (Standby List / System Cache)
|
||||||
|
pub async fn run_deep_memory_clean() -> Result<u64, String> {
|
||||||
|
use windows_sys::Win32::System::Memory::SetSystemFileCacheSize;
|
||||||
|
|
||||||
|
let before = get_memory_stats().used;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
// -1 (usize::MAX) 表示清空系统文件缓存
|
||||||
|
SetSystemFileCacheSize(usize::MAX, usize::MAX, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 配合普通清理一起执行
|
||||||
|
let _ = run_memory_clean().await;
|
||||||
|
|
||||||
|
let after = get_memory_stats().used;
|
||||||
|
let freed = before.saturating_sub(after);
|
||||||
|
Ok(freed)
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ async fn start_fast_clean(selected_paths: Vec<String>) -> Result<cleaner::CleanR
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn start_full_disk_scan(state: State<'_, cleaner::DiskState>) -> Result<(), String> {
|
async fn start_full_disk_scan(state: State<'_, cleaner::DiskState>, app_handle: tauri::AppHandle) -> Result<(), String> {
|
||||||
cleaner::run_full_scan("C:\\".to_string(), &state).await;
|
cleaner::run_full_scan("C:\\".to_string(), &state, app_handle).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +46,37 @@ async fn disable_hibernation() -> Result<String, String> {
|
|||||||
cleaner::disable_hibernation().await
|
cleaner::disable_hibernation().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 浏览器清理命令 ---
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn start_browser_scan(browser: String) -> Result<cleaner::BrowserScanResult, String> {
|
||||||
|
let b_type = if browser == "chrome" { cleaner::BrowserType::Chrome } else { cleaner::BrowserType::Edge };
|
||||||
|
cleaner::run_browser_scan(b_type).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn start_browser_clean(browser: String, profiles: Vec<String>) -> Result<cleaner::CleanResult, String> {
|
||||||
|
let b_type = if browser == "chrome" { cleaner::BrowserType::Chrome } else { cleaner::BrowserType::Edge };
|
||||||
|
cleaner::run_browser_clean(b_type, profiles).await
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 内存清理命令 ---
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn get_memory_stats() -> cleaner::MemoryStats {
|
||||||
|
cleaner::get_memory_stats()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn run_memory_clean() -> Result<u64, String> {
|
||||||
|
cleaner::run_memory_clean().await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn run_deep_memory_clean() -> Result<u64, String> {
|
||||||
|
cleaner::run_deep_memory_clean().await
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
@@ -62,7 +93,12 @@ pub fn run() {
|
|||||||
open_in_explorer,
|
open_in_explorer,
|
||||||
clean_system_components,
|
clean_system_components,
|
||||||
clean_thumbnails,
|
clean_thumbnails,
|
||||||
disable_hibernation
|
disable_hibernation,
|
||||||
|
start_browser_scan,
|
||||||
|
start_browser_clean,
|
||||||
|
get_memory_stats,
|
||||||
|
run_memory_clean,
|
||||||
|
run_deep_memory_clean
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
827
src/App.vue
827
src/App.vue
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user