fix(desktop): 顶部保留区优先读壳的 desktopWindow 契约(#864)
现象: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 档位不改变位置」的取值链优先级问题),两者不要互相关闭。
This commit is contained in:
1 parent
38ceecb051
commit
a67779acdc
11 files changed
+443
-41
No files matched your search
+12
-6
@@ -41,7 +41,7 @@ import { IconPanelBottomOutline16 } from './icons.tsx'
|
||||
import { Workbench, type WorkbenchActions } from './split-pane.tsx'
|
||||
import { useViewportSize } from './breakpoints.ts'
|
||||
import { bottomPushHeight } from './layout-push.ts'
|
||||
import { parseDesktopEnv } from './desktop-env.ts'
|
||||
import { parseDesktopEnv, probeDesktopWindow } from './desktop-env.ts'
|
||||
import { getWcoSnapshot, subscribeWco } from './wco.ts'
|
||||
import { getShellPreset } from './shell-presets.ts'
|
||||
import { computeTitleBarStrip } from './titlebar-strip.ts'
|
||||
@@ -240,10 +240,11 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
|
||||
}, [dirtyRevision])
|
||||
|
||||
// Title-bar / shell compatibility (the "位置兼容模式" scheme):
|
||||
// auto — CONSERVATIVE: only the standard Window Controls Overlay
|
||||
// geometry contributes (the real caption-overlay height,
|
||||
// reactive to maximize/restore). No URL stamp, no preset, no
|
||||
// guess — plain browsers see zero modification.
|
||||
// auto — CONSERVATIVE: the desktop shell's own window contract when it
|
||||
// publishes one, otherwise only the standard Window Controls
|
||||
// Overlay geometry contributes (the real caption-overlay
|
||||
// height, reactive to maximize/restore). No URL stamp, no
|
||||
// preset, no guess — plain browsers see zero modification.
|
||||
// preset — an opt-in built-in shell preset (shell-presets.ts) adds its
|
||||
// per-shell strip as the no-WCO fallback.
|
||||
// custom — the user's own CSS (injected below) + the legacy manual
|
||||
@@ -254,6 +255,11 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
|
||||
// both on unmount/boundary swap so a crashed sidebar never leaves them
|
||||
// behind.
|
||||
const desktopEnv = parseDesktopEnv()
|
||||
// The shell's own geometry contract (absent on a plain browser page and on
|
||||
// shells that only stamp the URL — see desktop-env.ts). Probed per render:
|
||||
// it is a plain read of an immutable service, and the sidebar re-renders on
|
||||
// every session / prefs / viewport change anyway.
|
||||
const desktopWindow = probeDesktopWindow(ctx)
|
||||
const wco = useSyncExternalStore(
|
||||
useMemo(() => subscribeWco, []),
|
||||
getWcoSnapshot,
|
||||
@@ -261,7 +267,7 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
|
||||
const scheme = snapshot.prefs.titleBarScheme
|
||||
const preset = scheme === 'preset' ? getShellPreset(snapshot.prefs.titleBarPresetId) : undefined
|
||||
const titleBarStrip = computeTitleBarStrip(
|
||||
desktopEnv, wco, scheme, preset, snapshot.prefs.titleBarStripPx,
|
||||
desktopEnv, wco, scheme, preset, snapshot.prefs.titleBarStripPx, desktopWindow,
|
||||
)
|
||||
const titleBarCompat = titleBarStrip > 0
|
||||
useEffect(() => {
|
||||
|
||||
+62
-10
@@ -6,19 +6,33 @@
|
||||
* mid-session); `resetDesktopEnvForTests` clears the memo for unit tests.
|
||||
*
|
||||
* GEOMETRY POLICY: this module only REPORTS shell facts — it never decides
|
||||
* how to adapt. The strip height comes from standard signals first (the
|
||||
* Window Controls Overlay API, see wco.ts), then the documented contract
|
||||
* parameter `dsh-desktop-titlebar-inset` (a shell may stamp the real pixels
|
||||
* it reserves at the top), then the user's chosen scheme (preset / custom).
|
||||
* The legacy win32-advanced 32px constant is gone from the core: it lives
|
||||
* in the opt-in shell preset (shell-presets.ts) as a fallback for shells
|
||||
* without the WCO API.
|
||||
* how to adapt. The strip height comes from the shell's own window contract
|
||||
* when the shell publishes one (`ctx.desktopWindow` — see
|
||||
* {@link probeDesktopWindow}), then from standard signals (the Window
|
||||
* Controls Overlay API, see wco.ts), then the documented contract parameter
|
||||
* `dsh-desktop-titlebar-inset` (a shell may stamp the real pixels it reserves
|
||||
* at the top), then the user's chosen scheme (preset / custom). The legacy
|
||||
* win32-advanced 32px constant is gone from the core: it lives in the opt-in
|
||||
* shell preset (shell-presets.ts) as a fallback for shells without the WCO
|
||||
* API.
|
||||
*/
|
||||
import type { Context, SidebarDesktopWindowService } from '../context-types.ts'
|
||||
|
||||
/** The three presentation modes the official desktop shell documents. */
|
||||
export type DesktopMode = 'compatibility' | 'extended' | 'advanced'
|
||||
|
||||
export interface DesktopEnv {
|
||||
/** Running inside a desktop shell (any URL stamp or preload marker). */
|
||||
readonly desktop: boolean
|
||||
/** `advanced` = frameless/custom-titlebar shell; `compatibility` = native frame. */
|
||||
readonly mode: 'compatibility' | 'advanced' | null
|
||||
/**
|
||||
* `advanced` = the shell draws a compact caption row INTO the web content
|
||||
* (so the page itself has to yield those pixels);
|
||||
* `compatibility` / `extended` = the shell keeps a native/framed title bar
|
||||
* ABOVE the content (compatibility ships the complete upstream frame below
|
||||
* it, extended hosts the same surfaces itself) — both report a zero content
|
||||
* inset, i.e. the page starts below chrome the shell already owns.
|
||||
*/
|
||||
readonly mode: DesktopMode | null
|
||||
/** Shell platform stamp ('darwin' | 'win32' | …), lowercased, or null. */
|
||||
readonly platform: string | null
|
||||
/**
|
||||
@@ -45,7 +59,9 @@ export function parseDesktopEnv(): DesktopEnv {
|
||||
? new URLSearchParams(window.location.search.replace(/^\?/, ''))
|
||||
: new URLSearchParams()
|
||||
const modeParam = params.get('dsh-desktop-mode')
|
||||
const mode = modeParam === 'compatibility' || modeParam === 'advanced' ? modeParam : null
|
||||
const mode = modeParam === 'compatibility' || modeParam === 'extended' || modeParam === 'advanced'
|
||||
? modeParam
|
||||
: null
|
||||
const platformParam = params.get('dsh-desktop-platform')
|
||||
const platform = platformParam !== null && platformParam !== '' ? platformParam.toLowerCase() : null
|
||||
const desktop = mode !== null || hasPreloadMarker
|
||||
@@ -66,6 +82,42 @@ function parseTitlebarInset(raw: string | null): number {
|
||||
return Math.min(120, Math.max(0, Math.round(parsed)))
|
||||
}
|
||||
|
||||
/**
|
||||
* The desktop shell's own window contract (`ctx.desktopWindow`, a CLIENT
|
||||
* cordis service provided by the official Electron shell — see
|
||||
* docs/plugin-services of anywhere-labs/dsh-desktop), or undefined on a
|
||||
* plain browser page.
|
||||
*
|
||||
* This is the authority the whole geometry question belongs to: the shell
|
||||
* reports where IT starts placing the upstream content surface, so a shell
|
||||
* that already moved the page below its own title bar reports
|
||||
* `safeAreaInsets.top = 0` there and must NOT be compensated again by the
|
||||
* plugin's strip (which is what the `dsh-desktop-titlebar-inset` URL stamp
|
||||
* used to cause — a second 36px of blank space, issue #864).
|
||||
*
|
||||
* PROBED, never injected: `dsh.client.inject` treats a missing service as
|
||||
* "keep this plugin pending", and a plain browser never provides this one —
|
||||
* listing it would stop the whole plugin from ever mounting. Read at CALL
|
||||
* time rather than memoized like the URL stamps above: the service is
|
||||
* published by the shell's own client plugin fiber, so it can legitimately
|
||||
* be absent on the first read and present later.
|
||||
*
|
||||
* @param ctx - client context (any context without a `get` face — a minimal
|
||||
* test double — resolves to undefined).
|
||||
* @returns the shell's window service, or undefined when there is none.
|
||||
*/
|
||||
export function probeDesktopWindow(ctx: Context): SidebarDesktopWindowService | undefined {
|
||||
try {
|
||||
if (typeof ctx.get !== 'function') return undefined
|
||||
return ctx.get('desktopWindow') as SidebarDesktopWindowService | undefined
|
||||
} catch (error) {
|
||||
// Probing is best-effort by contract: an incompatible host leaves the
|
||||
// caller on the standard-signal chain instead of crashing the render.
|
||||
console.error('[dsh-better-sidebar] desktop-window probe failed', error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute base for the plugin's own host transports — the HTTP routes
|
||||
* (`/sidebar/api/*`, `/sidebar/file`, `/sidebar/bundle/*`, …) and the
|
||||
|
||||
@@ -24,8 +24,9 @@ export interface ShellPreset {
|
||||
readonly desc: string | (() => 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.
|
||||
* 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).
|
||||
*/
|
||||
@@ -51,13 +52,19 @@ export interface ShellPreset {
|
||||
* 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.
|
||||
* 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
|
||||
|
||||
@@ -5,13 +5,20 @@
|
||||
*
|
||||
* 0. `web` scheme — EXPLICIT "DSH official web": never adapt, not even
|
||||
* standard WCO geometry (the user declares the plain web UI).
|
||||
* 1. Window Controls Overlay real geometry (standard API, authoritative
|
||||
* 1. The desktop shell's own window contract (`ctx.desktopWindow`, see
|
||||
* desktop-env.ts) — authoritative when present: `safeAreaInsets.top` is
|
||||
* where the SHELL starts placing the content, so it already accounts for
|
||||
* everything the shell reserved. This is what keeps a shell that moved
|
||||
* the page below its own title bar (compatibility / extended, inset 0)
|
||||
* from being compensated a second time by the URL stamp below.
|
||||
* 2. Window Controls Overlay real geometry (standard API, authoritative
|
||||
* when present — even 0, e.g. the overlay is hidden while maximized).
|
||||
* 2. The `dsh-desktop-titlebar-inset` URL contract parameter (a shell
|
||||
* declares the exact pixels it reserves).
|
||||
* 3. The active shell preset's strip (scheme `preset` — opt-in data).
|
||||
* 4. The legacy manual `titleBarStripPx` (scheme `custom`).
|
||||
* 5. 0 — plain-browser semantics, nothing modified.
|
||||
* 3. The `dsh-desktop-titlebar-inset` URL contract parameter (a shell
|
||||
* declares the exact pixels it reserves) — only for shells old enough
|
||||
* not to publish the service above.
|
||||
* 4. The active shell preset's strip (scheme `preset` — opt-in data).
|
||||
* 5. The legacy manual `titleBarStripPx` (scheme `custom`).
|
||||
* 6. 0 — plain-browser semantics, nothing modified.
|
||||
*
|
||||
* The result drives `--dsh-title-bar-strip` + `body[data-dsh-title-bar-compat]`
|
||||
* exactly like the legacy boolean did; only the VALUE source changed.
|
||||
@@ -19,6 +26,7 @@
|
||||
import type { DesktopEnv } from './desktop-env.ts'
|
||||
import type { TitleBarScheme } from '../prefs-shared.ts'
|
||||
import type { WcoSnapshot } from './wco.ts'
|
||||
import type { SidebarDesktopWindowService } from '../context-types.ts'
|
||||
import { presetStripFor, type ShellPreset } from './shell-presets.ts'
|
||||
|
||||
export function computeTitleBarStrip(
|
||||
@@ -27,8 +35,16 @@ export function computeTitleBarStrip(
|
||||
scheme: TitleBarScheme,
|
||||
preset: ShellPreset | undefined,
|
||||
customStripPx: number,
|
||||
desktopWindow?: SidebarDesktopWindowService | undefined,
|
||||
): number {
|
||||
if (scheme === 'web') return 0
|
||||
// The shell's own contract outranks every signal below, including a URL
|
||||
// stamp the shell itself published: the stamp is the shell's OWN reserve,
|
||||
// and the shell's `safeAreaInsets.top` is that reserve already applied.
|
||||
// A service without a usable `top` (an older/incompatible host) falls
|
||||
// through to the standard chain instead of throwing mid-render.
|
||||
const shellTop = desktopWindow?.safeAreaInsets?.top
|
||||
if (typeof shellTop === 'number' && Number.isFinite(shellTop)) return shellTop
|
||||
if (wco.present) return wco.height
|
||||
if (env.titlebarInset > 0) return env.titlebarInset
|
||||
if (scheme === 'preset') return presetStripFor(preset, env) ?? 0
|
||||
|
||||
Reference in new issue
Block a user