feat(sidebar): 桌面兼容三方案——自动检测(WCO 标准几何)/壳预设/自定义 CSS (#284)

* feat(sidebar): 桌面兼容三方案——自动检测(WCO 标准几何)/壳预设/自定义 CSS

核心只保留 Web 标准机制,壳专属适配全部下沉到用户空间(KISS):
- prefs 新增 titleBarScheme(默认 auto)/titleBarPresetId/customCss,旧 titleBarCompat
  布尔自动迁移(true→custom 保留 stripPx,false/缺失→auto)
- wco.ts:navigator.windowControlsOverlay 反应式几何(geometrychange 实时更新;
  visible=false 的幽灵 API 视为缺失),实现 #257
- titlebar-strip.ts 唯一 strip 取值链:WCO → dsh-desktop-titlebar-inset 契约参数
  → 预设 stripFor → 手动 px → 0;desktop-env.ts 移除 win32 32px 硬编码
- shell-presets.ts 数据驱动预设(准入:issue/PR 提及 + 100+ star;v1 仅
  anywhere-labs DSH Desktop:darwin 20px / win32 无 WCO 时 32px),opt-in 手动
- 预设/自定义 CSS 注入(data-dsh-preset-css / data-dsh-custom-css 标签),
  chrome 补稳定寻址面 data-dsh-toggle-cluster / data-dsh-panel
- 交互 chrome 统一 -webkit-app-region: no-drag(吸收 #111/#153)
- layout.css 底栏推挤复合锚点([data-pane] 与 :has(> [data-slot]) 双保险,
  rc.8 实测前者失效、后者命中,吸收 #226 思路)
- 设置 UI:位置兼容模式齿轮弹窗改三方案(自动检测/壳兼容方案/自定义方案)
- 测试:wco/titlebar-strip/shell-presets 单测 + prefs 迁移 + e2e 5 场景
  (保守 auto/WCO 反应式/预设/自定义 CSS/复合锚点),挂载门禁 12/12 全绿

核心 grep 无壳专属类名;为某壳做的兼容在另一壳会再坏——预设与自定义 CSS
是唯一出路(AGENTS.md §8 契约已更新)。

* refine(sidebar): 位置兼容模式改主行下拉四选项——自动检测/DSH官方Web/壳预设/自定义

按用户反馈定稿 UI:
- 主行下拉:自动检测(默认)/ DSH官方Web(显式零适配,连 WCO 也强制 0)/
  各壳预设(命中环境带「已检测」后缀,仅提示)/ 自定义方案(保留齿轮弹窗:
  下移距离 + 自定义 CSS)
- 旧文档迁移:titleBarCompat=true 或 titleBarStripPx 非默认值(此前已有配置)
  → 默认落到 custom 方案保留用户数值;干净文档 → auto
- prefs 新增 'web' 方案;strip 取值链最优先处理 web→0
- 测试:prefs 迁移(stripPx 48→custom / 40→auto)、web 强制 0、下拉渲染断言
- 单测 693 通过,挂载 e2e 12/12 全绿

* refine(sidebar): 方案下拉复用 SelectMenu 组件,不用原生 <select>

- 抽出可复用 SelectMenu(primitives Menu:锚点按钮 + 下拉选项卡,支持
  icon/desc/多选),SelectRow 改为其薄壳
- 位置兼容模式方案下拉改用 SelectMenu;选项带描述(自动检测/DSH官方Web/
  各壳预设(命中带「已检测」后缀)/自定义方案)
- 移除原生 select 样式;单测 693 通过,挂载 e2e 12/12 全绿
This commit is contained in:
Atlas Zeng
2026-08-21 01:28:17 +08:00
committed by GitHub
parent 4e52923970
commit 50a888845f
26 changed files with 1312 additions and 181 deletions
+83
View File
@@ -0,0 +1,83 @@
/**
* Built-in desktop-shell presets for the "位置兼容模式" secondary setting
* (scheme `preset`). DATA-DRIVEN by design: each shell's adaptation lives
* in one entry (strip values / optional CSS), the core applies it through
* the SAME generic strip variable and CSS-injection mechanism — adding a
* shell is adding data, never a code path.
*
* Inclusion rule (maintained in AGENTS.md §8): only shells that (a) appear
* in this repo's issues/PRs (a user actually hit a problem) and (b) have
* 100+ GitHub stars (a real user base). The mechanism is opt-in: auto
* detection never applies a preset — the settings badge only SUGGESTS it.
*/
import type { DesktopEnv } from './desktop-env.ts'
export interface ShellPreset {
/** Stable preset id (persisted in `titleBarPresetId`). */
readonly id: string
/** User-facing name of the shell. */
readonly title: string
/** One-line description shown in the settings popup. */
readonly desc: string
/**
* The top strip (px) this shell reserves over web content, per
* environment — the fallback used when neither the standard WCO API nor
* the `dsh-desktop-titlebar-inset` contract parameter is available.
* Return undefined when the shell needs no strip in that environment.
* MUST be pure (called during render).
*/
readonly stripFor?: (env: DesktopEnv) => number | undefined
/**
* Extra CSS applied while the preset is enabled (injected last, after the
* plugin's own styles). Targets the plugin's stable data attributes and
* shell-declared body/URL markers only — never other shells' class names.
* Empty for presets fully covered by the strip variable.
*/
readonly css?: string
/**
* Whether this shell's marker is currently visible (URL stamps / preload
* markers — see desktop-env.ts). Used ONLY for the settings "已检测"
* badge; never auto-applies anything. MUST be pure.
*/
readonly detect?: (env: DesktopEnv) => boolean
}
/**
* DeepSeek Harness Desktop (anywhere-labs, Electron, 16k+ stars — the most
* reported shell in this repo's issues/PRs). Advanced mode: macOS reserves
* a 20px caption row (traffic lights top-left), win32 draws the native
* window controls in a ~32px overlay (WCO reports the real height when
* available, which the auto scheme already consumes; the 32 is the
* no-WCO fallback). Compatibility mode keeps the native frame — nothing.
*/
const DSH_DESKTOP: ShellPreset = {
id: 'dsh-desktop',
title: 'DeepSeek Harness Desktop',
desc: 'Electron 高级模式(无边框):macOS 顶栏 20px、Windows 无 WCO 时 32px 标题栏让位',
stripFor: (env) => {
if (env.mode !== 'advanced') return undefined
if (env.platform === 'darwin') return 20
if (env.platform === 'win32') return 32
return undefined
},
detect: (env) => env.mode === 'advanced',
}
const PRESETS: readonly ShellPreset[] = [
DSH_DESKTOP,
]
/** All built-in shell presets (registration order = settings list order). */
export function getShellPresets(): readonly ShellPreset[] {
return PRESETS
}
/** One preset by id, or undefined for an unknown/empty id. */
export function getShellPreset(id: string): ShellPreset | undefined {
return PRESETS.find(preset => preset.id === id)
}
/** The strip the active preset contributes for the given environment. */
export function presetStripFor(preset: ShellPreset | undefined, env: DesktopEnv): number | undefined {
return preset?.stripFor?.(env)
}