From cdc60fbe6dfee02e73982e1191558c1018c84ed5 Mon Sep 17 00:00:00 2001 From: lijunjie Date: Tue, 24 Nov 2026 11:43:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=B8=E8=BD=BD=E5=A2=9E=E5=BC=BA=EF=BC=9A?= =?UTF-8?q?=E6=9D=A5=E6=BA=90=E5=BE=BD=E7=AB=A0=E3=80=81=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E4=B8=8D=E5=AE=8C=E6=95=B4=E6=A3=80=E6=B5=8B=E4=B8=8E=E6=AE=8B?= =?UTF-8?q?=E7=95=99=E8=AE=B0=E5=BD=95=E6=B8=85=E7=90=86=EF=BC=88G2=20?= =?UTF-8?q?=E5=AE=8C=E6=88=90=20C=20=E6=89=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AppInfo 新增 uninstall_string/reg_key/dead 字段(serde default,全平台默认值) - Windows 卸载扫描:MsiQueryProductStateW 探测 MSI 产品状态,安装目录与卸载器双缺失 → 「安装不完整」 - 包管理器来源徽章:winget/scoop/Chocolatey/JetBrains Toolbox/Microsoft Store 按路径指纹识别 - 死应用卸载方案:幽灵 bundle 行改为锁定说明,新增 app_remove_record 命令删除孤儿注册表记录(HKLM 走一次 UAC 提权 reg.exe,HKCU 进程内直删) - 应用页 UI:安装不完整红色徽章 + 包管理器来源徽章 + 清理残留引导卡 - AI 模型体积诚实化:manifest 行只带自身字节,cluster 总额写入 note,杜绝 清理点 求和双计 - 修正 squid-engine Cargo.toml 误置的 libc 依赖段 - demo 点击测试扩至 53 项全过(隐私锁定/永久删除、优化开关与恢复默认、进阶启动项签名徽章与开关、卸载徽章与残留清理) --- Cargo.lock | 2 + crates/squid-core/src/model.rs | 15 ++- crates/squid-engine/Cargo.toml | 3 + crates/squid-engine/src/ai.rs | 48 ++++++--- crates/squid-engine/src/uninstall.rs | 10 +- crates/squid-platform/src/advanced.rs | 2 +- crates/squid-platform/src/apps.rs | 1 + crates/squid-platform/src/linux.rs | 2 + crates/squid-platform/src/windows.rs | 148 ++++++++++++++++++++++++-- crates/squid-tui/src/app.rs | 2 + crates/squid-tui/src/views.rs | 1 + src-tauri/Cargo.lock | 2 + src-tauri/src/app.rs | 20 ++++ src-tauri/src/lib.rs | 1 + src-tauri/src/manage.rs | 7 +- src/lib/api.ts | 1 + src/pages/ApplicationsPage.tsx | 82 +++++++++++++- src/styles.css | 38 +++++++ src/types.ts | 6 ++ 19 files changed, 359 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d9aee6..f233a74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1172,6 +1172,7 @@ dependencies = [ "squid-rules", "squid-stats", "walkdir", + "winreg", ] [[package]] @@ -1184,6 +1185,7 @@ dependencies = [ "png", "rayon", "serde", + "serde_json", "squid-core", "sysinfo", "unicode-width 0.2.0", diff --git a/crates/squid-core/src/model.rs b/crates/squid-core/src/model.rs index 1089374..13bacf3 100644 --- a/crates/squid-core/src/model.rs +++ b/crates/squid-core/src/model.rs @@ -415,10 +415,23 @@ pub struct AppInfo { pub has_sibling_install: bool, pub publisher: Option, pub installed_ms: Option, - /// Raw `DisplayIcon` registry value (Windows): a path, optionally with an + /// Raw `DisplayIcon` registry value (Windows): a path, optionally with a /// `,index` suffix — the icon Explorer shows for this app. #[serde(default)] pub display_icon: Option, + /// The uninstaller command recorded by the app itself, when present. + #[serde(default)] + pub uninstall_string: Option, + /// Windows: the exact registry key holding this entry + /// (`HKCU|HKLM` + subkey), so an orphaned record can be removed after + /// its files are gone. + #[serde(default)] + pub reg_key: Option, + /// Install is broken: neither the install folder nor the uninstaller + /// target exists any more (or MSI reports the product absent while the + /// registry record remains). 「安装不完整」 — offer leftover cleanup. + #[serde(default)] + pub dead: bool, } impl AppInfo { diff --git a/crates/squid-engine/Cargo.toml b/crates/squid-engine/Cargo.toml index a1cbed9..2f762fc 100644 --- a/crates/squid-engine/Cargo.toml +++ b/crates/squid-engine/Cargo.toml @@ -23,3 +23,6 @@ sha2.workspace = true filetime.workspace = true dirs.workspace = true libc.workspace = true + +[target.'cfg(windows)'.dependencies] +winreg = "0.52" diff --git a/crates/squid-engine/src/ai.rs b/crates/squid-engine/src/ai.rs index e170830..598ab5b 100644 --- a/crates/squid-engine/src/ai.rs +++ b/crates/squid-engine/src/ai.rs @@ -210,14 +210,17 @@ fn ollama_models(home: &Path) -> Vec { shared_note = format!(";另有 {shared_skipped} 个共享层被其它模型使用,不计算在内"); } let label = format!("Ollama · {name}"); - // Manifest File item carries the cluster's label and total; blob - // items are plain File rows (they only exist while the cluster is - // ticked as a whole; individually the user may also untick one). - let mut item = model_item(manifest, label.clone(), size, newest, &rule); + // The manifest is the anchor row and carries the cluster label. Every + // row — manifest and blobs alike — carries **its own** size: the 清理点 + // row sums its members, so charging the total to the manifest on top + // of the blobs would double-count the model. + let manifest_bytes = std::fs::metadata(&manifest).map(|m| m.len()).unwrap_or(0); + let mut item = model_item(manifest, label.clone(), manifest_bytes, newest, &rule); item.kind = ItemKind::File; // the manifest file itself item.note = Some(format!( - "{};删除后 `ollama pull` 可原样恢复{shared_note}", - age.clone().unwrap_or_else(|| "从未记录使用时间".into()) + "{};整个模型可释放 {},删除后 `ollama pull` 可原样恢复{shared_note}", + age.clone().unwrap_or_else(|| "从未记录使用时间".into()), + Bytes(size + manifest_bytes) )); rows.push(item); for (blob, bytes, ms) in blob_items { @@ -383,16 +386,18 @@ mod tests { assert_eq!(rows.len(), 2, "{rows:?}"); assert!(rows.iter().all(|r| r.rule_id == "ai-ollama-qwen3-8b")); assert_eq!(rows[0].label, "Ollama · qwen3/8b"); - assert_eq!( - rows.iter().map(|r| r.size.as_u64()).sum::(), - 2048, - "manifest row carries the cluster total, blob its own size" - ); + // Each row carries its own size; the cluster total rides in the note. + let total = rows.iter().map(|r| r.size.as_u64()).sum::(); + assert!(total >= 2048, "manifest + exclusive blob, no double count"); + assert!(rows[0] + .note + .as_deref() + .is_some_and(|n| n.contains("可释放"))); assert!(rows.iter().all(|r| !r.selected), "models never pre-checked"); assert!(rows[0] .note .as_deref() - .is_some_and(|n| n.contains("重新下载"))); + .is_some_and(|n| n.contains("可原样恢复"))); let _ = std::fs::remove_dir_all(&root); } @@ -432,15 +437,26 @@ mod tests { .iter() .filter(|r| r.rule_id == "ai-ollama-b-latest") .collect(); - // A: manifest + own blob, sized 100 (the shared 5 GB belongs to nobody yet). + // A: manifest (its own JSON bytes) + own blob sized 100; the shared + // 5 GB belongs to nobody yet, so it is billed to neither row. assert_eq!(model_a.len(), 2, "{model_a:?}"); - assert_eq!(model_a[0].size.as_u64(), 100); + assert_eq!(model_a[1].size.as_u64(), 100); + assert!( + model_a[0].size.as_u64() < 200, + "manifest carries its own bytes" + ); assert!(model_a[0] .note .as_deref() .is_some_and(|n| n.contains("共享层"))); - // B: only the manifest survives, sized 0 → skipped entirely. - assert!(model_b.iter().all(|r| r.size.as_u64() == 0) || model_b.is_empty()); + // B: only the manifest survives (its own JSON bytes, not the shared + // 5 GB), and its note says the layers are held by other models. + assert_eq!(model_b.len(), 1, "{model_b:?}"); + assert!(model_b[0].size.as_u64() < 200, "manifest bytes only"); + assert!(model_b[0] + .note + .as_deref() + .is_some_and(|n| n.contains("共享层"))); let _ = std::fs::remove_dir_all(&root); } diff --git a/crates/squid-engine/src/uninstall.rs b/crates/squid-engine/src/uninstall.rs index 2f629c4..06f8bb0 100644 --- a/crates/squid-engine/src/uninstall.rs +++ b/crates/squid-engine/src/uninstall.rs @@ -136,7 +136,14 @@ pub fn build_plan( Some(version) => format!("{} · {}", app.source, version), None => app.source.clone(), }); - if system { + if app.dead || app.path.as_os_str().is_empty() { + // 安装不完整: there is no bundle to move to the bin — the plan + // carries only the leftovers and the registry record the page + // offers to drop. + bundle_item = bundle_item + .locked(LockReason::Protected) + .with_note("程序本体已不存在,仅需清理注册表记录与残留"); + } else if system { bundle_item = bundle_item .locked(LockReason::Protected) .with_note("system application"); @@ -472,6 +479,7 @@ mod tests { publisher: None, installed_ms: None, display_icon: None, + ..AppInfo::default() } } diff --git a/crates/squid-platform/src/advanced.rs b/crates/squid-platform/src/advanced.rs index aa25256..7d651c9 100644 --- a/crates/squid-platform/src/advanced.rs +++ b/crates/squid-platform/src/advanced.rs @@ -517,7 +517,7 @@ mod tests { #[test] fn exe_extraction_handles_quotes_and_arguments() { assert_eq!( - windows::exe_of(r#""C:\Program Files\Tool\warp.exe" --quiet""#.as_ref()).as_deref(), + windows::exe_of(r#""C:\Program Files\Tool\warp.exe" --quiet""#).as_deref(), Some(r"C:\Program Files\Tool\warp.exe") ); assert_eq!( diff --git a/crates/squid-platform/src/apps.rs b/crates/squid-platform/src/apps.rs index b044953..9d0a4a6 100644 --- a/crates/squid-platform/src/apps.rs +++ b/crates/squid-platform/src/apps.rs @@ -135,6 +135,7 @@ pub fn app_from_bundle( .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()) .map(|d| d.as_millis() as u64), display_icon: None, + ..AppInfo::default() }; if app.name.to_lowercase() == "safari" { // Safari cannot be removed and its caches are managed by the OS. diff --git a/crates/squid-platform/src/linux.rs b/crates/squid-platform/src/linux.rs index 551b18f..45bfeaa 100644 --- a/crates/squid-platform/src/linux.rs +++ b/crates/squid-platform/src/linux.rs @@ -201,6 +201,7 @@ impl Platform for Linux { publisher: desktop.icon.clone(), installed_ms: None, display_icon: None, + ..AppInfo::default() }); } } @@ -236,6 +237,7 @@ impl Platform for Linux { publisher: None, installed_ms: None, display_icon: None, + ..AppInfo::default() }); } } diff --git a/crates/squid-platform/src/windows.rs b/crates/squid-platform/src/windows.rs index 4c5dd93..112ab81 100644 --- a/crates/squid-platform/src/windows.rs +++ b/crates/squid-platform/src/windows.rs @@ -12,7 +12,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use sysinfo::{Disks, System}; use winreg::enums::{ - HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_32KEY, KEY_WOW64_64KEY, + HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_32KEY, KEY_WOW64_64KEY, KEY_WRITE, }; use winreg::RegKey; @@ -23,27 +23,135 @@ const UNINSTALL_SUBKEY: &str = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Unins const NT_VERSION_KEY: &str = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion"; const BIOS_KEY: &str = r"HARDWARE\DESCRIPTION\System\BIOS"; -fn open_uninstall_hives() -> Vec<(RegKey, &'static str)> { +fn open_uninstall_hives() -> Vec<(RegKey, &'static str, &'static str)> { let mut hives = Vec::new(); let views = [ - (KEY_WOW64_64KEY, "Registry (HKLM 64-bit)"), - (KEY_WOW64_32KEY, "Registry (HKLM 32-bit)"), + (KEY_WOW64_64KEY, "Registry (HKLM 64-bit)", "HKLM64"), + (KEY_WOW64_32KEY, "Registry (HKLM 32-bit)", "HKLM32"), ]; - for (flag, label) in views { + for (flag, label, tag) in views { if let Ok(key) = RegKey::predef(HKEY_LOCAL_MACHINE) .open_subkey_with_flags(UNINSTALL_SUBKEY, KEY_READ | flag) { - hives.push((key, label)); + hives.push((key, label, tag)); } } if let Ok(key) = RegKey::predef(HKEY_CURRENT_USER).open_subkey_with_flags(UNINSTALL_SUBKEY, KEY_READ) { - hives.push((key, "Registry (HKCU)")); + hives.push((key, "Registry (HKCU)", "HKCU")); } hives } +/// MSI install-state probe (the honest "安装不完整" detector). A registry +/// record whose product state is Unknown/Broken/Removed means the MSI +/// package itself is gone — the record is an orphan no msiexec can honour. +mod msi { + #[link(name = "msi")] + extern "system" { + fn MsiQueryProductStateW(product: *const u16) -> i32; + } + + // INSTALLSTATE: 0 Unknown, 1 Broken, 2 Advertised, 3 Removed, + // 4 Installed, 5 Local, 6 Source, 7 Default. + fn wide(text: &str) -> Vec { + text.encode_utf16().chain(std::iter::once(0)).collect() + } + + /// True when the MSI product for `guid` is missing or unusable. + pub fn product_broken(guid: &str) -> bool { + let normalized = guid.to_ascii_uppercase(); + let state = unsafe { MsiQueryProductStateW(wide(&normalized).as_ptr()) }; + matches!(state, 0 | 1 | 3) + } +} + +/// The product GUID inside an `MsiExec.exe /X{GUID}` style command. +fn msi_guid(uninstall_string: &str) -> Option<&str> { + let upper = uninstall_string.to_ascii_uppercase(); + if !upper.contains("MSIEXEC") { + return None; + } + let start = uninstall_string.find('{')?; + let end = uninstall_string[start..].find('}')? + start + 1; + Some(&uninstall_string[start..end]) +} + +/// Which manager owns this install, by path fingerprint (MangoDisk's source +/// merge, cheapened to what the registry already tells us). The badge is +/// honest provenance, not a guess: only well-known layouts qualify. +fn package_source(path: &Path, fallback: &str) -> String { + let lower = path.to_string_lossy().to_lowercase(); + if lower.contains("\\windowsapps\\") { + return "Microsoft Store".into(); + } + if lower.contains("\\scoop\\apps\\") { + return "scoop".into(); + } + if lower.contains("\\chocolatey\\") { + return "Chocolatey".into(); + } + if lower.contains("\\winget\\") || lower.contains("\\packages\\desktopappinstaller") { + return "winget".into(); + } + if lower.contains("\\jetbrains\\toolbox\\apps\\") { + return "Toolbox".into(); + } + fallback.into() +} + +/// Remove the 安装不完整 registry record of a dead app (the orphan no +/// msiexec can honour). `reg_key` is the scanner's "HKLM64|" tag. +/// HKLM needs admin, so an in-process denial escalates through one UAC +/// prompt via `reg.exe` — the record either goes or the user declines. +pub fn remove_uninstall_record(reg_key: &str) -> std::result::Result<(), String> { + let (tag, name) = reg_key.split_once('|').ok_or("注册表记录标识无效")?; + let hive_path = match tag { + "HKLM64" | "HKLM32" | "HKCU" => UNINSTALL_SUBKEY, + _ => return Err("注册表记录标识无效".into()), + }; + if tag != "HKCU" { + use std::os::windows::process::CommandExt; + // reg.exe spells the 32-bit view through WOW6432Node. + let elevated_path = format!( + "HKLM\\{}\\{}", + if tag == "HKLM32" { + r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" + } else { + hive_path + }, + name + ); + let status = Command::new("reg.exe") + .args(["delete", &elevated_path, "/f"]) + .creation_flags(0x0800_0000) // no console flash + .status(); + if matches!(&status, Ok(s) if s.success()) { + return Ok(()); + } + // Direct write denied (ACL or lack of admin): escalate once. + let script = format!( + "$ErrorActionPreference='Stop'; Start-Process -FilePath 'reg.exe' -ArgumentList 'delete','{}','/f' -Verb RunAs -WindowStyle Hidden -Wait", + elevated_path.replace('\'', "''") + ); + let escalated = Command::new("powershell.exe") + .args(["-NoProfile", "-NonInteractive", "-Command", &script]) + .creation_flags(0x0800_0000) + .status() + .map_err(|error| format!("无法启动提权助手:{error}"))?; + if !escalated.success() { + return Err("管理员授权被取消,注册表记录未删除".into()); + } + return Ok(()); + } + let hive = RegKey::predef(HKEY_CURRENT_USER) + .open_subkey_with_flags(hive_path, KEY_READ | KEY_WRITE) + .map_err(|error| format!("无法打开卸载注册表:{error}"))?; + hive.delete_subkey_all(name) + .map_err(|error| format!("删除注册表记录失败:{error}")) +} + fn str_value(key: &RegKey, name: &str) -> Option { key.get_value::(name) .ok() @@ -213,7 +321,7 @@ impl Platform for Windows { .map(|p| p.to_lowercase()) .collect(); let mut apps = Vec::new(); - for (hive, source) in open_uninstall_hives() { + for (hive, source, tag) in open_uninstall_hives() { let names = hive .enum_keys() .filter_map(|name| name.ok()) @@ -254,6 +362,21 @@ impl Platform for Windows { running.iter().any(|exe| exe.starts_with(&loc)) }) .unwrap_or(false); + // 安装不完整 detection (MangoDisk's cross-check): the record + // exists but the product cannot be found any more — the MSI + // state says gone, or neither the install folder nor the + // uninstaller binary is on disk. + let dead = match uninstall_string.as_deref().and_then(msi_guid) { + Some(guid) => msi::product_broken(guid), + None => { + let uninstaller_gone = uninstall_string + .as_deref() + .and_then(uninstall_program) + .map(|exe| !exe.exists()) + .unwrap_or(true); + install_location.is_none() && uninstaller_gone + } + }; // Size: Windows installers report EstimatedSize (KB) for // Add/Remove Programs — the same number Settings shows. // Absent that, measure the install folder when asked. @@ -267,18 +390,25 @@ impl Platform for Windows { .unwrap_or_default(), None => Bytes::ZERO, }; + let mut source = package_source(&path, source); + if dead { + source.push_str(" · 安装不完整"); + } apps.push(AppInfo { name: display_name, bundle_id: None, path, version: str_value(&key, "DisplayVersion"), size, - source: source.into(), + source, running: running_app, has_sibling_install: false, publisher: str_value(&key, "Publisher"), installed_ms: install_date_ms(str_value(&key, "InstallDate")), display_icon: str_value(&key, "DisplayIcon"), + uninstall_string, + reg_key: Some(format!("{tag}|{name}")), + dead, }); } } diff --git a/crates/squid-tui/src/app.rs b/crates/squid-tui/src/app.rs index c4a3d72..5178658 100644 --- a/crates/squid-tui/src/app.rs +++ b/crates/squid-tui/src/app.rs @@ -2612,6 +2612,7 @@ mod tests { publisher: None, installed_ms: None, display_icon: None, + ..AppInfo::default() }; let items = vec![ CleanupItem::new( @@ -2708,6 +2709,7 @@ mod tests { publisher: None, installed_ms: None, display_icon: None, + ..AppInfo::default() }]; app.uninstall.filter = "Squid".into(); assert_eq!(app.uninstall.visible().len(), 1); diff --git a/crates/squid-tui/src/views.rs b/crates/squid-tui/src/views.rs index 983b2e5..61e7409 100644 --- a/crates/squid-tui/src/views.rs +++ b/crates/squid-tui/src/views.rs @@ -2053,6 +2053,7 @@ mod tests { publisher: None, installed_ms: None, display_icon: None, + ..AppInfo::default() }, // Sorted the way `build_plan` sorts: biggest first, so the bundle // is *not* the first item here. diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c7cf648..9c6410e 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3573,6 +3573,7 @@ dependencies = [ "squid-rules", "squid-stats", "walkdir", + "winreg 0.52.0", ] [[package]] @@ -3585,6 +3586,7 @@ dependencies = [ "png 0.17.16", "rayon", "serde", + "serde_json", "squid-core", "sysinfo", "unicode-width", diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 799fc9c..7ed61f1 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -1193,6 +1193,26 @@ pub async fn app_uninstall( Ok(DeleteResultView::from_outcome(outcome)) } +/// 卸载增强: drop the 安装不完整 registry record after its files are gone. +/// HKLM removal escalates through one UAC prompt; a declined prompt is an +/// error the page surfaces, never a silent no-op. +#[tauri::command] +pub async fn app_remove_record(_app: AppHandle, reg_key: String) -> Result<(), String> { + #[cfg(windows)] + { + tauri::async_runtime::spawn_blocking(move || { + squid_platform::windows::remove_uninstall_record(®_key) + }) + .await + .map_err(|error| error.to_string())? + } + #[cfg(not(windows))] + { + let _ = reg_key; + Err("此系统没有注册表记录".to_string()) + } +} + /// What `storage_explore` answers: the tree plus how fresh it is (A⑥). /// `cached` = served from the in-memory size cache; `measuredAtMs` = age of /// the measurement so the page can say "12 分钟前" honestly. `Node` itself diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 55fcae2..4577bda 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -139,6 +139,7 @@ pub fn run() { app::apps_scan, app::app_plan, app::app_uninstall, + app::app_remove_record, app::storage_explore, app::storage_insights, app::write_text_file, diff --git a/src-tauri/src/manage.rs b/src-tauri/src/manage.rs index f3eba50..05878e2 100644 --- a/src-tauri/src/manage.rs +++ b/src-tauri/src/manage.rs @@ -406,8 +406,11 @@ pub async fn advanced_scan(app: AppHandle) -> Result { } #[tauri::command] -pub async fn advanced_set_enabled(app: AppHandle, id: String, enabled: bool) -> Result<(), String> { - let manage = app.state::(); +pub async fn advanced_set_enabled( + _app: AppHandle, + id: String, + enabled: bool, +) -> Result<(), String> { // Advanced rows carry their whole state in the id + a fresh scan match. let entry = tauri::async_runtime::spawn_blocking(squid_platform::advanced::scan_advanced) .await diff --git a/src/lib/api.ts b/src/lib/api.ts index 3573aef..bd5109c 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -97,6 +97,7 @@ export const api = { appPlan: (jobId: string, appKey: string) => invoke("app_plan", { jobId, appKey }), appUninstall: (jobId: string, planId: string, selected: number[], mode: DeleteMode) => invoke("app_uninstall", { jobId, planId, selected, mode }), + appRemoveRecord: (regKey: string) => invoke("app_remove_record", { regKey }), storageExplore: (jobId: string, path?: string | null, depth = 1, top = 16, force = false) => invoke("storage_explore", { jobId, path, depth, top, force }), storageInsights: () => invoke("storage_insights"), diff --git a/src/pages/ApplicationsPage.tsx b/src/pages/ApplicationsPage.tsx index 41e3b76..f1546e5 100644 --- a/src/pages/ApplicationsPage.tsx +++ b/src/pages/ApplicationsPage.tsx @@ -2,15 +2,18 @@ import { AppWindow, ChevronRight, FolderOpen, + Hammer, PackageX, Play, Search, + ShieldAlert, ShieldCheck, Trash2, } from "lucide-react"; import { useMemo, useState } from "react"; import { useI18n } from "../i18n"; -import { formatBytes, formatCount, shortPath } from "../lib/format"; +import { api } from "../lib/api"; +import { formatBytes, formatCount, messageFrom, shortPath } from "../lib/format"; import type { AppInfo, DeleteMode } from "../types"; import type { AppsWorkspace } from "../hooks/useAppsWorkspace"; import { @@ -27,6 +30,23 @@ import { useToast, } from "../components/ui"; +/* 卸载增强: package-manager provenance as a chip. The backend only badges + well-known layouts, so the chip states a fact, never a guess. */ +const SOURCE_BADGES: Record = { + winget: ["winget", "winget"], + scoop: ["scoop", "scoop"], + Chocolatey: ["Chocolatey", "Chocolatey"], + "Microsoft Store": ["Store", "Microsoft Store"], + Toolbox: ["Toolbox", "JetBrains Toolbox"], +}; + +function sourceBadge(source: string): [string, string] | null { + for (const [key, badge] of Object.entries(SOURCE_BADGES)) { + if (source.includes(key)) return badge; + } + return null; +} + function AppRow({ app, selected, @@ -38,6 +58,7 @@ function AppRow({ }) { const { t } = useI18n(); const letter = app.name.trim().slice(0, 1).toUpperCase() || "?"; + const badge = sourceBadge(app.source); return ( @@ -75,6 +108,7 @@ export function ApplicationsPage({ const [query, setQuery] = useState(""); const [confirming, setConfirming] = useState(false); const [mode, setMode] = useState("trash"); + const [recordBusy, setRecordBusy] = useState(false); const apps = useMemo(() => { const needle = query.trim().toLowerCase(); @@ -109,6 +143,24 @@ export function ApplicationsPage({ } }; + // 卸载增强: an 安装不完整 entry is only fully gone once its registry + // record goes too — otherwise Windows (and every scanner) still lists it. + const removeRecord = async () => { + const regKey = workspace.plan?.app.reg_key; + if (!regKey || recordBusy) return; + setRecordBusy(true); + try { + await api.appRemoveRecord(regKey); + push(t("Orphaned registry record removed", "已清除残留的注册表记录"), "success"); + workspace.chooseApp(null); + await workspace.scan(); + } catch (reason) { + push(messageFrom(reason), "danger"); + } finally { + setRecordBusy(false); + } + }; + return (
+ {workspace.plan.app.dead ? ( +
+ +
+ {t("Incomplete install", "安装不完整")} +

+ {t( + "The program files are already gone; only its registry record and leftovers remain. Removing the record makes Windows stop listing it.", + "程序本体已经不存在,只剩下注册表记录和残留文件。清除记录后,系统将不再列出这个应用。", + )} +

+ +
+
+ ) : null} + {workspace.plan.warnings.length > 0 ? (
{workspace.plan.warnings.map((warning) => ( diff --git a/src/styles.css b/src/styles.css index 81a5dd5..7f078eb 100644 --- a/src/styles.css +++ b/src/styles.css @@ -990,6 +990,44 @@ select:focus-visible, background: var(--nex-primary-tint); } +/* 卸载增强: 安装不完整 rows and package-manager provenance chips. */ +.status-chip.is-danger { + color: #b3372c; + background: #fdeae7; +} + +.status-chip.is-source { + color: #4c5f94; + background: #e9edf8; +} + +.plan-dead-callout { + display: flex; + gap: 10px; + padding: 12px 14px; + border: 1px solid #f3cfc9; + border-radius: 14px; + background: #fdf1ef; + color: #8c2f26; +} + +.plan-dead-callout > svg { + flex: none; + margin-top: 2px; +} + +.plan-dead-callout strong { + display: block; + font-size: var(--nex-text-sm); +} + +.plan-dead-callout p { + margin: 4px 0 8px; + color: #a05a53; + font-size: var(--nex-text-xs); + line-height: 1.5; +} + /* Header gauge and cards */ .overview-hero { diff --git a/src/types.ts b/src/types.ts index efbc299..7835a81 100644 --- a/src/types.ts +++ b/src/types.ts @@ -165,6 +165,12 @@ export interface AppInfo { publisher: string | null; installed_ms: number | null; display_icon: string | null; + /** Recorded uninstaller command (Windows), when the app left one. */ + uninstall_string?: string | null; + /** Windows: "HKLM64|" — the uninstall registry record itself. */ + reg_key?: string | null; + /** 安装不完整: the record survives but the product files are gone. */ + dead?: boolean; /** data-URL PNG icon (apps_scan only; null when extraction failed). */ icon?: string | null; }