现象: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 档位不改变位置」的取值链优先级问题),两者不要互相关闭。
144 lines
7.7 KiB
TypeScript
144 lines
7.7 KiB
TypeScript
/**
|
|
* The title-bar strip resolution chain: the desktop shell's own window
|
|
* contract first (present → its `safeAreaInsets.top` is authoritative),
|
|
* then standard WCO geometry (authoritative even when 0), then the
|
|
* documented URL inset contract parameter, then the opt-in preset / custom
|
|
* scheme — and 0 (plain web, nothing modified) otherwise. No per-shell
|
|
* branch lives in the core.
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { computeTitleBarStrip } from '../src/client/titlebar-strip.ts'
|
|
import type { DesktopEnv } from '../src/client/desktop-env.ts'
|
|
import type { WcoSnapshot } from '../src/client/wco.ts'
|
|
import type { ShellPreset } from '../src/client/shell-presets.ts'
|
|
import type { SidebarDesktopWindowService } from '../src/context-types.ts'
|
|
|
|
const env = (partial: Partial<DesktopEnv>): DesktopEnv => ({
|
|
desktop: false,
|
|
mode: null,
|
|
platform: null,
|
|
titlebarInset: 0,
|
|
...partial,
|
|
})
|
|
|
|
const wco = (present: boolean, height = 0): WcoSnapshot => ({ present, height })
|
|
|
|
const noPreset: ShellPreset | undefined = undefined
|
|
|
|
/** One desktop-shell window contract snapshot (only the read field varies). */
|
|
const shell = (
|
|
mode: SidebarDesktopWindowService['mode'],
|
|
top: number,
|
|
): SidebarDesktopWindowService => ({
|
|
mode,
|
|
platform: mode === 'advanced' ? 'win32' : 'darwin',
|
|
material: 'off',
|
|
safeAreaInsets: { top, right: 0, bottom: 0, left: 0 },
|
|
dragRegion: { height: top, leftInset: 0, rightInset: 0 },
|
|
})
|
|
|
|
describe('computeTitleBarStrip', () => {
|
|
it('keeps plain web untouched: no WCO, no inset, no scheme → 0', () => {
|
|
expect(computeTitleBarStrip(env({}), wco(false), 'auto', noPreset, 40)).toBe(0)
|
|
expect(computeTitleBarStrip(env({}), wco(false), 'custom', noPreset, 40)).toBe(40)
|
|
})
|
|
|
|
it('the explicit WEB scheme forces 0 — not even standard WCO geometry applies', () => {
|
|
const desktop = env({ desktop: true, mode: 'advanced', platform: 'win32' })
|
|
// The user declared "DSH official web": no adaptation at all, even when
|
|
// a real overlay exists or a preset is active.
|
|
expect(computeTitleBarStrip(desktop, wco(true, 36), 'web', noPreset, 40)).toBe(0)
|
|
expect(computeTitleBarStrip(desktop, wco(false), 'web', noPreset, 40)).toBe(0)
|
|
expect(computeTitleBarStrip(desktop, wco(false), 'web', {
|
|
id: 't', title: 't', desc: '', stripFor: () => 20,
|
|
}, 40)).toBe(0)
|
|
// ... and the shell contract does not override that explicit choice.
|
|
expect(computeTitleBarStrip(desktop, wco(false), 'web', noPreset, 40, shell('advanced', 32))).toBe(0)
|
|
})
|
|
|
|
it('trusts the standard WCO geometry first in every scheme (even 0 — e.g. maximized)', () => {
|
|
const desktop = env({ desktop: true, mode: 'advanced', platform: 'win32' })
|
|
expect(computeTitleBarStrip(desktop, wco(true, 36), 'auto', noPreset, 0)).toBe(36)
|
|
expect(computeTitleBarStrip(desktop, wco(true, 36), 'preset', noPreset, 0)).toBe(36)
|
|
expect(computeTitleBarStrip(desktop, wco(true, 36), 'custom', noPreset, 40)).toBe(36)
|
|
// Authoritative zero: the overlay is hidden while maximized — no strip.
|
|
expect(computeTitleBarStrip(desktop, wco(true, 0), 'auto', noPreset, 40)).toBe(0)
|
|
})
|
|
|
|
it('applies the documented URL inset contract parameter before any scheme', () => {
|
|
const stamped = env({ desktop: true, mode: 'advanced', platform: 'darwin', titlebarInset: 20 })
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'auto', noPreset, 0)).toBe(20)
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'preset', noPreset, 0)).toBe(20)
|
|
})
|
|
|
|
it('uses the opt-in preset strip under the preset scheme only', () => {
|
|
const preset: ShellPreset = {
|
|
id: 't', title: 't', desc: '',
|
|
stripFor: (e) => e.platform === 'darwin' ? 20 : undefined,
|
|
}
|
|
const darwin = env({ desktop: true, mode: 'advanced', platform: 'darwin' })
|
|
expect(computeTitleBarStrip(darwin, wco(false), 'preset', preset, 0)).toBe(20)
|
|
// Auto never applies the preset — only standard signals.
|
|
expect(computeTitleBarStrip(darwin, wco(false), 'auto', preset, 0)).toBe(0)
|
|
// Custom never applies the preset either.
|
|
expect(computeTitleBarStrip(darwin, wco(false), 'custom', preset, 0)).toBe(0)
|
|
})
|
|
|
|
it('uses the manual strip px under the custom scheme only', () => {
|
|
expect(computeTitleBarStrip(env({}), wco(false), 'custom', noPreset, 56)).toBe(56)
|
|
expect(computeTitleBarStrip(env({}), wco(false), 'auto', noPreset, 56)).toBe(0)
|
|
expect(computeTitleBarStrip(env({}), wco(false), 'preset', noPreset, 56)).toBe(0)
|
|
})
|
|
|
|
// The desktop shell's own window contract (`ctx.desktopWindow`) — issue
|
|
// #430. The shell reserves its title bar by placing the WHOLE page below it
|
|
// (compatibility / extended) yet still publishes the
|
|
// `dsh-desktop-titlebar-inset=36` URL stamp describing that same reserve;
|
|
// reading the stamp as "pixels the page must additionally yield" left a
|
|
// second 36px blank strip at the top of every panel. `safeAreaInsets.top`
|
|
// is that reserve ALREADY APPLIED, so it outranks the stamp.
|
|
describe('the shell window contract (ctx.desktopWindow)', () => {
|
|
it('(a) compatibility / extended report a zero inset → nothing is reserved', () => {
|
|
const stamped = env({ desktop: true, mode: 'compatibility', platform: 'win32', titlebarInset: 36 })
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'auto', noPreset, 0, shell('compatibility', 0))).toBe(0)
|
|
const extended = env({ desktop: true, mode: 'extended', platform: 'win32', titlebarInset: 36 })
|
|
expect(computeTitleBarStrip(extended, wco(false), 'auto', noPreset, 0, shell('extended', 0))).toBe(0)
|
|
})
|
|
|
|
it('(b) advanced reports the caption row it draws INTO the content → that height', () => {
|
|
const advanced = env({ desktop: true, mode: 'advanced', platform: 'win32' })
|
|
expect(computeTitleBarStrip(advanced, wco(false), 'auto', noPreset, 0, shell('advanced', 32))).toBe(32)
|
|
// The value is the SHELL's, not a constant: macOS advanced reports 20.
|
|
expect(computeTitleBarStrip(advanced, wco(false), 'auto', noPreset, 0, shell('advanced', 20))).toBe(20)
|
|
})
|
|
|
|
it('(c) without the service the existing chain is untouched (older shells, plain pages)', () => {
|
|
const stamped = env({ desktop: true, mode: 'compatibility', platform: 'win32', titlebarInset: 36 })
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'auto', noPreset, 0)).toBe(36)
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'preset', noPreset, 0)).toBe(36)
|
|
})
|
|
|
|
it('(d) with the service the URL stamp is IGNORED, whatever it says', () => {
|
|
const stamped = env({ desktop: true, mode: 'extended', platform: 'darwin', titlebarInset: 36 })
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'auto', noPreset, 40, shell('extended', 0))).toBe(0)
|
|
// ... including the custom scheme's manual px, which the shell's real
|
|
// geometry outranks exactly like WCO always did.
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'custom', noPreset, 40, shell('extended', 0))).toBe(0)
|
|
// Even a present WCO overlay does not outrank the shell's own contract.
|
|
expect(computeTitleBarStrip(stamped, wco(true, 36), 'auto', noPreset, 0, shell('extended', 0))).toBe(0)
|
|
})
|
|
|
|
it('falls through to the standard chain for a service without a usable top', () => {
|
|
const stamped = env({ desktop: true, mode: 'compatibility', platform: 'win32', titlebarInset: 36 })
|
|
const broken = {
|
|
...shell('compatibility', 0),
|
|
safeAreaInsets: undefined,
|
|
} as unknown as SidebarDesktopWindowService
|
|
expect(computeTitleBarStrip(stamped, wco(false), 'auto', noPreset, 0, broken)).toBe(36)
|
|
const nan = { ...shell('compatibility', 0), safeAreaInsets: { top: Number.NaN, right: 0, bottom: 0, left: 0 } }
|
|
expect(computeTitleBarStrip(stamped, wco(true, 24), 'auto', noPreset, 0, nan)).toBe(24)
|
|
})
|
|
})
|
|
})
|
|
|