深度扫描目录改为可检视清单(对齐 Mole);Git 保护开关移除
- 深度扫描目录:点击不再只弹文件夹框,展开清单逐行显示每个目录(✓ 存在 / ⌀ 不存在已跳过),支持移除、添加、恢复默认;折叠态文案改为 「N 处有效 · M 处不存在已跳过」;所有增删即时写入配置文件(原先只存内存, 重启即丢)。 - 默认清单 Windows 化:桌面 / 文档 / source\repos(VS 默认)等惯例目录前置。 - 界面移除「Git 保护」开关:它本来就是默认安全兜底,现在永远开启; 需要绕过走 CLI --all。 - 新增 roots_status 命令与 settings 持久化 purgeRoots;无头浏览器 10 项 点击断言全过;cargo fmt/test/clippy、pnpm check/build 全绿。dev
parent
e3eba338a7
commit
3bb3aeca42
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<Vec<String>>) -> Result<Vec<RootStatus>, String> {
|
||||
let list = tauri::async_runtime::spawn_blocking(move || -> Result<Vec<RootStatus>, 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<String>,
|
||||
show_allocated: Option<bool>,
|
||||
purge_min_age_days: Option<u64>,
|
||||
purge_roots: Option<Vec<String>>,
|
||||
history_keep: Option<usize>,
|
||||
setup_reviewed: Option<bool>,
|
||||
}
|
||||
|
|
@ -1087,6 +1126,15 @@ pub async fn settings_save(patch: SettingsPatch) -> Result<SettingsView, String>
|
|||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<SettingsView>("whitelist_add", { path }),
|
||||
whitelistRemove: (pattern: string) => invoke<SettingsView>("whitelist_remove", { pattern }),
|
||||
whitelistAudit: () => invoke<{ pattern: string; live: boolean }[]>("whitelist_audit"),
|
||||
rootsStatus: (roots: string[] | null) =>
|
||||
invoke<RootStatus[]>("roots_status", { roots: roots ?? null }),
|
||||
writeTextFile: (path: string, contents: string) =>
|
||||
invoke<void>("write_text_file", { path, contents }),
|
||||
revealPath: (path: string) => invoke<void>("reveal_path", { path }),
|
||||
|
|
|
|||
|
|
@ -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<string[]>(bootstrap.settings.purgeRoots);
|
||||
const [rootsOpen, setRootsOpen] = useState(false);
|
||||
const [rootStatuses, setRootStatuses] = useState<RootStatus[]>([]);
|
||||
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<Entry[]>(() => {
|
||||
const all: Entry[] = [];
|
||||
for (const source of [cleanup, purge]) {
|
||||
|
|
@ -1049,20 +1091,88 @@ export function SpacePage({
|
|||
<span className="space-config-label">
|
||||
{t("Deep-scan folders", "深度扫描目录")}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="space-config-value"
|
||||
onClick={() => void browse()}
|
||||
title={roots.replace(/\r?\n/g, "\n")}
|
||||
>
|
||||
{roots.trim()
|
||||
? t(
|
||||
`${roots.split(/\r?\n/).filter((line) => line.trim()).length} folder(s) · click to edit`,
|
||||
`共 ${roots.split(/\r?\n/).filter((line) => line.trim()).length} 处 · 点击编辑`,
|
||||
)
|
||||
: t("Home folder (default)", "主目录(默认)")}
|
||||
<FolderOpen size={13} />
|
||||
</button>
|
||||
<span className="space-roots-wrap">
|
||||
<button
|
||||
type="button"
|
||||
className="space-config-value"
|
||||
onClick={toggleRootsPopover}
|
||||
aria-expanded={rootsOpen}
|
||||
>
|
||||
{(() => {
|
||||
const living = rootStatuses.filter((row) => row.exists).length;
|
||||
const missing = rootStatuses.length - living;
|
||||
if (!rootStatuses.length) {
|
||||
return roots.length
|
||||
? t(`${roots.length} folder(s) · click to view`, `共 ${roots.length} 处 · 点击检视`)
|
||||
: t("Defaults · click to view", "默认目录 · 点击检视");
|
||||
}
|
||||
return missing > 0
|
||||
? t(
|
||||
`${living} active · ${missing} missing (skipped)`,
|
||||
`${living} 处有效 · ${missing} 处不存在已跳过`,
|
||||
)
|
||||
: t(`${living} active folders`, `${living} 处目录全部有效`);
|
||||
})()}
|
||||
<ChevronRight
|
||||
size={12}
|
||||
style={{ transform: rootsOpen ? "rotate(90deg)" : undefined }}
|
||||
/>
|
||||
</button>
|
||||
{rootsOpen ? (
|
||||
<div className="space-roots-pop">
|
||||
<div className="space-roots-list">
|
||||
{(rootStatuses.length ? rootStatuses : roots.map((raw) => ({ raw, expanded: raw, exists: true }))).map(
|
||||
(row) => (
|
||||
<div
|
||||
className={`space-roots-row ${row.exists ? "" : "is-missing"}`}
|
||||
key={row.raw}
|
||||
>
|
||||
<span className="space-roots-state">
|
||||
{row.exists ? "✓" : "⌀"}
|
||||
</span>
|
||||
<span className="space-roots-path" title={row.expanded}>
|
||||
{row.expanded}
|
||||
</span>
|
||||
{!row.exists ? (
|
||||
<small>{t("missing · skipped", "不存在 · 跳过")}</small>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
className="space-roots-x"
|
||||
aria-label={t("Remove folder", "移除该目录")}
|
||||
onClick={() => void removeRoot(row.raw)}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
{roots.length === 0 ? (
|
||||
<p className="space-roots-empty">
|
||||
{t(
|
||||
"No folders — the built-in defaults are used.",
|
||||
"未设置目录,使用内置默认清单。",
|
||||
)}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="space-roots-acts">
|
||||
<Button variant="ghost" size="sm" icon={<FolderOpen size={13} />} onClick={() => void addRoots()}>
|
||||
{t("Add folder", "+ 添加目录")}
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={() => void resetRoots()}>
|
||||
{t("Restore defaults", "恢复默认")}
|
||||
</Button>
|
||||
<small>
|
||||
{t(
|
||||
"Saved automatically; missing folders are skipped at scan time.",
|
||||
"改动即时保存;扫描时不存在的目录自动跳过。",
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="space-config-label">
|
||||
{t("Older than", "仅处理早于")}
|
||||
</span>
|
||||
|
|
@ -1078,20 +1188,8 @@ export function SpacePage({
|
|||
</button>
|
||||
))}
|
||||
</div>
|
||||
<span className="space-config-label">
|
||||
{t("Git-protected", "Git 保护")}
|
||||
</span>
|
||||
<Toggle
|
||||
checked={!force}
|
||||
onChange={(on) => setForce(!on)}
|
||||
label={t("Git protection", "Git 保护")}
|
||||
/>
|
||||
<input
|
||||
className="space-roots-hidden"
|
||||
value={roots}
|
||||
onChange={(event) => setRoots(event.target.value)}
|
||||
aria-label={t("Project folders to inspect", "要检查的项目目录")}
|
||||
/>
|
||||
{/* Git 保护不再有开关:它永远是开着的(删前用 git 复核被跟踪的目录),
|
||||
需要绕过时走 CLI 的 --all。 */}
|
||||
</div>
|
||||
|
||||
{scanning ? (
|
||||
|
|
|
|||
116
src/styles.css
116
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue