Skip to content

fix(plugin-view): follow the app type scale in docked plugin pages - #1930

Merged
vastsa merged 4 commits into
vastsa:mainfrom
algerkong:main
Oct 28, 2026
Merged

vastsa merged 4 commits into
vastsa:mainfrom
algerkong:main

Conversation

@algerkong

Copy link
Copy Markdown
Contributor

Problem

The two bundled work-panel plugins — Browser (pi.browser) and Files
(pi.file-manager) — do not follow the app's own type size.

Both are contributes.views surfaces, so each is a separate webContents that
the host composites into the work panel. Settings → General → Appearance →
Font size only sets --font-scale on the app document (D343 / ADR 0180), and
menu Zoom In/Out/Reset only zooms the focused page. Neither reaches a docked
plugin page, so those two panels keep their author-sized 12px/13px chrome
while everything around them grows: at 125 % app type the Browser address bar and
the Files tree look like a different product, and the same drift happens as soon
as the window is zoomed.

Fix

The host now republishes the app's type factor to a docked page as that page's
own zoom
— fontScale × window zoom — instead of expecting plugin CSS to adopt
host design tokens:

  • PluginViewHost.setFontScale() takes the persisted AppSettings.fontScale
    from the existing settings path (applyApplicationMenuSettings), and
    resyncZoom() re-asserts the composed factor after a menu zoom.
  • The factor is applied at creation and on every dom-ready, so a reload or a
    navigation cannot leave a page at its author size. Live views are rescaled in
    place: no reload, no lost plugin state or scroll position.
  • At that factor one CSS pixel inside the plugin paints at the same DIP size as
    one CSS pixel in the app, which is what makes text and control proportions
    match — and it composes correctly with window zoom, because both operate in the
    same window.

pi.browser guest geometry. The Browser chrome measures the rect of its guest
hole in its own CSS pixels; the window places the guest in DIP. Once the chrome
page is scaled, one chrome pixel covers more than one DIP, so the host converts
the incoming hole with the same factor (scaleGuestHole) — otherwise the website
inside would sit in a hole smaller than the toolbar actually draws. The scale
travels on the existing onSurface payload; no new channel and no plugin code
change.

Scope

  • Applies to docked work-panel views, i.e. the surfaces composited inside the
    app window — exactly the two bundled plugins above, and any third-party view.
  • Detached ui.panel windows and floating widgets deliberately keep their own
    base size: they are their own windows, not a surface inside the app, and their
    46px native drag band is DIP-based. Say the word if you would rather have them
    follow the setting too; that needs the published --pi-plugin-titlebar-height
    to be divided by the same factor.
  • No plugin SDK / protocol / storage change. No migration. Nothing to update in
    pi.browser or the vendored pi.file-manager.

Test plan

Unit / contract:

  • apps/desktop/test/plugin-view-scale.test.mjs — composition rules: identity at
    100 %, 1.25 × 0.9, settled pairs stable, unusable factors fall back to 1.
  • apps/desktop/test/browser-guest-hole-scale.test.mjs — scaleGuestHole and the
    end-to-end guest rect through a real BrowserHost: at 125 % a 30 CSS px chrome
    bar becomes 37.5 DIP and the guest fills the remaining 400×600 view instead of
    ending 142 DIP too early.
  • apps/desktop/test/plugin-work-panel-views.test.mjs — source contract that the
    settings path feeds the factor in, that a fresh document re-applies it, and that
    the surface carries the factor.

Manual (dev build, pnpm dev):

  1. Settings → General → Appearance → Font size → Trenta / 125 %.
  2. Open the Browser and Files work-panel tabs. Their text and controls now scale
    with the app instead of staying at 12/13px.
  3. Ctrl/⌘ + / - / 0: the docked pages follow the window zoom as well.
  4. In Browser, load any page: the website still fills exactly the area under the
    toolbar, and resizing the panel keeps it aligned.
  5. Back to Grande / 100 %: both panels return to their author size.

Checks run on this branch: pnpm build:js (desktop electron-vite build + package
builds) passes; tsc -p apps/desktop/tsconfig.json --noEmit reports 0 errors; the
three test files above pass 25/25. The full apps/desktop suite was not run to
completion here — update-cache.test.mjs fails on Windows path assertions that are
unrelated to this change. No verify:ui:* run.

Docs

  • docs/spec/07-plugins/03-plugin-api.md — docked views now follow the host type
    size; consequences for plugin authors (page pixels are the scaled page's own
    pixels; fixed window metrics must scale themselves).
  • docs/spec/06-delivery/04-e2e-test-plan.md — E2E-193 (font size) step 4 and its
    expected result now cover the two bundled views.
  • zh-CN mirrors of both.

A `contributes.views` page is its own webContents, so neither the renderer's
`--font-scale` nor the window zoom reached it. The bundled Browser and Files
panels kept author-sized 12/13px chrome while the app around them grew, so the
two never looked like one product at any font-size setting.

The host now republishes the Appearance multiplier (times the window zoom) as
the docked page's own zoom, re-applies it to every fresh document, and rescales
live views in place so plugin state survives. `pi.browser` measures its guest
hole in the chrome page's CSS pixels, so the guest rect is converted with the
same factor and a website keeps filling the area the toolbar leaves. Detached
plugin windows and widgets keep their own base size; they are their own windows
rather than surfaces composited inside the app.

