From 09ad92972cc901f376278df555501d1472e7f10a Mon Sep 17 00:00:00 2001 From: workbuddy-mac13 Date: Sat, 28 Nov 2026 20:20:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(sidebar):=20=E9=BB=98=E8=AE=A4=E6=8A=98?= =?UTF-8?q?=E5=8F=A0=E6=AC=A1=E8=A6=81=E4=BE=A7=E6=A0=8F=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E6=94=B6=E8=BF=9B=E5=AE=BF=E4=B8=BB=E3=80=8C=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E3=80=8D=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 宿主左栏自带取消固定机制(localStorage dsh-desktop.sidebar.panel-pins = {unpinned:[panelId]}): 未固定的入口会从左栏隐藏,收进宿主自带的「更多」菜单(sidebar.panellist.actions)。 本插件在客户端首次装载时写入默认折叠集合,并刷新一次让折叠生效: dsh-market(插件市场)、dsh-context(上下文洞察)、 task-board(任务看板)、forge-review(代码评审) - 标记键 dsh-apes-sidebar:collapsed-defaults 记录已写集合, 之后用户手动 pin / unpin 的结果不再被改动;默认集合升级时只补齐缺项 - 宿主固定项 plugins(插件管理入口)不可折叠,保持显示 - 仅存储不可用时静默跳过,不阻断插件装载 --- src/client/index.tsx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/client/index.tsx b/src/client/index.tsx index 4dadfaf1..ce931b61 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -82,11 +82,52 @@ export const inject = ['slots', 'sessions', 'locale', 'modules', 'connection', ' * per-tab scope (Sidebar.tsx) catches viewer/editor crashes first; this root * boundary stays as the last resort for Workbench/shell errors. */ +/** + * 宿主左栏的「取消固定」状态:localStorage `dsh-desktop.sidebar.panel-pins` + * 形如 `{ unpinned: string[] }`。未被固定的入口会从左栏隐藏,收进宿主自带的 + * 「更多」菜单(`sidebar.panellist.actions` → entry-customization)。 + * + * 我们在**首次见到该键**时写入默认折叠清单(插件市场 / 上下文洞察 / 任务看板), + * 让左栏只留常用入口;用户之后手动 pin / unpin 的选择不再被覆盖。 + * `plugins`(宿主内置的插件管理入口)是固定项,不可折叠。 + */ +const PANEL_PIN_KEY = 'dsh-desktop.sidebar.panel-pins' +const DEFAULT_COLLAPSED_PANELS = ['dsh-market', 'dsh-context', 'task-board', 'forge-review'] +const PANEL_PIN_MARK_KEY = 'dsh-apes-sidebar:collapsed-defaults' + +/** + * 写入默认折叠清单(仅当用户从未做过 pin 选择、或默认集合升级时补齐缺项)。 + * + * 宿主的 pin store 在它自己的模块初始化时读取该键,我们的 bundle 加载更晚, + * 因此写入后刷新一次页面让折叠生效;标记键记录我们已写过的默认集合, + * 之后用户手动 pin / unpin 的结果不再被改动。 + */ +function ensureDefaultCollapsedPanels(): void { + if (typeof localStorage === 'undefined') return + try { + const mark = localStorage.getItem(PANEL_PIN_MARK_KEY) + if (mark === DEFAULT_COLLAPSED_PANELS.join(',')) return + const raw = localStorage.getItem(PANEL_PIN_KEY) + const current = raw === null ? [] : (JSON.parse(raw)?.unpinned ?? []) + if (!Array.isArray(current)) return + // 只补齐缺项:用户手动 pin 回来的入口,若不在默认集合里则保持不变。 + const merged = [...current] + for (const id of DEFAULT_COLLAPSED_PANELS) if (!merged.includes(id)) merged.push(id) + localStorage.setItem(PANEL_PIN_KEY, JSON.stringify({ unpinned: merged })) + localStorage.setItem(PANEL_PIN_MARK_KEY, DEFAULT_COLLAPSED_PANELS.join(',')) + console.info('[dsh-apes-sidebar] 已写入默认折叠的侧栏入口,刷新后生效') + location.reload() + } catch { + // 存储不可用(隐私模式 / 配额满)时保持宿主默认,不阻断插件装载。 + } +} + /** * Client plugin body. * @param ctx - the client cordis context (slots, sessions). */ export function apply(ctx: Context): void { + ensureDefaultCollapsedPanels() // The sidebar follows the DSH i18n system: attach the locale service so // the module-level t()/isZh() resolve the Host-backed language preference // (and switch live — the Sidebar root subscribes to it), and register the