开机启动项对齐电脑管家:软件分组总开关 + 默认折叠 + 其他软件兜底组

- 后端为每个启动项标注 named(能否归属到真实软件产品:二进制带可用的
  FileDescription/ProductName 才算),无法归属的进「其他软件」组(排最后),
  与管家的归类依据一致。
- 每个软件组标题行:图标、组名、状态(全部开启/部分开启/已全部关闭,橙/绿
  着色)、「共N项」与总开关;总开关一次开/关该组全部细项,点标题行展开细项
  单独控制;默认折叠,搜索时自动全部展开。
- 新增 toggleStartupGroup(逐项调用同一后端开关,失败汇总红色气泡)。
- 无头浏览器 9 项点击断言全过(折叠/计数/其他软件兜底与排序/组展开/总开关
  两连发/状态文案/搜索展开);fmt/test/clippy×2/pnpm check+build 全绿。
dev
lijunjie 2026-11-21 11:16:02 +08:00
parent 6a664515b3
commit 7f464e7a19
6 changed files with 218 additions and 42 deletions

View File

@ -28,6 +28,12 @@ pub struct StartupEntry {
/// `currentUser` | `machine`
pub scope: String,
pub enabled: bool,
/// True once the entry was attributed to a real software product (the
/// binary carries a human FileDescription/ProductName). 电脑管家 groups
/// every entry it *cannot* attribute under 其他软件; this flag drives
/// that bucket on the UI side.
#[serde(default)]
pub named: bool,
/// PNG bytes of the binary's default icon, extracted on Windows only —
/// the 电脑管家 habit of showing the software icon next to its name.
#[serde(default)]
@ -540,11 +546,20 @@ mod windows {
.entry(probed.clone())
.or_insert_with(|| {
let (description, product, _company) = version_strings(&probed);
(description, product, software_icon(&probed, &vendors))
let usable = |text: Option<String>| text.filter(|t| !is_placeholder_label(t));
(
usable(description),
usable(product),
software_icon(&probed, &vendors),
)
})
.clone();
entry.display_name =
friendly_program_name(&entry.name, description.as_deref(), product.as_deref());
// 电脑管家's grouping rule: an entry is only attributed to a
// software product when the binary carries real human strings;
// everything else falls into the 其他软件 bucket.
entry.named = description.is_some() || product.is_some();
entry.icon = icon;
}
}
@ -1128,6 +1143,7 @@ mod windows {
"currentUser".to_string()
},
enabled,
named: false,
});
}
out
@ -1176,6 +1192,7 @@ mod windows {
"currentUser".to_string()
},
enabled,
named: false,
});
}
out
@ -1224,6 +1241,7 @@ mod windows {
source_label: "计划任务".to_string(),
scope: "machine".to_string(),
enabled: task_settings_enabled(&text),
named: false,
});
}
}
@ -1300,6 +1318,7 @@ mod windows {
source_label: "计划任务".to_string(),
scope: "machine".to_string(),
enabled,
named: false,
});
}
out
@ -1428,6 +1447,7 @@ mod windows {
.to_string(),
scope: "machine".to_string(),
enabled: start == 2,
named: false,
});
}
out
@ -2322,6 +2342,7 @@ mod macos {
source_label: label.to_string(),
scope: scope.to_string(),
enabled,
named: true,
});
}
out
@ -2426,6 +2447,7 @@ mod linux {
source_label: "~/.config/autostart".to_string(),
scope: "currentUser".to_string(),
enabled,
named: true,
});
}
for entry in &mut out {

View File

@ -135,6 +135,8 @@ pub struct StartupView {
source_label: String,
scope: String,
enabled: bool,
/// Attributed to a real software product (drives the 其他软件 bucket).
named: bool,
}
impl From<&StartupEntry> for StartupView {
@ -149,6 +151,7 @@ impl From<&StartupEntry> for StartupView {
source_label: entry.source_label.clone(),
scope: entry.scope.clone(),
enabled: entry.enabled,
named: entry.named,
}
}
}

View File

