现象:dsh-desktop 的 compatibility / extended 模式下,壳已经把整个页面下移 36px(页面在独立
WebContentsView / 壳自有 root 里从 y=36 开始),却仍按契约在 URL 上盖
`dsh-desktop-titlebar-inset=36`;插件把这枚戳当成「页面还要再让位 36px」,于是面板顶部多一条空白。
修法:
① `desktop-env.ts`:mode 接受第三种取值 `extended`(与 compatibility 同几何的独立 36px
frame),并新增 `probeDesktopWindow(ctx)` —— 结构化探测客户端服务 `ctx.desktopWindow`
(镜像类型 `SidebarDesktopWindowService` 落在 `context-types.ts`,照 sidebar-file.ts 的
probe 约定)。**不写进 `dsh.client.inject`**:普通浏览器没有该服务,注入它会让整个插件
pending;探测按调用读(服务由壳自己的 client fiber 提供,可能后到),`get` 抛错按缺失处理。
② `computeTitleBarStrip`:取值链在 ⓪ `web` 强制 0 之后、① WCO 之前插入壳契约 —— 服务存在时
以 `safeAreaInsets.top` 为权威(compatibility / extended 报 0 → 不再预留;advanced 报它画进
内容里的 caption 行,darwin 与 win32 同为 32,以壳上报值为准)。URL 戳因此在有服务时被忽略;服务不存在时旧链路
(WCO → URL → preset/custom)逐字不变。
③ `shell-presets.ts`:复核 `env.mode !== 'advanced'` —— extended 不套用 advanced 的 preset
顶部值(guard 原样成立,补注释与用例把它钉住)。
文档:指南 §12 的壳信号与 strip 取值链、`docs/plans/2026-08-20-desktop-scheme-settings-design.md`
的实施偏差记录同步。
判别性(`git stash push -- src` 临时还原源码、保留测试后重跑):
- titlebar-strip.spec.ts:(a)/(d) 由 0 变 **36**、(b) 由 32 变 0 → 3 例红((c)「无服务 + 戳 36
→ 36」在旧代码上照旧绿,正是本次刻意不动的那段);
- desktop-window-strip.spec.tsx(挂真 Sidebar、断言页面实际状态):期望
`{compat:false, px:''}` 实得 `{compat:true, px:'36px'}` —— issue 的可见症状本身;advanced 实得
无 strip → 3 例红;
- desktop-env.spec.ts:extended 解析成 null、`probeDesktopWindow is not a function` → 4 例红
(typecheck 同时报 12 条:链只收 5 参 / `'extended'` 不在联合里);
- 还原后 34/34 绿,src diff 与还原前逐字节一致(`git diff -- src | diff - /tmp/430-src.patch`)。
全量:174 files / 1977 passed | 13 skipped(新增 14 例),typecheck 0,eslint 0。
本改动**不**解决 #430(那是「preset / custom 档位不改变位置」的取值链优先级问题),两者不要互相关闭。
94 lines
4.0 KiB
TypeScript
94 lines
4.0 KiB
TypeScript
/**
|
|
* 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 docs/external-plugin-guide.md §12): 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 { t } from './locales.ts'
|
|
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 (i18n friendly:
|
|
* string or () => string — the plain string form is the raw-text
|
|
* fallback when no dictionary key covers the preset). */
|
|
readonly desc: string | (() => string)
|
|
/**
|
|
* The top strip (px) this shell reserves over web content, per
|
|
* environment — the fallback used when neither the shell's own
|
|
* `ctx.desktopWindow` contract, nor 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 and extended modes keep the shell's own
|
|
* frame ABOVE the web content — the shell has already pushed the page below
|
|
* it (and, on shells new enough to publish `ctx.desktopWindow`, reports
|
|
* `safeAreaInsets.top = 0`), so nothing is due here: the
|
|
* `env.mode !== 'advanced'` guard below is what keeps an extended shell from
|
|
* inheriting advanced's caption-row value.
|
|
*/
|
|
const DSH_DESKTOP: ShellPreset = {
|
|
id: 'dsh-desktop',
|
|
title: 'DeepSeek Harness Desktop',
|
|
desc: () => t('presetDshDesktopDesc'),
|
|
stripFor: (env) => {
|
|
// Advanced only — compatibility / extended own the region themselves.
|
|
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)
|
|
}
|