空间清理:默认勾选改为页面策略一次播种;修复扫描后卡片互锁不可点
- 根因:浏览器缓存/部分系统垃圾规则 select_by_default=false,而项目产物/开发文件默认 true,方向与页面设计相反;页面用级联 setState 事后纠正时相互覆盖(后生效的只保留自己的类别)——默认态改由 useScanWorkspace 的 selectionPolicy 在扫描落地时一次 seedSelection 播种(日常类全勾、可选类全不勾) - 卡片 disabled 原为「无已选项目」,用户取消勾选后立刻灰死且全选后反向死锁;改为「全部条目锁定」才禁用,勾选状态判定改用 removable 计数 - 「N 项」按钮接通 focus 过滤(显示全部 / 按类过滤) - 重新打包(sha256 ce99d51d…)dev
parent
ad1b70fe13
commit
5f6112f877
|
|
@ -1,2 +1,2 @@
|
|||
9ccb814e0e5b59847d650581f2707e7c392b12910e134f0320dac4665d98ce19 *Squid-Setup-0.1.10-win-x64.exe
|
||||
c0908cb68b9e4b91b5901199217a5fa28624ec7588931f53a2e9318b72f9382e *Squid-0.1.10-portable-win-x64.zip
|
||||
ce99d51d92fdedcd9f858fde032a0aaf1d159d12962a06b8f1a30b46f361c990 *Squid-Setup-0.1.10-win-x64.exe
|
||||
53cda1033de7db972961ebd6a707ac311fbd05e01fd12243cfd499b90636231e *Squid-0.1.10-portable-win-x64.zip
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -6,8 +6,8 @@
|
|||
"artifacts": {
|
||||
"windows": {
|
||||
"file": "Squid-Setup-0.1.10-win-x64.exe",
|
||||
"sha256": "9ccb814e0e5b59847d650581f2707e7c392b12910e134f0320dac4665d98ce19",
|
||||
"size": 3568622
|
||||
"sha256": "ce99d51d92fdedcd9f858fde032a0aaf1d159d12962a06b8f1a30b46f361c990",
|
||||
"size": 3570273
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/App.tsx
16
src/App.tsx
|
|
@ -167,6 +167,17 @@ function BootstrapError({ message }: { message: string }) {
|
|||
);
|
||||
}
|
||||
|
||||
const SPACE_OPTIONAL_CATEGORIES = [
|
||||
"update-installers",
|
||||
"project-artifacts",
|
||||
"developer",
|
||||
];
|
||||
|
||||
/** 空间清理 defaults: daily groups pre-checked, opt-in groups untouched. */
|
||||
function spaceDefaults(item: { category: string }): boolean {
|
||||
return !SPACE_OPTIONAL_CATEGORIES.includes(item.category);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const { push } = useToast();
|
||||
const [bootstrap, setBootstrap] = useState<Bootstrap | null>(null);
|
||||
|
|
@ -178,8 +189,9 @@ export default function App() {
|
|||
const [setupOpen, setSetupOpen] = useState(false);
|
||||
// The 托盘驻留 case: a hidden main window must stop sampling the machine.
|
||||
const [windowVisible, setWindowVisible] = useState(true);
|
||||
const cleanup = useScanWorkspace("cleanup");
|
||||
const purge = useScanWorkspace("purge");
|
||||
// 空间清理 defaults: daily groups pre-checked, opt-in groups untouched.
|
||||
const cleanup = useScanWorkspace("cleanup", spaceDefaults);
|
||||
const purge = useScanWorkspace("purge", spaceDefaults);
|
||||
const apps = useAppsWorkspace();
|
||||
const permissions = usePermissionsWorkspace(page === "permissions");
|
||||
const systemActive = (page === "overview" || page === "system") && windowVisible;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { api, subscribeJobProgress } from "../lib/api";
|
|||
import { isCancelled, messageFrom } from "../lib/format";
|
||||
import type {
|
||||
Category,
|
||||
CleanupItem,
|
||||
DeleteMode,
|
||||
DeleteResult,
|
||||
JobProgress,
|
||||
|
|
@ -15,6 +16,20 @@ function jobId(): string {
|
|||
|
||||
export type ScanKind = "cleanup" | "purge";
|
||||
|
||||
/** Seed the checkbox state of a fresh result: unlocked items the policy
|
||||
* keeps win; without a policy the rule metadata (`item.selected`) speaks. */
|
||||
export function seedSelection(
|
||||
items: CleanupItem[],
|
||||
defaultFor?: (item: CleanupItem) => boolean,
|
||||
): Set<number> {
|
||||
const picked = new Set<number>();
|
||||
items.forEach((item, index) => {
|
||||
if (item.lock) return;
|
||||
if (defaultFor ? defaultFor(item) : item.selected) picked.add(index);
|
||||
});
|
||||
return picked;
|
||||
}
|
||||
|
||||
export interface ScanWorkspace {
|
||||
kind: ScanKind;
|
||||
result: ScanResult | null;
|
||||
|
|
@ -44,7 +59,16 @@ export interface ScanWorkspace {
|
|||
reset: () => void;
|
||||
}
|
||||
|
||||
export function useScanWorkspace(kind: ScanKind): ScanWorkspace {
|
||||
export function useScanWorkspace(
|
||||
kind: ScanKind,
|
||||
/** Overrides the rule metadata's per-item default when a scan lands
|
||||
* (空间清理 uses this to pre-check every daily group and leave opt-in
|
||||
* groups untouched). Read through a ref, so a fresh closure per render is
|
||||
* fine without restarting the hook. */
|
||||
selectionPolicy?: (item: CleanupItem) => boolean,
|
||||
): ScanWorkspace {
|
||||
const policyRef = useRef(selectionPolicy);
|
||||
policyRef.current = selectionPolicy;
|
||||
const [result, setResult] = useState<ScanResult | null>(null);
|
||||
const [selected, setSelected] = useState<Set<number>>(new Set());
|
||||
const [progress, setProgress] = useState<JobProgress | null>(null);
|
||||
|
|
@ -82,14 +106,7 @@ export function useScanWorkspace(kind: ScanKind): ScanWorkspace {
|
|||
);
|
||||
if (activeJob.current !== id) return;
|
||||
setResult(next);
|
||||
setSelected(
|
||||
new Set(
|
||||
next.items
|
||||
.map((item, index) => ({ item, index }))
|
||||
.filter(({ item }) => item.selected && !item.lock)
|
||||
.map(({ index }) => index),
|
||||
),
|
||||
);
|
||||
setSelected(seedSelection(next.items, policyRef.current));
|
||||
} catch (reason) {
|
||||
if (!isCancelled(reason)) setError(messageFrom(reason));
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import {
|
|||
ProgressCard,
|
||||
SectionTitle,
|
||||
Toggle,
|
||||
categoryLabel,
|
||||
useToast,
|
||||
} from "../components/ui";
|
||||
|
||||
|
|
@ -73,6 +74,7 @@ export function SpacePage({
|
|||
const [minAge, setMinAge] = useState(bootstrap.settings.purgeMinAgeDays || 7);
|
||||
const [force, setForce] = useState(false);
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const [focus, setFocus] = useState<Category | null>(null);
|
||||
const [mode, setMode] = useState<DeleteMode>(deleteMode);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [result, setResult] = useState<DeleteResult | null>(null);
|
||||
|
|
@ -102,23 +104,8 @@ export function SpacePage({
|
|||
}
|
||||
}, [cleanup, deleting, force, minAge, purge, roots, scanning]);
|
||||
|
||||
// The optional groups start untouched on every fresh result: the hooks'
|
||||
// default selection comes from rule metadata, and this page overrides the
|
||||
// three opt-in categories back to "unchecked" once React has committed.
|
||||
useEffect(() => {
|
||||
if (!cleanup.result) return;
|
||||
for (const category of OPTIONAL_CATEGORIES) {
|
||||
cleanup.setCategorySelection(category, false);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [cleanup.result]);
|
||||
useEffect(() => {
|
||||
if (!purge.result) return;
|
||||
for (const category of OPTIONAL_CATEGORIES) {
|
||||
purge.setCategorySelection(category, false);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [purge.result]);
|
||||
// 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 () => {
|
||||
const chosen = await open({
|
||||
|
|
@ -152,16 +139,18 @@ export function SpacePage({
|
|||
const groups = useMemo(() => {
|
||||
const map = new Map<
|
||||
Category,
|
||||
{ total: number; count: number; selected: number }
|
||||
{ total: number; count: number; selected: number; removable: number }
|
||||
>();
|
||||
for (const entry of entries) {
|
||||
const group = map.get(entry.item.category) ?? {
|
||||
total: 0,
|
||||
count: 0,
|
||||
selected: 0,
|
||||
removable: 0,
|
||||
};
|
||||
group.total += entry.item.onDisk;
|
||||
group.count += 1;
|
||||
if (!entry.item.lock) group.removable += 1;
|
||||
if (entry.source.selected.has(entry.index)) group.selected += 1;
|
||||
map.set(entry.item.category, group);
|
||||
}
|
||||
|
|
@ -213,26 +202,25 @@ export function SpacePage({
|
|||
}, [entries]);
|
||||
|
||||
const toggleGroup = (category: Category) => {
|
||||
const allOn = groupSelected(category);
|
||||
for (const source of [cleanup, purge]) {
|
||||
if (source.result?.items.some((item) => item.category === category)) {
|
||||
const anyOn = source.result.items.some(
|
||||
(item, index) =>
|
||||
item.category === category &&
|
||||
!item.lock &&
|
||||
source.selected.has(index),
|
||||
);
|
||||
source.setCategorySelection(category, !anyOn);
|
||||
source.setCategorySelection(category, !allOn);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const groupSelected = (category: string) => {
|
||||
const group = groups.get(category as Category);
|
||||
return Boolean(group && group.count > 0 && group.selected === group.count);
|
||||
// A group is "on" when every removable item in it is checked; it may only
|
||||
// switch itself off when nothing can be removed at all (every row locked)
|
||||
// — an empty selection is a state to click back from, never a disability.
|
||||
const groupSelected = (category: Category) => {
|
||||
const group = groups.get(category);
|
||||
if (!group || group.removable === 0) return false;
|
||||
return group.selected >= group.removable;
|
||||
};
|
||||
const groupDisabled = (category: string) => {
|
||||
const group = groups.get(category as Category);
|
||||
return !group || group.count === 0 || group.selected === 0;
|
||||
const groupDisabled = (category: Category) => {
|
||||
const group = groups.get(category);
|
||||
return !group || group.removable === 0;
|
||||
};
|
||||
|
||||
// One delete button, possibly two engines: run whichever halves have a
|
||||
|
|
@ -566,10 +554,10 @@ export function SpacePage({
|
|||
total={group.total}
|
||||
count={group.count}
|
||||
selected={groupSelected(category)}
|
||||
focused={false}
|
||||
focused={focus === category}
|
||||
disabled={groupDisabled(category)}
|
||||
onToggle={() => toggleGroup(category)}
|
||||
onInspect={() => undefined}
|
||||
onInspect={() => setFocus(focus === category ? null : category)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
@ -579,21 +567,34 @@ export function SpacePage({
|
|||
|
||||
<section className="cleanup-list-panel">
|
||||
<SectionTitle
|
||||
title={t("Everything found in this scan", "本次扫描的全部项目")}
|
||||
title={
|
||||
focus
|
||||
? categoryLabel(focus, lang, bin)
|
||||
: t("Everything found in this scan", "本次扫描的全部项目")
|
||||
}
|
||||
subtitle={t(
|
||||
"Only checked items are touched. Protected items stay locked.",
|
||||
"只会处理已勾选的项目,受保护项目始终保持锁定。",
|
||||
)}
|
||||
action={
|
||||
focus ? (
|
||||
<Button variant="ghost" size="sm" onClick={() => setFocus(null)}>
|
||||
{t("Show all", "显示全部")}
|
||||
</Button>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
<div className="cleanup-rows">
|
||||
{entries.map((entry) => (
|
||||
<ItemRow
|
||||
key={`${entry.item.path}-${entry.index}`}
|
||||
item={entry.item}
|
||||
checked={entry.source.selected.has(entry.index)}
|
||||
onToggle={() => entry.source.toggleItem(entry.index)}
|
||||
/>
|
||||
))}
|
||||
{entries
|
||||
.filter((entry) => !focus || entry.item.category === focus)
|
||||
.map((entry) => (
|
||||
<ItemRow
|
||||
key={`${entry.item.path}-${entry.index}`}
|
||||
item={entry.item}
|
||||
checked={entry.source.selected.has(entry.index)}
|
||||
onToggle={() => entry.source.toggleItem(entry.index)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
|
|
|
|||
Loading…
Reference in New Issue