@ -20,6 +20,8 @@ export interface PermissionsWorkspace {
scan: () => Promise<void>;
refreshWindows: () => Promise<void>;
toggleStartup: (id: string, enabled: boolean) => Promise<void>;
/** 电脑管家's master switch: flip every entry of one software group. */
toggleStartupGroup: (ids: string[], enabled: boolean) => Promise<void>;
toggleExtension: (id: string, registered: boolean) => Promise<void>;
addRule: (hwnd: number, matcher: "exact" | "contains") => Promise<void>;
toggleRule: (index: number, enabled: boolean) => Promise<void>;
@ -115,6 +117,32 @@ export function usePermissionsWorkspace(active: boolean): PermissionsWorkspace {
[push, scan],
);
const toggleStartupGroup = useCallback(
async (ids: string[], enabled: boolean) => {
if (ids.length === 0) return;
setBusyId(ids[0]);
setError(null);
const failures: string[] = [];
try {
for (const id of ids) {
try {
await api.startupSetEnabled(id, enabled);
} catch (reason) {
failures.push(messageFrom(reason));
}
}
await scan();
} finally {
setBusyId(null);
}
if (failures.length > 0) {
setError(failures[0]);
push(failures[0], "danger");
}
},
[push, scan],
);
const toggleExtension = useCallback(
async (id: string, registered: boolean) => {
setBusyId(id);
@ -217,6 +245,7 @@ export function usePermissionsWorkspace(active: boolean): PermissionsWorkspace {
scan,
refreshWindows,
toggleStartup,
toggleStartupGroup,
toggleExtension,
addRule,
toggleRule,

View File

@ -1,4 +1,4 @@
import { BellRing, RefreshCw, Search, ShieldCheck, Trash2, X } from "lucide-react";
import { BellRing, ChevronRight, RefreshCw, Search, ShieldCheck, Trash2, X } from "lucide-react";
import { useMemo, useState } from "react";
import { useI18n } from "../i18n";
import { shortPath } from "../lib/format";
@ -38,6 +38,7 @@ function RowIcon({ icon, label }: { icon: string | null | undefined; label: stri
export function PermissionsPage({ workspace }: { workspace: PermissionsWorkspace }) {
const { t } = useI18n();
const [query, setQuery] = useState("");
const [openGroups, setOpenGroups] = useState<Set<string>>(new Set());
const [extCat, setExtCat] = useState<string | null>(null);
const view = workspace.view;
@ -118,13 +119,32 @@ export function PermissionsPage({ workspace }: { workspace: PermissionsWorkspace
item.displayName.toLowerCase().includes(needle) ||
item.command.toLowerCase().includes(needle),
);
// 电脑管家 style: one group per software, Chinese name in the header.
// 电脑管家 style: one group per software (Chinese name in the header);
// every entry the backend could not attribute to a real product lands in
// a catch-all 其他软件 group, which always sorts last.
const otherName = t("Other software", "其他软件");
const startupGroups = new Map<string, typeof startup>();
for (const item of startup) {
const list = startupGroups.get(item.displayName) ?? [];
const key = item.named && item.displayName ? item.displayName : otherName;
const list = startupGroups.get(key) ?? [];
list.push(item);
startupGroups.set(item.displayName, list);
startupGroups.set(key, list);
}
const orderedGroups = [...startupGroups.entries()].sort(
([a], [b]) => Number(a === otherName) - Number(b === otherName),
);
// Groups start folded (管家 habit): the header carries a master switch
// and the status line; expanding shows the per-entry detail. Searching
// force-expands everything so matches are never hidden.
const searching = query.trim().length > 0;
const isGroupOpen = (name: string) => searching || openGroups.has(name);
const toggleGroupOpen = (name: string) =>
setOpenGroups((current) => {
const next = new Set(current);
if (next.has(name)) next.delete(name);
else next.add(name);
return next;
});
const groupedExtensions = view.extensions
.filter(
(entry) =>
@ -202,50 +222,88 @@ export function PermissionsPage({ workspace }: { workspace: PermissionsWorkspace
placeholder={t("Filter by name or path…", "按名称或路径筛选…")}
/>
</label>
{Array.from(startupGroups.entries()).map(([software, items]) => (
<div key={software}>
<h4 className="perm-group">
{items.find((item) => item.icon)?.icon ? (
<img className="perm-group-icon" src={softwareIcon(items)} alt="" />
) : (
<span className="perm-group-icon perm-group-icon-fallback" aria-hidden="true">
{software.trim().slice(0, 1).toUpperCase()}
</span>
)}
<span>{software}</span>
<b>
{t(
`${items.filter((item) => item.enabled).length}/${items.length} on`,
`${items.filter((item) => item.enabled).length}/${items.length} 开启`,
{orderedGroups.map(([software, items]) => {
const onCount = items.filter((item) => item.enabled).length;
const allOn = onCount === items.length;
const open = isGroupOpen(software);
const groupIds = items.map((item) => item.id);
return (
<div key={software} className={`perm-group-card ${open ? "is-open" : ""}`}>
<h4 className="perm-group" onClick={() => toggleGroupOpen(software)}>
{items.find((item) => item.icon)?.icon ? (
<img className="perm-group-icon" src={softwareIcon(items)} alt="" />
) : (
<span className="perm-group-icon perm-group-icon-fallback" aria-hidden="true">
{software.trim().slice(0, 1).toUpperCase()}
</span>
)}
</b>
</h4>
<div className="perm-rows">
{items.map((item) => (
<div
className={`settings-row ${workspace.busyId === item.id ? "is-busy" : ""}`}
key={item.id}
<span className="perm-group-name">{software}</span>
<b className={allOn ? "is-all" : onCount === 0 ? "is-none" : "is-part"}>
{allOn
? t("All on", "全部开启")
: onCount === 0
? t("All off", "已全部关闭")
: t(
`${onCount}/${items.length} on`,
`部分开启 ${onCount}/${items.length}`,
)}
</b>
<span
className="perm-group-tail"
onClick={(event) => event.stopPropagation()}
>
<div className="perm-row perm-row-noicon">
<div>
<span>{item.name}</span>
<small title={item.command}>
{item.sourceLabel} · {scopeLabel(item.scope, t)}
{item.command ? ` · ${shortPath(item.command, 72)}` : ""}
</small>
</div>
</div>
<span
className="perm-group-count"
onClick={(event) => {
event.stopPropagation();
toggleGroupOpen(software);
}}
>
{items.length > 1
? t(`${items.length} items`, `共${items.length}项`)
: t("1 item", "共1项")}
<ChevronRight
size={13}
className={`perm-group-chv ${open ? "is-open" : ""}`}
/>
</span>
<Toggle
checked={item.enabled}
checked={allOn}
disabled={workspace.busyId !== null}
onChange={(next) => void workspace.toggleStartup(item.id, next)}
label={`${item.name} ${item.enabled ? "disable" : "enable"}`}
onChange={(next) => void workspace.toggleStartupGroup(groupIds, next)}
label={`${software} master ${allOn ? "disable" : "enable"}`}
/>
</span>
</h4>
{open ? (
<div className="perm-rows">
{items.map((item) => (
<div
className={`settings-row ${workspace.busyId === item.id ? "is-busy" : ""}`}
key={item.id}
>
<div className="perm-row perm-row-noicon">
<div>
<span>{item.name}</span>
<small title={item.command}>
{item.sourceLabel} · {scopeLabel(item.scope, t)}
{item.command ? ` · ${shortPath(item.command, 72)}` : ""}
</small>
</div>
</div>
<Toggle
checked={item.enabled}
disabled={workspace.busyId !== null}
onChange={(next) => void workspace.toggleStartup(item.id, next)}
label={`${item.name} ${item.enabled ? "disable" : "enable"}`}
/>
</div>
))}
</div>
))}
) : null}
</div>
</div>
))}
);
})}
{startup.length === 0 ? (
<p className="perm-empty">{t("No matches.", "没有匹配的项目。")}</p>
) : null}

View File

@ -4970,6 +4970,68 @@ select:focus-visible,
font-weight: var(--nex-weight-regular);
}
/* 电脑管家-style startup groups: folded software rows with a master switch. */
.perm-group-card {
border-radius: 10px;
transition: background 0.15s ease;
}
.perm-group-card:hover {
background: rgba(255, 255, 255, 0.55);
}
.perm-group-card .perm-group {
cursor: pointer;
user-select: none;
}
.perm-group-card.is-open .perm-group {
margin-bottom: 0;
}
.perm-group-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.perm-group b.is-all {
color: #4b8a55;
}
.perm-group b.is-part {
color: #b3854d;
}
.perm-group b.is-none {
color: #9aa6b2;
}
.perm-group-tail {
display: flex;
align-items: center;
gap: 12px;
margin-left: auto;
}
.perm-group-count {
display: inline-flex;
align-items: center;
gap: 3px;
color: #909fad;
font-size: var(--nex-text-3xs);
cursor: pointer;
}
.perm-group-chv {
color: #b7bfca;
transition: transform 0.15s ease;
}
.perm-group-chv.is-open {
transform: rotate(90deg);
}
/* Per-row software icon (电脑管家 shows the app icon on every list row). */
.settings-row > .perm-row {
display: flex;

View File

@ -362,6 +362,8 @@ export interface StartupItem {
sourceLabel: string;
scope: string;
enabled: boolean;
/** Attributed to a real product; false lands in the 其他软件 group. */
named: boolean;
}
export interface ShellExtension {