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
@@ -1071,9 +1071,9 @@ interface SettingsDescriptor {
|
||||
- **根锚点**:宿主 div 带 `data-dsh-better-sidebar`(append 到 body);其内**面板宿主层** `[data-dsh-panel-host]`(`fixed; inset:0; z-25; pointer-events:none; overflow:hidden+clip`,v0.13.1+),面板/开关簇 absolute 定位,免疫中间层 transform 劫持;页面级 transform 触发 `data-dsh-panel-host-degraded` 降级。`overflow` 级联是**契约**(`hidden` 兜底 + `clip` 收尾,`tests/panel-host-css.spec.ts` 守护):`hidden` 盒子仍是滚动容器,脚本滚动或浏览器 scroll-into-view 修正(焦点移入视口外区域、嵌套 iframe/工作台加载时抢焦点、面板滑出动画中 focus() 落点)会沿最近可滚祖先滚走整层——面板与开关簇集体偏离视口角(computed left/right 仍"正确",偏移藏在盒子自身 scroll offset 里);`clip` 裁剪语义相同但不产生滚动盒,任何路径都滚不动这层。皮肤作用域覆盖限定在 `[data-dsh-better-sidebar]` 内。
|
||||
- **布局变量**(`<html>` 上,面板打开时有效):`--dsh-sidebar-width` / `--dsh-sidebar-height`。右面板宽度 = AppFrame 的 `padding-right` 预留(新版 `#root [data-dsh-frame]` / rc.8 `#root > [data-slot="root"] > div` 双锚点),AppFrame border box 保持完整桌面视口宽度(Harness 以此判定桌面/窄屏布局,避免插件面板展开误入窄屏);AppFrame 的 details 拖拽手柄按同一变量向左平移贴合列边缘。底部面板仍走 centerCol `margin-bottom`;centerCol 锚点 = **JS 标注**(禁止 `nth-child`):侧栏 shell 的定位器给测得的 centerCol 节点打 `[data-dsh-center-col]` 标签(`Sidebar.tsx` locate,节点更换/HMR 时随 ref 迁移),`layout.css` 用 `#root [data-dsh-center-col]` 选中(`drag-layout.e2e.ts` 断言恰一节点且为对话槽宿主的父级——alpha.2 起 shell 把 `#root [data-slot="main.conversation"]` 解析进列并跳过 `display: contents` 祖先(`center-column.ts` 的 `CENTER_COLUMN_SELECTOR` 同时认 `main.conversation` 与 alpha.1 的 `conversation`),定位器从槽宿主向上取第一个非 `contents` 的祖先;frame 宽度与桌面 Session Log 由 `desktop-layout.e2e.ts` 断言)。
|
||||
- **桌面信号与标题栏**(v0.14.1+ 四方案模型 `SidebarPrefs.titleBarScheme`,唯一决策点 `src/client/titlebar-strip.ts` 纯函数):
|
||||
- 壳信号(只读,不自动触发修改):URL `dsh-desktop-mode` / `dsh-desktop-platform` / 可选 `dsh-desktop-titlebar-inset`(0–120 clamp)。
|
||||
- **strip 取值链**:⓪ `web` 方案强制 0;① `navigator.windowControlsOverlay` 真实几何(`wco.ts` 订阅 `geometrychange`,**为 0 也权威**,`visible=false` 幽灵 API 视为缺失);② URL inset;③ 壳预设 `stripFor`(仅 `preset`);④ 手动 `titleBarStripPx`(仅 `custom`);⑤ 0。驱动 `body[data-dsh-title-bar-compat]` + `--dsh-title-bar-strip`。
|
||||
- **四方案**:`auto`(默认,只信 WCO——"为某壳做的兼容在另一个壳会再坏",核心不做壳专属分支)/ `web`(强制 0)/ `preset`(`src/client/shell-presets.ts`,准入:issue/PR 提及且 GitHub ⭐>100;命中环境显示「已检测」后缀,绝不自动启用)/ `custom`(用户 CSS + 手动 px,齿轮弹窗)。
|
||||
- 壳信号(只读,不自动触发修改):URL `dsh-desktop-mode`(`compatibility` / `extended` / `advanced`)/ `dsh-desktop-platform` / 可选 `dsh-desktop-titlebar-inset`(0–120 clamp);官方 Electron 壳还会提供**客户端服务** `ctx.desktopWindow`(`mode` / `platform` / `material` / `safeAreaInsets` / `dragRegion`,见 anywhere-labs/dsh-desktop 的 `plugin-services` 文档)。插件侧以结构化镜像探测它(`src/context-types.ts` 的 `SidebarDesktopWindowService` + `src/client/desktop-env.ts` 的 `probeDesktopWindow`),**绝不写进 `dsh.client.inject`**——普通浏览器没有该服务,注入它会让整个插件 pending。
|
||||
- **strip 取值链**:⓪ `web` 方案强制 0;① **壳自带窗口契约**(`ctx.desktopWindow` 存在时以 `safeAreaInsets.top` 为权威:compatibility / extended 报 0——壳已把整个页面放在自己的 36px frame 之下,插件**不得**再让位一次;advanced 报它画进内容里的 caption 行高度,macOS 20 / win32 32);② `navigator.windowControlsOverlay` 真实几何(`wco.ts` 订阅 `geometrychange`,**为 0 也权威**,`visible=false` 幽灵 API 视为缺失);③ URL inset(**只在壳没提供上面的服务时生效**,即旧壳);④ 壳预设 `stripFor`(仅 `preset`);⑤ 手动 `titleBarStripPx`(仅 `custom`);⑥ 0。驱动 `body[data-dsh-title-bar-compat]` + `--dsh-title-bar-strip`。
|
||||
- **四方案**:`auto`(默认,保守:壳提供了 `ctx.desktopWindow` 就用壳的真实几何,否则只信 WCO——"为某壳做的兼容在另一个壳会再坏",核心不做壳专属分支)/ `web`(强制 0)/ `preset`(`src/client/shell-presets.ts`,准入:issue/PR 提及且 GitHub ⭐>100;命中环境显示「已检测」后缀,绝不自动启用)/ `custom`(用户 CSS + 手动 px,齿轮弹窗)。
|
||||
- **迁移**:`titleBarScheme` 无默认值;旧文档已有值(`titleBarCompat === true` 或 `titleBarStripPx` 非 40)→ 迁 `custom`;干净文档 → `auto`。
|
||||
- **用户空间 CSS**:预设/自定义 css 注入 `<style data-dsh-preset-css|data-dsh-custom-css>` 到 head 末尾(后写胜出;覆盖 JS 内联需 `!important`),fiber 卸载即移除。稳定寻址面:`[data-dsh-toggle-cluster]` / `[data-dsh-panel]` / `[data-dsh-bottom-panel]`。
|
||||
- **拖拽区退出**:交互 chrome(`.toggleCluster` / `.toggleButton` / `.tabBar`)统一 `-webkit-app-region: no-drag`(无边框壳拖拽带吞点击,#103/#111)。
|
||||
|
||||
@@ -34,7 +34,7 @@ better-sidebar 的桌面端适配历史上是"每壳一条补丁":右上角开
|
||||
### 标准件(`src/client/wco.ts` + `src/client/titlebar-strip.ts`)
|
||||
|
||||
- `wco.ts`:模块级反应式 store(subscribe/getSnapshot,`useSyncExternalStore` 消费),特性检测 `navigator.windowControlsOverlay`,订阅 `geometrychange` 重读矩形(最大化/还原实时更新);最后订阅者退订时解绑原生监听;`setWcoSourceForTests` 注入测试源。API 抛错视为 present+0(绝不崩布局)。
|
||||
- `titlebar-strip.ts`(唯一决策点,纯函数):**⓪ `web` 方案强制 0 → ① WCO 真实高度(权威,0 也权威;`visible=false` 幽灵 API 视为缺失)→ ② URL `dsh-desktop-titlebar-inset`(0–120 clamp)→ ③ 预设 `stripFor`(仅 preset 方案)→ ④ 手动 `titleBarStripPx`(仅 custom 方案)→ ⑤ 0**。结果驱动 `body[data-dsh-title-bar-compat]` + `--dsh-title-bar-strip`(CSS 契约不变)。
|
||||
- `titlebar-strip.ts`(唯一决策点,纯函数):**⓪ `web` 方案强制 0 → ① WCO 真实高度(权威,0 也权威;`visible=false` 幽灵 API 视为缺失)→ ② URL `dsh-desktop-titlebar-inset`(0–120 clamp)→ ③ 预设 `stripFor`(仅 preset 方案)→ ④ 手动 `titleBarStripPx`(仅 custom 方案)→ ⑤ 0**。结果驱动 `body[data-dsh-title-bar-compat]` + `--dsh-title-bar-strip`(CSS 契约不变)。(2026-10-05 起 ⓪ 与 ① 之间插入「壳自带窗口契约」,见文末实施偏差记录。)
|
||||
- `desktop-env.ts`:只做环境报告(desktop/mode/platform/titlebarInset),SSR 安全;移除旧 `win32OverlayTop` 硬编码。
|
||||
|
||||
### 预设与用户 CSS(`src/client/shell-presets.ts` + `Sidebar.tsx` effect)
|
||||
@@ -71,6 +71,7 @@ better-sidebar 的桌面端适配历史上是"每壳一条补丁":右上角开
|
||||
## 实施偏差记录
|
||||
|
||||
- 无。计划与实施一致;仅补充:schema 新字段必须无 default 才能让旧文档迁移(否则 settings 服务会把 default 填进解析结果、吞掉迁移),`plugin-shape.spec.ts` 断言了这一点。
|
||||
- **2026-10-05(issue #864,分支 `fix/864-desktop-window-contract`)**:取值链在 ⓪ 与 ① 之间插入**壳自带窗口契约**——官方 Electron 壳(DSH Desktop 2.x)通过客户端服务 `ctx.desktopWindow` 公布 `safeAreaInsets.top`,插件以结构化镜像探测(`src/context-types.ts` 的 `SidebarDesktopWindowService`、`src/client/desktop-env.ts` 的 `probeDesktopWindow`),**不写进 `dsh.client.inject`**(普通浏览器没有该服务,注入会让插件永远 pending)。壳存在时该值权威:compatibility / extended 报 0(壳已把整个页面放在自己的 36px frame 之下),advanced 报它画进内容的 caption 行(macOS 20 / win32 32);壳不存在时 ②–⑤ 原样保留。`desktop-env.ts` 的 mode 同时接受第三种取值 `extended`(与 compatibility 同几何的独立 frame,**不套用 advanced 的预设顶部值**)。
|
||||
|
||||
## 存量 PR/issue 处置(合并后执行,均含哲学声明)
|
||||
|
||||
|
||||
+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
|
||||
|
||||
@@ -626,6 +626,51 @@ export interface SidebarConversation {
|
||||
}
|
||||
}
|
||||
|
||||
/** Insets (CSS px) the desktop shell reserved for its own native chrome. */
|
||||
export interface SidebarDesktopWindowInsets {
|
||||
readonly top: number
|
||||
readonly right: number
|
||||
readonly bottom: number
|
||||
readonly left: number
|
||||
}
|
||||
|
||||
/** The shell's top caption hit-region (drag band + excluded native controls). */
|
||||
export interface SidebarDesktopWindowDragRegion {
|
||||
readonly height: number
|
||||
readonly leftInset: number
|
||||
readonly rightInset: number
|
||||
}
|
||||
|
||||
/**
|
||||
* The desktop shell's native-window geometry contract (`ctx.desktopWindow`,
|
||||
* a CLIENT cordis service of the official Electron shell; see its
|
||||
* docs/plugin-services). Mirrored structurally — like every other service
|
||||
* face here — because the plugin must not value-import `dsh-plugin-desktop`
|
||||
* (and the package is dev-time absent anyway).
|
||||
*
|
||||
* The service is OPTIONAL: a plain browser never provides it, so it is
|
||||
* probed through {@link ./client/desktop-env.ts} rather than listed in
|
||||
* `dsh.client.inject` (a missing inject dependency would keep the whole
|
||||
* client plugin pending forever). Only `safeAreaInsets.top` is consumed
|
||||
* today (the strip the sidebar yields at the top); the remaining fields are
|
||||
* mirrored to keep the contract legible at the probe site.
|
||||
*/
|
||||
export interface SidebarDesktopWindowService {
|
||||
/**
|
||||
* `compatibility` / `extended` = the shell owns a frame ABOVE the content
|
||||
* (both report a zero content inset); `advanced` = a compact caption row
|
||||
* is drawn INTO the content (as of upstream master both darwin and win32 report 32; Linux 0 — always trust the shell's reported value).
|
||||
*/
|
||||
readonly mode: 'compatibility' | 'extended' | 'advanced'
|
||||
readonly platform: 'darwin' | 'win32' | 'linux'
|
||||
/** Capability-gated native material behind the renderer. */
|
||||
readonly material: 'off' | 'transparent'
|
||||
/** Where the shell starts placing the upstream content surface. */
|
||||
readonly safeAreaInsets: SidebarDesktopWindowInsets
|
||||
/** Native caption hit region; interactive children must opt out of dragging. */
|
||||
readonly dragRegion: SidebarDesktopWindowDragRegion
|
||||
}
|
||||
|
||||
/** Read-only subset of api-workspace-controller's public IWorkspaces.list. */
|
||||
export interface SidebarWorkspacesService {
|
||||
readonly list: {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
/**
|
||||
* Desktop-shell detection tests: URL stamps (dsh-desktop-mode/platform)
|
||||
* from the official Electron shell, the preload marker
|
||||
* (__DSH_DESKTOP_FILE_PATH__), and the `dsh-desktop-titlebar-inset`
|
||||
* contract parameter. Geometry ADAPTATION is deliberately NOT here — the
|
||||
* strip resolution chain lives in titlebar-strip.ts (standard WCO first,
|
||||
* see wco.spec.ts), keeping this module a pure environment reporter.
|
||||
* (__DSH_DESKTOP_FILE_PATH__), the `dsh-desktop-titlebar-inset` contract
|
||||
* parameter, and the shell's own window service probe
|
||||
* (`ctx.desktopWindow` — see titlebar-strip.spec.ts for how the chain
|
||||
* consumes it). Geometry ADAPTATION is deliberately NOT here — the strip
|
||||
* resolution chain lives in titlebar-strip.ts (standard WCO first, see
|
||||
* wco.spec.ts), keeping this module a pure environment reporter.
|
||||
*/
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import './browser-globals.ts'
|
||||
import { parseDesktopEnv, resetDesktopEnvForTests } from '../src/client/desktop-env.ts'
|
||||
import { parseDesktopEnv, probeDesktopWindow, resetDesktopEnvForTests } from '../src/client/desktop-env.ts'
|
||||
import type { Context, SidebarDesktopWindowService } from '../src/context-types.ts'
|
||||
|
||||
function setSearch(search: string): void {
|
||||
;(window.location as { search: string }).search = search
|
||||
@@ -50,6 +53,21 @@ describe('parseDesktopEnv', () => {
|
||||
expect(env.titlebarInset).toBe(0)
|
||||
})
|
||||
|
||||
it('parses extended mode — the shell-owned 36px frame with compatibility geometry', () => {
|
||||
// Extended window (DSH Desktop 2.x): the shell hosts the upstream
|
||||
// surfaces below its OWN frame, exactly like compatibility — the mode is
|
||||
// not an unknown value, and must not be read as `advanced` (whose preset
|
||||
// strip would reserve the caption row a second time).
|
||||
setSearch('?dsh-desktop-mode=extended&dsh-desktop-platform=darwin&dsh-desktop-titlebar-inset=36')
|
||||
const env = parseDesktopEnv()
|
||||
expect(env.desktop).toBe(true)
|
||||
expect(env.mode).toBe('extended')
|
||||
expect(env.platform).toBe('darwin')
|
||||
// The stamp is still REPORTED verbatim: it is the shell's own reserve
|
||||
// (the strip chain ignores it only because the window service exists).
|
||||
expect(env.titlebarInset).toBe(36)
|
||||
})
|
||||
|
||||
it('detects the desktop preload marker even without URL stamps', () => {
|
||||
;(window as unknown as Record<string, unknown>).__DSH_DESKTOP_FILE_PATH__ = { getPathForFile: () => '' }
|
||||
const env = parseDesktopEnv()
|
||||
@@ -87,3 +105,41 @@ describe('parseDesktopEnv', () => {
|
||||
expect(parseDesktopEnv().desktop).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('probeDesktopWindow', () => {
|
||||
const service: SidebarDesktopWindowService = {
|
||||
mode: 'extended',
|
||||
platform: 'win32',
|
||||
material: 'off',
|
||||
safeAreaInsets: { top: 0, right: 0, bottom: 0, left: 0 },
|
||||
dragRegion: { height: 0, leftInset: 0, rightInset: 0 },
|
||||
}
|
||||
|
||||
/** A client context whose `get` answers one service name. */
|
||||
const ctxWith = (name: string, value: unknown): Context => ({
|
||||
get: (asked: string): unknown => asked === name ? value : undefined,
|
||||
}) as unknown as Context
|
||||
|
||||
it('returns the shell service the client context publishes', () => {
|
||||
expect(probeDesktopWindow(ctxWith('desktopWindow', service))).toBe(service)
|
||||
})
|
||||
|
||||
it('returns undefined on a plain browser page (the service is never injected)', () => {
|
||||
expect(probeDesktopWindow(ctxWith('desktopWindow', undefined))).toBeUndefined()
|
||||
expect(probeDesktopWindow({} as Context)).toBeUndefined()
|
||||
})
|
||||
|
||||
it('stays best-effort when the context getter throws', () => {
|
||||
const ctx: Context = {
|
||||
get: (): never => { throw new Error('cannot get property without inject') },
|
||||
} as unknown as Context
|
||||
const logged = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
try {
|
||||
expect(probeDesktopWindow(ctx)).toBeUndefined()
|
||||
// Assert inside the spy's lifetime: mockRestore also clears the calls.
|
||||
expect(logged).toHaveBeenCalledTimes(1)
|
||||
} finally {
|
||||
logged.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* The desktop shell's window contract must reach the DOM, not just the pure
|
||||
* chain (issue #430).
|
||||
*
|
||||
* `computeTitleBarStrip` is covered field by field in titlebar-strip.spec.ts;
|
||||
* what this file adds is the WIRING, which is where the regression actually
|
||||
* lived: the shell places the whole page below its own 36px frame and
|
||||
* publishes `safeAreaInsets.top = 0` through `ctx.desktopWindow`, yet still
|
||||
* stamps the render URL with `dsh-desktop-titlebar-inset=36`. If the Sidebar
|
||||
* never hands the service to the chain, that stamp wins and every panel gets
|
||||
* a second 36px blank strip at the top (`body[data-dsh-title-bar-compat]` +
|
||||
* `--dsh-title-bar-strip: 36px`).
|
||||
*
|
||||
* Rendered with the REAL Sidebar + real store/service against a minimal fake
|
||||
* context (the repo's jsdom mount pattern), so the assertion is on the
|
||||
* document state the CSS actually consumes.
|
||||
*/
|
||||
// @vitest-environment jsdom
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createElement } from 'react'
|
||||
import { createRoot, type Root } from 'react-dom/client'
|
||||
import { act } from 'react-dom/test-utils'
|
||||
import { setupReactAct } from './test-utils.ts'
|
||||
setupReactAct()
|
||||
|
||||
import { Sidebar } from '../src/client/Sidebar.tsx'
|
||||
import { createSidebarStore } from '../src/client/state.ts'
|
||||
import { createBetterSidebarService } from '../src/client/service.ts'
|
||||
import { resetDesktopEnvForTests } from '../src/client/desktop-env.ts'
|
||||
import type { Context, SidebarDesktopWindowService } from '../src/context-types.ts'
|
||||
|
||||
const shell = (mode: SidebarDesktopWindowService['mode'], top: number): SidebarDesktopWindowService => ({
|
||||
mode,
|
||||
platform: 'win32',
|
||||
material: 'off',
|
||||
safeAreaInsets: { top, right: 0, bottom: 0, left: 0 },
|
||||
dragRegion: { height: top, leftInset: 0, rightInset: 0 },
|
||||
})
|
||||
|
||||
/**
|
||||
* Mount the real sidebar on a desktop-shell URL.
|
||||
* @param search - the render URL's query (the shell's own stamps).
|
||||
* @param desktopWindow - the service `ctx.get('desktopWindow')` answers, or
|
||||
* undefined for a shell that does not publish one.
|
||||
*/
|
||||
function mount(search: string, desktopWindow: SidebarDesktopWindowService | undefined): { unmount: () => void } {
|
||||
window.history.replaceState({}, '', `/${search}`)
|
||||
resetDesktopEnvForTests()
|
||||
// jsdom has no WebSocket; the panel's host feeds construct one on mount.
|
||||
vi.stubGlobal('WebSocket', class { close(): void {} })
|
||||
const store = createSidebarStore()
|
||||
store.setSession('s1')
|
||||
const service = createBetterSidebarService(store)
|
||||
// useSyncExternalStore requires STABLE snapshots across calls (the real DSH
|
||||
// services return stable objects) — a fresh object per call loops forever.
|
||||
const locale = { active: 'en' }
|
||||
const sessions = { byId: { s1: { id: 's1', cwd: '/ws' } } }
|
||||
const ctx = {
|
||||
locale: { subscribe: () => () => {}, getSnapshot: () => locale },
|
||||
sessions: { list: { subscribe: () => () => {}, getSnapshot: () => sessions } },
|
||||
get: (name: string) => name === 'betterSidebar' ? service : name === 'desktopWindow' ? desktopWindow : undefined,
|
||||
}
|
||||
const container = document.createElement('div')
|
||||
document.body.append(container)
|
||||
const root: Root = createRoot(container)
|
||||
act(() => { root.render(createElement(Sidebar, { ctx: ctx as unknown as Context, store })) })
|
||||
return {
|
||||
unmount: () => {
|
||||
act(() => { root.unmount() })
|
||||
container.remove()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** The strip the plugin applied to the page, as the CSS reads it. */
|
||||
function appliedStrip(): { compat: boolean; px: string } {
|
||||
return {
|
||||
compat: document.body.hasAttribute('data-dsh-title-bar-compat'),
|
||||
px: document.documentElement.style.getPropertyValue('--dsh-title-bar-strip'),
|
||||
}
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = ''
|
||||
document.body.removeAttribute('data-dsh-title-bar-compat')
|
||||
document.documentElement.style.removeProperty('--dsh-title-bar-strip')
|
||||
vi.unstubAllGlobals()
|
||||
resetDesktopEnvForTests()
|
||||
})
|
||||
|
||||
describe('the shell window contract drives the applied strip', () => {
|
||||
it('compatibility + URL inset 36 + contract top 0 → no strip at all', () => {
|
||||
const view = mount(
|
||||
'?dsh-desktop-mode=compatibility&dsh-desktop-platform=win32&dsh-desktop-titlebar-inset=36',
|
||||
shell('compatibility', 0),
|
||||
)
|
||||
try {
|
||||
expect(appliedStrip()).toEqual({ compat: false, px: '' })
|
||||
} finally {
|
||||
view.unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('extended + URL inset 36 + contract top 0 → no strip at all', () => {
|
||||
const view = mount(
|
||||
'?dsh-desktop-mode=extended&dsh-desktop-platform=darwin&dsh-desktop-titlebar-inset=36',
|
||||
shell('extended', 0),
|
||||
)
|
||||
try {
|
||||
expect(appliedStrip()).toEqual({ compat: false, px: '' })
|
||||
} finally {
|
||||
view.unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('advanced + contract top 32 → the caption row is yielded', () => {
|
||||
const view = mount(
|
||||
'?dsh-desktop-mode=advanced&dsh-desktop-platform=win32',
|
||||
shell('advanced', 32),
|
||||
)
|
||||
try {
|
||||
expect(appliedStrip()).toEqual({ compat: true, px: '32px' })
|
||||
} finally {
|
||||
view.unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('no service (plain browser / older shell) → the URL stamp chain is unchanged', () => {
|
||||
const view = mount(
|
||||
'?dsh-desktop-mode=compatibility&dsh-desktop-platform=win32&dsh-desktop-titlebar-inset=36',
|
||||
undefined,
|
||||
)
|
||||
try {
|
||||
expect(appliedStrip()).toEqual({ compat: true, px: '36px' })
|
||||
} finally {
|
||||
view.unmount()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -2,8 +2,8 @@
|
||||
* Built-in shell-preset data tests: registry integrity (unique ids, non-empty
|
||||
* titles, non-empty localized descs, pure strip/detect functions) and the
|
||||
* anywhere-labs DSH Desktop entry's strip values (darwin advanced 20px,
|
||||
* win32 advanced 32px as the no-WCO fallback, compatibility/plain browser
|
||||
* nothing).
|
||||
* win32 advanced 32px as the no-WCO fallback, compatibility / extended /
|
||||
* plain browser nothing).
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { getShellPreset, getShellPresets, presetStripFor } from '../src/client/shell-presets.ts'
|
||||
@@ -65,6 +65,18 @@ describe('shell presets', () => {
|
||||
expect(presetStripFor(preset, env({ desktop: false, mode: null, platform: null }))).toBeUndefined()
|
||||
})
|
||||
|
||||
it('reserves nothing in EXTENDED mode either — the caption row is advanced-only', () => {
|
||||
// Extended is a third presentation mode (DSH Desktop 2.x): the shell
|
||||
// hosts the surfaces below its own 36px frame, exactly like
|
||||
// compatibility, and reports a zero content inset through
|
||||
// `ctx.desktopWindow`. Inheriting advanced's caption-row values here
|
||||
// would be the very double reservation issue #430 is about.
|
||||
expect(presetStripFor(preset, env({ desktop: true, mode: 'extended', platform: 'darwin' }))).toBeUndefined()
|
||||
expect(presetStripFor(preset, env({ desktop: true, mode: 'extended', platform: 'win32' }))).toBeUndefined()
|
||||
// ... and the settings badge must not SUGGEST the preset there either.
|
||||
expect(preset.detect?.(env({ desktop: true, mode: 'extended', platform: 'win32' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('detects advanced shells only as a SUGGESTION signal (never auto-applies)', () => {
|
||||
expect(preset.detect?.(env({ desktop: true, mode: 'advanced', platform: 'darwin' }))).toBe(true)
|
||||
expect(preset.detect?.(env({ desktop: true, mode: 'advanced', platform: 'win32' }))).toBe(true)
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
/**
|
||||
* The title-bar strip resolution chain: standard WCO geometry first
|
||||
* (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.
|
||||
* 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,
|
||||
@@ -22,6 +25,18 @@ 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)
|
||||
@@ -37,6 +52,8 @@ describe('computeTitleBarStrip', () => {
|
||||
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)', () => {
|
||||
@@ -72,4 +89,55 @@ describe('computeTitleBarStrip', () => {
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user