diff --git a/crates/squid-core/src/settings.rs b/crates/squid-core/src/settings.rs index 4e58e61..fa85bf0 100644 --- a/crates/squid-core/src/settings.rs +++ b/crates/squid-core/src/settings.rs @@ -45,6 +45,13 @@ impl Default for Settings { whitelist: Vec::new(), disabled_rules: Vec::new(), purge_roots: vec![ + // Windows-style project homes first; the classic dev names + // stay (case variants dedupe at check time), and every entry + // is skipped silently when absent — Mole's default-list habit. + "~/Desktop".into(), + "~/Documents".into(), + "~/Documents/WeChat Projects".into(), + "~/source/repos".into(), "~/code".into(), "~/Code".into(), "~/dev".into(), @@ -57,8 +64,6 @@ impl Default for Settings { "~/src".into(), "~/work".into(), "~/Work".into(), - "~/Desktop".into(), - "~/Documents".into(), "~/.codex/worktrees".into(), ], purge_min_age_days: 7, diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index bbf2fef..1ffbc9e 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -1010,6 +1010,44 @@ pub fn stop_process(app: AppHandle, process: ProcessSample) -> Result<(), String /// Write a UTF-8 text file (B5 clean-list export; the UI picked the path /// through the save dialog, so this is a plain, bounded write). +/// Existence check for the 深度扫描目录 picker: Mole's manage screen shows +/// per-path ✓ / not-found, so the UI needs the same facts. `~` expands. +/// Without an explicit list the persisted one is reported on. +#[derive(Clone, serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RootStatus { + raw: String, + expanded: String, + exists: bool, +} + +#[tauri::command] +pub async fn roots_status(roots: Option>) -> Result, String> { + let list = tauri::async_runtime::spawn_blocking(move || -> Result, String> { + let list = match roots { + Some(list) => list, + None => { + let (settings, _) = Settings::load(); + settings.purge_roots + } + }; + Ok(list + .iter() + .map(|raw| { + let path = squid_core::paths::expand(raw); + RootStatus { + raw: raw.clone(), + expanded: squid_core::paths::pretty(&path), + exists: path.is_dir(), + } + }) + .collect()) + }) + .await + .map_err(|error| error.to_string())??; + Ok(list) +} + #[tauri::command] pub async fn write_text_file(path: String, contents: String) -> Result<(), String> { tauri::async_runtime::spawn_blocking(move || { @@ -1066,6 +1104,7 @@ pub struct SettingsPatch { language: Option, show_allocated: Option, purge_min_age_days: Option, + purge_roots: Option>, history_keep: Option, setup_reviewed: Option, } @@ -1087,6 +1126,15 @@ pub async fn settings_save(patch: SettingsPatch) -> Result if let Some(days) = patch.purge_min_age_days { settings.purge_min_age_days = days.min(3650); } + if let Some(roots) = patch.purge_roots { + // Empty list = "back to the built-in defaults", mirroring Mole's + // leave-the-file-blank-to-reset habit. + settings.purge_roots = if roots.is_empty() { + Settings::default().purge_roots + } else { + roots + }; + } if let Some(keep) = patch.history_keep { settings.history_keep = keep.clamp(5, 500); } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8646d15..cc0ace5 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -131,6 +131,7 @@ pub fn run() { app::storage_explore, app::storage_insights, app::write_text_file, + app::roots_status, app::storage_largest_files, app::system_snapshot, app::stop_process, diff --git a/src/lib/api.ts b/src/lib/api.ts index 0bab13b..cb8ce68 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -16,6 +16,7 @@ import type { PopupClosedEvent, PopupWindowItem, PreflightResult, + RootStatus, ScanResult, SettingsView, SpaceInsight, @@ -33,6 +34,7 @@ export interface SettingsPatch { language?: string; showAllocated?: boolean; purgeMinAgeDays?: number; + purgeRoots?: string[]; historyKeep?: number; setupReviewed?: boolean; } @@ -78,6 +80,8 @@ export const api = { whitelistAdd: (path: string) => invoke("whitelist_add", { path }), whitelistRemove: (pattern: string) => invoke("whitelist_remove", { pattern }), whitelistAudit: () => invoke<{ pattern: string; live: boolean }[]>("whitelist_audit"), + rootsStatus: (roots: string[] | null) => + invoke("roots_status", { roots: roots ?? null }), writeTextFile: (path: string, contents: string) => invoke("write_text_file", { path, contents }), revealPath: (path: string) => invoke("reveal_path", { path }), diff --git a/src/pages/SpacePage.tsx b/src/pages/SpacePage.tsx index b3c163e..1b18ca3 100644 --- a/src/pages/SpacePage.tsx +++ b/src/pages/SpacePage.tsx @@ -40,6 +40,7 @@ import type { DeleteMode, DeleteResult, PreflightResult, + RootStatus, } from "../types"; import type { ScanWorkspace } from "../hooks/useScanWorkspace"; import { @@ -51,7 +52,6 @@ import { InlineError, ProgressCard, SectionTitle, - Toggle, categoryLabel, lockLabel, useToast, @@ -455,9 +455,12 @@ export function SpacePage({ }) { const { t, lang, bin } = useI18n(); const { push } = useToast(); - const [roots, setRoots] = useState(bootstrap.settings.purgeRoots.join("\n")); + // 深度扫描目录: the persisted list, edited in a checklist popover that + // mirrors Mole's manage screen (every path shown, ✓ / 不存在 marked). + const [roots, setRoots] = useState(bootstrap.settings.purgeRoots); + const [rootsOpen, setRootsOpen] = useState(false); + const [rootStatuses, setRootStatuses] = useState([]); const [minAge, setMinAge] = useState(bootstrap.settings.purgeMinAgeDays || 7); - const [force, setForce] = useState(false); const [confirming, setConfirming] = useState(false); // Open accordions. On first results we auto-expand the biggest category so // the list never reads as a dead panel; that initial choice is remembered @@ -486,26 +489,47 @@ export function SpacePage({ // (and its preflight verdict) no longer describes what is on screen. setInlineConfirm(false); setPreflight(null); - const rootList = roots - .split(/\r?\n/) - .map((root) => root.trim()) - .filter(Boolean); try { await cleanup.runScan(); await purge.runScan({ - roots: rootList, + roots, minAgeDays: minAge > 0 ? minAge : null, - force, + force: false, }); } finally { inFlight.current = false; } - }, [cleanup, deleting, force, minAge, purge, roots, scanning]); + }, [cleanup, deleting, minAge, purge, roots, scanning]); // Default checking is seeded at scan time by the workspaces' selection // policy (App.tsx spaceDefaults): daily groups on, opt-in groups off. - const browse = async () => { + // Every roots edit lands on disk right away (Mole persists its list file; + // a restart must never silently revert to defaults). + const saveRoots = async (next: string[]) => { + setRoots(next); + try { + await api.settingsSave({ purgeRoots: next }); + } catch { + // Scan still uses the in-memory list; persistence can retry next edit. + } + }; + + const refreshRootStatuses = async (list: string[]) => { + try { + setRootStatuses(await api.rootsStatus(list)); + } catch { + setRootStatuses([]); + } + }; + + const toggleRootsPopover = () => { + const next = !rootsOpen; + setRootsOpen(next); + if (next) void refreshRootStatuses(roots); + }; + + const addRoots = async () => { const chosen = await open({ directory: true, multiple: true, @@ -513,17 +537,35 @@ export function SpacePage({ }); if (!chosen) return; const picked = (Array.isArray(chosen) ? chosen : [chosen]).filter( - (path) => !roots.split(/\r?\n/).some((line) => line.trim() === path), + (path) => !roots.some((root) => root.toLowerCase() === path.toLowerCase()), ); if (picked.length > 0) { - setRoots((current) => - current.trim().length > 0 - ? `${current.trimEnd()}\n${picked.join("\n")}` - : picked.join("\n"), - ); + const next = [...roots, ...picked]; + await saveRoots(next); + void refreshRootStatuses(next); } }; + const removeRoot = async (raw: string) => { + const next = roots.filter((root) => root !== raw); + await saveRoots(next); + void refreshRootStatuses(next); + }; + + const resetRoots = async () => { + await saveRoots([]); + // [] on disk means defaults again: the Rust patch swaps in the built-in + // list, so re-read it to keep the popover honest. + try { + const status = await api.rootsStatus(null); + setRoots(status.map((row) => row.raw)); + setRootStatuses(status); + } catch { + setRootStatuses([]); + } + push(t("Scan folders restored to defaults", "扫描目录已恢复默认"), "success"); + }; + const entries = useMemo(() => { const all: Entry[] = []; for (const source of [cleanup, purge]) { @@ -1049,20 +1091,88 @@ export function SpacePage({ {t("Deep-scan folders", "深度扫描目录")} - + + + {rootsOpen ? ( +
+
+ {(rootStatuses.length ? rootStatuses : roots.map((raw) => ({ raw, expanded: raw, exists: true }))).map( + (row) => ( +
+ + {row.exists ? "✓" : "⌀"} + + + {row.expanded} + + {!row.exists ? ( + {t("missing · skipped", "不存在 · 跳过")} + ) : null} + +
+ ), + )} + {roots.length === 0 ? ( +

+ {t( + "No folders — the built-in defaults are used.", + "未设置目录,使用内置默认清单。", + )} +

+ ) : null} +
+
+ + + + {t( + "Saved automatically; missing folders are skipped at scan time.", + "改动即时保存;扫描时不存在的目录自动跳过。", + )} + +
+
+ ) : null} +
{t("Older than", "仅处理早于")} @@ -1078,20 +1188,8 @@ export function SpacePage({ ))} - - {t("Git-protected", "Git 保护")} - - setForce(!on)} - label={t("Git protection", "Git 保护")} - /> - setRoots(event.target.value)} - aria-label={t("Project folders to inspect", "要检查的项目目录")} - /> + {/* Git 保护不再有开关:它永远是开着的(删前用 git 复核被跟踪的目录), + 需要绕过时走 CLI 的 --all。 */} {scanning ? ( diff --git a/src/styles.css b/src/styles.css index 310ee6d..a1c17fa 100644 --- a/src/styles.css +++ b/src/styles.css @@ -5329,7 +5329,6 @@ select:focus-visible, align-items: center; gap: 6px; min-width: 0; - flex: 1; border: none; background: none; color: var(--nex-muted); @@ -5379,6 +5378,121 @@ select:focus-visible, font-size: var(--nex-text-2xs); } +/* 深度扫描目录 checklist popover (Mole manage-screen habit). */ +.space-roots-wrap { + position: relative; + display: inline-flex; + min-width: 0; + flex: 1; +} + +.space-roots-wrap .space-config-value { + flex: 1; +} + +.space-roots-pop { + position: absolute; + top: calc(100% + 8px); + left: 0; + z-index: 30; + width: min(460px, 86vw); + padding: 10px 12px 12px; + border: 1px solid #eee1cc; + border-radius: 12px; + background: #fffdf8; + box-shadow: 0 12px 32px rgba(90, 60, 20, 0.16); +} + +.space-roots-list { + display: flex; + max-height: 240px; + flex-direction: column; + gap: 1px; + overflow-y: auto; +} + +.space-roots-row { + display: flex; + align-items: center; + gap: 8px; + padding: 4px 6px; + border-radius: 7px; +} + +.space-roots-row:hover { + background: #f8f1e2; +} + +.space-roots-state { + flex: 0 0 auto; + width: 14px; + color: #4b8a55; + font-size: var(--nex-text-3xs); + text-align: center; +} + +.space-roots-row.is-missing .space-roots-state { + color: #c0b49b; +} + +.space-roots-path { + min-width: 0; + flex: 1 1 auto; + overflow: hidden; + color: #42505e; + font-size: var(--nex-text-3xs); + text-overflow: ellipsis; + white-space: nowrap; +} + +.space-roots-row.is-missing .space-roots-path { + color: #b3a688; + text-decoration: line-through; + text-decoration-color: rgba(179, 166, 136, 0.5); +} + +.space-roots-row small { + flex: 0 0 auto; + color: #b3a688; + font-size: var(--nex-text-3xs); +} + +.space-roots-x { + flex: 0 0 auto; + padding: 0 4px; + border: none; + background: none; + color: #c0b49b; + font-size: 14px; + line-height: 1; + cursor: pointer; +} + +.space-roots-x:hover { + color: #a94c52; +} + +.space-roots-empty { + margin: 4px 0; + color: #909fad; + font-size: var(--nex-text-3xs); +} + +.space-roots-acts { + display: flex; + align-items: center; + gap: 8px; + margin-top: 8px; + padding-top: 8px; + border-top: 1px dashed #eee1cc; +} + +.space-roots-acts small { + margin-left: auto; + color: #b3a688; + font-size: var(--nex-text-3xs); +} + .space-stage-steps { display: flex; flex-direction: column; diff --git a/src/types.ts b/src/types.ts index 000d1e1..0b76fb3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -286,6 +286,13 @@ export interface PreflightResult { blocked: { path: string; reason: string }[]; } +/** One 深度扫描目录 with its existence verdict (Mole manage-screen habit). */ +export interface RootStatus { + raw: string; + expanded: string; + exists: boolean; +} + export interface LargestFile { path: string; logical: number;