diff --git a/crates/squid-platform/src/permissions.rs b/crates/squid-platform/src/permissions.rs index 41d3148..b76242f 100644 --- a/crates/squid-platform/src/permissions.rs +++ b/crates/squid-platform/src/permissions.rs @@ -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| 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 { diff --git a/src-tauri/src/manage.rs b/src-tauri/src/manage.rs index 6f70f44..999fce3 100644 --- a/src-tauri/src/manage.rs +++ b/src-tauri/src/manage.rs @@ -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, } } } diff --git a/src/hooks/usePermissionsWorkspace.ts b/src/hooks/usePermissionsWorkspace.ts index ef8792a..bcc41b7 100644 --- a/src/hooks/usePermissionsWorkspace.ts +++ b/src/hooks/usePermissionsWorkspace.ts @@ -20,6 +20,8 @@ export interface PermissionsWorkspace { scan: () => Promise; refreshWindows: () => Promise; toggleStartup: (id: string, enabled: boolean) => Promise; + /** 电脑管家's master switch: flip every entry of one software group. */ + toggleStartupGroup: (ids: string[], enabled: boolean) => Promise; toggleExtension: (id: string, registered: boolean) => Promise; addRule: (hwnd: number, matcher: "exact" | "contains") => Promise; toggleRule: (index: number, enabled: boolean) => Promise; @@ -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, diff --git a/src/pages/PermissionsPage.tsx b/src/pages/PermissionsPage.tsx index 3be4fbe..ee0c078 100644 --- a/src/pages/PermissionsPage.tsx +++ b/src/pages/PermissionsPage.tsx @@ -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>(new Set()); const [extCat, setExtCat] = useState(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(); 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…", "按名称或路径筛选…")} /> - {Array.from(startupGroups.entries()).map(([software, items]) => ( -
-

- {items.find((item) => item.icon)?.icon ? ( - - ) : ( - - )} - {software} - - {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 ( +
+

toggleGroupOpen(software)}> + {items.find((item) => item.icon)?.icon ? ( + + ) : ( + )} - -

-
- {items.map((item) => ( -
{software} + + {allOn + ? t("All on", "全部开启") + : onCount === 0 + ? t("All off", "已全部关闭") + : t( + `${onCount}/${items.length} on`, + `部分开启 ${onCount}/${items.length}`, + )} + + event.stopPropagation()} > -
-
- {item.name} - - {item.sourceLabel} · {scopeLabel(item.scope, t)} - {item.command ? ` · ${shortPath(item.command, 72)}` : ""} - -
-
+ { + event.stopPropagation(); + toggleGroupOpen(software); + }} + > + {items.length > 1 + ? t(`${items.length} items`, `共${items.length}项`) + : t("1 item", "共1项")} + + 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"}`} /> +
+

+ {open ? ( +
+ {items.map((item) => ( +
+
+
+ {item.name} + + {item.sourceLabel} · {scopeLabel(item.scope, t)} + {item.command ? ` · ${shortPath(item.command, 72)}` : ""} + +
+
+ void workspace.toggleStartup(item.id, next)} + label={`${item.name} ${item.enabled ? "disable" : "enable"}`} + /> +
+ ))}
- ))} + ) : null}
- - ))} + ); + })} {startup.length === 0 ? (

{t("No matches.", "没有匹配的项目。")}

) : null} diff --git a/src/styles.css b/src/styles.css index 4d1cdb0..8d978c8 100644 --- a/src/styles.css +++ b/src/styles.css @@ -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; diff --git a/src/types.ts b/src/types.ts index 000d1e1..8ae38b7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 {