D343 / ADR 0180 introduced the global type scale for the app document only.
The PR gate requires the target tip to be an ancestor of the pull request
head, and upstream landed 32 commits after this branch was prepared, so the
base was no longer an ancestor. Merged rather than rebased: the branch is
already published on the fork and shared as a pull request.

No conflict touched this change; the conflict-free merge is followed by the
same static and unit checks.
@muzimu217

muzimu217 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

核实了这条描述的事实基础,成立,而且能定位到具体缺口。

--font-scale 确实到不了 docked 页面。 它只是应用文档上的 CSS 变量(AppSettings.fontScale 经 FontSizeRow.tsx:36-38 写入,图标等地方用 var(--font-scale) 消费),而 contributes.views 的页面是独立的 webContents——CSS 变量不跨文档,菜单 Zoom 也只作用于聚焦页面。主进程这边 plugin-view-host.ts 从未调用过 setZoomFactor;zoomFactor 在这个文件里只出现在 scaleBoundsToDip 的入参上(plugin-view-host.ts:173、:296)。所以两个内置面板保持作者写的 12/13px,和周围 125% 的界面确实像两个产品。

实现时有一个容易踩的点:这里需要两个不同的因子,不能共用一个。

  • 页面的 setZoomFactor 应该用 fontScale × windowZoom——这是让插件内容跟着变大的杠杆;
  • 但 scaleBoundsToDip(bounds, zoomFactor)(plugin-view-bounds.ts:10-22)负责把渲染层的 CSS 像素换算成 setBounds 需要的 DIP,它的入参必须仍然只是窗口 zoom(现在传的就是 currentZoomFactor(),plugin-view-host.ts:173、:296)。如果把 fontScale × windowZoom 也传进去,视图的矩形会被二次放大,面板会超出容器。

更正一句:我上一条把这条当成了 issue(gh issue view 对 PR 也返回内容),其实它就是 PR,提交式标题是对的,忽略那条"建议开 PR"的话。下面按 PR 继续看。

@muzimu217 muzimu217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The premise checks out and the two-factor split — the part I flagged before reading the diff — is implemented correctly.

Premise verified. --font-scale lives on the app document (FontSizeRow.tsx:36-38 writes AppSettings.fontScale; consumers use var(--font-scale)), a contributes.views page is its own webContents, and plugin-view-host.ts had no setZoomFactor call at all before this PR, so neither the variable nor menu zoom could reach the docked pages.

The two factors are kept apart, which is the trap here:

  • page zoom is composed — pluginViewZoom(this.fontScale, this.currentZoomFactor()) — so the plugin's CSS grows with both the Appearance scale and window zoom;
  • the host's own view bounds still convert with the window factor alone (scaleBoundsToDip(lastCssBounds, this.currentZoomFactor())), so the panel rectangle is not multiplied by fontScale a second time;
  • the browser guest hole, which the chrome page measures in its own CSS pixels, multiplies by the composed scale (scaleGuestHole(hole, chrome.scale) in browser-host.ts), which is the correct direction for that one — it is the only rect that lives in the zoomed page's coordinate space.

New views are not stranded. appliedZoom makes syncZoom() a no-op when the factor is unchanged, but a freshly created view still gets applyZoom(wc, this.viewZoom()) at creation and again on dom-ready, so a view opened after the last scale change does not render at 1.0.

Two small questions, neither blocking:

  1. setZoomFactor makes the host the owner of the docked page's zoom; a plugin that calls window.devicePixelRatio-based sizing or sets its own zoom will now be overridden. Worth one sentence in 03-plugin-api.md saying the host owns page zoom for docked views, so plugin authors do not try to compensate twice.
  2. resyncZoom() re-emits the surface when a view is visible, which is what makes the guest hole pick up the new scale. If a view is not visible at the moment the window zoom changes, its surface is emitted when it becomes visible again — worth confirming the reveal path recomputes chrome.scale rather than reusing the previous surface, otherwise a hidden-then-revealed browser would keep the old hole.

The probe's proxy asserts that every tunnel it sees targets the fixture, but
Chromium's own component updater reaches the configured session proxy while the
probe is installed. On a cold CI runner that CONNECT arrives at an unrelated
moment — a gvt1.com CDN host in the failing run — and the assertion fired
through the probe's uncaughtException path even though every probe step had
already been logged green.

A CONNECT for any host but the fixture is now refused with 502 and never
counted, so `tunnels` keeps measuring fixture traffic only, and a self-check
asserts that refusal instead of relying on the runner staying quiet.
@algerkong

Copy link
Copy Markdown
Contributor Author

Coordination note: this PR's top commit (067a13a3, the certificate-probe background-CONNECT fix) is also proposed separately as #1933, so main can go green without waiting for this PR. Whichever lands first, the other can drop it — no other content is duplicated.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The report is confirmed: docked plugin views are separate WebContents, so the app renderer's --font-scale cannot reach Browser/Files. The composed page zoom and matching Browser guest-hole conversion address that boundary, and the PR documents the observable plugin-view effect.

Validated on a candidate containing current main: 29/29 targeted tests passed, Desktop TypeScript check passed, and electron-vite build passed. The full UI journey remains draft in the E2E plan, so I did not run it. Thanks for the focused fix and tests.

@vastsa
vastsa merged commit 5c445b5 into vastsa:main Oct 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants