Files
magpie/internal/gui/assets/fonts.js
T
yetone e4aadb4840 gui: the header is fitted again when the language or the interface font changes, so the tabs no longer run under the magpie and the traffic lights (kiwiflysky on X)
With a wide interface font, the macOS window's header fit in Chinese but not
in English, Japanese or German: the tabs slid left under the magpie and the
window's buttons, and in German into the refresh button and the gear.
fitTop draws the header in step by step (tight, cramped, inrow, crowded,
packed), but it only ran again when .top, .brand or .actions changed size
(ResizeObserver) and once on document.fonts.ready. Another language or a
font picked later changes only #nav's width, so the header kept the fit it
had for the old one.

Now translateStatic (every language change) and desktopFonts.apply (every
font applied: picked, saved in the other webview, from settings) call
fitTop, and document.fonts' loadingdone does too, for a font still loading
when it's applied. Both run synchronously, where the change happens. A
ResizeObserver on #nav was tried first. It had to defer to a frame, since
fitting resizes the nav and WebKit reports that loop as a page error, and the
deferred refit moved the page after a click: text-size, number-units,
tray-logos and rail-tip went red. That approach was dropped.

Measured (830px, macOS window, before): switched live to en, ja and de, the
tabs ran 61, 105 and 148px under the magpie (Chromium and WebKit alike).

header-relang.test.cjs (new):
- Opens a macOS window in Chinese, with the header's tabs picked over the
  sidebar.
- Switches it from Settings to en, zh-TW, ja, de and back.
- In English, on the Agents page, it hands in Menlo at each width from 1000
  to 640px. Each fit must equal a fresh fitTop.
- Sweeps each language from 1100 to 600px: 7.5px clear of the magpie or
  padding and of the buttons.
- Chromium and WebKit.

Run on this commit:
- header-relang: 12/12 in Chromium and WebKit. Red on origin/main 781cb386c
  (en -61.5, ja -104.6, de -148.0 before the rebase onto the sidebar; ja
  -50.8, de -94.3 after it). Red with only the language hook removed (2
  subtests). Red with only the font hook removed (5 subtests:
  "top tight" where a fresh fit is "top tight cramped").
- Header, font, click-scroll and language neighbours: 77/77.
- text-size, number-units, tray-logos, rail-tip and menu-scroll alone: pass.
- Full GUI suite, concurrency 3, rebased on 781cb386c: 6261/6347. Each of
  the 19 failing files was run alone with this change and without it, at
  the same tree; the counts were the same (a few ±1 each way).
- On 6ebe481f8, after 054bdb8bb's sidebar fixes, 5 files are still red with
  or without this change: routing-group-fold, text-size (foot of the page),
  routing-sessions, pick-skills, otel. Filed as #1672.
- go test ./internal/gui/: TestPanelCloseHidesIt and
  TestTrayCellClickReleasedPanel fail the same on a fresh origin/main
  94fd332c3 (#1664, #1661). Everything else is ok.

Not done: in German the Settings page's sub-tabs wrap to two lines, and in
English and Japanese the "Find a setting" box drops to its own row. That is
wrapping, not overlap, and left for its own change. Beside the sidebar (from
1024px, the default since 18e82adc6) the header has no tabs. Checked by
screenshot in de with Menlo at 1100 and 1024px: nothing overlaps.
2026-10-12 03:28:42 +08:00

34 lines
1.9 KiB
JavaScript

// Installed font choices reach both webviews before their first paint.
// Keep --font and --code as the platform/theme fallbacks: an explicit
// choice is a separate variable, including on Omarchy's body.
window.desktopFonts = (() => {
let catalogue = null;
const same = (a, b) => !!a && !!b && ["family", "name", "weight", "style", "stretch"].every((k) => a[k] === b[k]);
const available = (face) => !face || catalogue === null || catalogue.some((f) => f.styles.some((s) => same(s, face)));
const quoted = (s) => '"' + s.replace(/[\\"\x00-\x1f\x7f]/g, (c) => "\\" + c.charCodeAt(0).toString(16) + " ") + '"';
function apply(s) {
const root = document.documentElement;
let active = false;
for (const [key, prefix, fallback] of [["uiFont", "ui", "font"], ["codeFont", "code", "code"]]) {
const f = !window.bootPrefs?.web && s?.[key];
const valid = f && typeof f.family === "string" && f.family && ["normal", "italic", "oblique"].includes(f.style)
&& Number.isFinite(f.weight) && f.weight >= 1 && f.weight <= 1000 && Number.isFinite(f.stretch) && f.stretch >= 0;
const values = valid && available(f) ? {
font: quoted(f.family) + ", var(--" + fallback + ")", weight: f.weight, style: f.style, stretch: f.stretch + "%",
} : {};
if (values.font) active = true;
for (const part of ["font", "weight", "style", "stretch"]) {
const name = "--" + prefix + "-" + part;
if (values[part] !== undefined) root.style.setProperty(name, values[part]);
else root.style.removeProperty(name);
}
}
if (active) root.setAttribute("data-fonts", "");
else root.removeAttribute("data-fonts");
// a wider font widens the tabs too: the header is fitted again (kiwiflysky on X)
window.fitTop?.();
}
return { apply, available, same, catalogue: (list) => { catalogue = list; } };
})();
window.desktopFonts.apply(window.bootPrefs);