gui: a browser tab's font rows show on a nogui magpie, and Text size no longer flashes
Norcleeh (Discord #general, after v0.1.1788): in magpie's web GUI the interface-font and code-font rows "flash once and disappear" on refresh. Cause, reproduced on a real nogui `magpie web` on mote in Chromium and WebKit, at 127.0.0.1, localhost and the LAN address: a nogui build (Docker, magpie-cli) has fonts.Available false, so boot.js carried no `fonts` flag and app.js never showed the font rows at all. What flashed was the Text size row: index.html shows it, and renderSettings hid it for a browser tab 40-120ms later (`#textSizeRow.hidden = web`). Fix: - A browser tab always gets the font rows. Its /api/fonts answers the server's families plus a common list (Arial, Menlo, Consolas, PingFang SC, Microsoft YaHei, Noto Sans CJK SC, JetBrains Mono, ...) and never errors for a tab; fonts.js keeps only what this browser can draw, and "System default" is always offered, so with nothing kept the rows still show with it. - The app-only rows (Text size, tray, login, tray usage) carry .app-only, which `body.web .app-only` hides before first paint, so none of them paints in a tab. - The boot `fonts` flag is gone. app.js and core both got smaller; no budget changed. - docs/subsystems/gui-shell.md "Desktop fonts" says so. Run (mote-run, at this head rebased on98e23350f): - go build ./... and -tags nogui; gofmt -l clean; GOOS=linux go vet -tags nogui ./internal/gui and GOOS=windows go vet ./internal/gui ./internal/fonts ok (at the pre-rebase head). - go test -tags nogui -run 'Font|Budget|Boot' ./internal/gui ./internal/fonts ok (and with cgo before the rebase); the new TestBrowserTabFontsWithoutInstalledFonts covers nogui, a failed read and a merge with the server's own families. - fonts, i18n-keys, settings-general, text-size, web-page: 76/76. - Before the rebase, 20 files (fonts, font-cascade, win-fonts, login-allow, omarchy, settings-general/-search/-sections/-groups/ -lines-wrap/-tabs-stick, text-size, tray-usages, web-page, web-app-standalone, gui-de, gui-ja, gui-zh-tw, i18n-keys) 259 tests, all ok but i18n-keys' "Runs as" (#3897, green now on main). - Whole GUI suite before the rebase, --test-concurrency=4 beside other sessions' load: 13,626 tests, 160 red in 31 files. Those 31 files run alone at head and at base0a7633136: 166 vs 157 red, the same tests at other widths/languages (routing-*, segs-press-redraw's webkit 900/440px, usage-*); mobile-web's "matches origin/main" needs .git, which a mote-run copy lacks; old-webkit's :has() is on base. segs-press-redraw alone: 7 red at head, 8 at base. - New GUI test, both engines, en and zh: "a browser tab's font rows show on a nogui magpie and nothing flashes" records every rAF frame. Red on the old assets (uiFontRow never shows). Broken by hand: without the .app-only CSS rule it goes red with textSizeRow painting ~20 frames then going away (the reported flash); with `row.hidden = web && fontList?.length === 0` it goes red. - Real servers on mote, both engines, 3 origins: nogui shows the rows (19 families in Chromium, 21 in WebKit), Text size never shown; a cgo desktop server 204/181 families. Not tried: a Windows server with the fix (old code showed the rows), WebKit over a LAN tunnel, Brave/Safari fingerprinting modes, the full Go suite.
This commit is contained in:
@@ -258,17 +258,24 @@ CoreText on macOS and Fontconfig on Linux. Discovery is lazy, cached in the
|
||||
handler, and refreshed by the menu. It returns names and CSS traits, never
|
||||
font files or paths. A failed refresh answers 503 and preserves the previous
|
||||
collection; an empty successful collection is distinct from failure.
|
||||
A `nogui` build can't read the catalogue and answers 404.
|
||||
A `nogui` build can't read the catalogue and answers the app 404.
|
||||
|
||||
A browser tab (`magpie web`, or the app's page opened in a browser) has the
|
||||
same rows when boot says `fonts` (Norcleeh on Discord). Its choice is the
|
||||
A browser tab (`magpie web`, or the app's page opened in a browser) always
|
||||
has the same rows (Norcleeh on Discord). Its choice is the
|
||||
browser's own, kept in `localStorage` under `magpie.fonts` and applied by
|
||||
`fonts.js` before the first paint: the tab can be on another computer, so
|
||||
it neither changes nor takes the app's `settings.UIFont`/`CodeFont`. Its
|
||||
list is `/api/fonts` less the families the browser doesn't draw
|
||||
(`desktopFonts.here`: text in the family measures apart from a generic
|
||||
family's on a canvas), so another computer's fonts, and Safari's
|
||||
user-installed ones, aren't offered. In a nogui build the rows stay hidden.
|
||||
it neither changes nor takes the app's `settings.UIFont`/`CodeFont`. A
|
||||
tab's `/api/fonts` is the server's families (none in a nogui build such as
|
||||
Docker or `magpie-cli`, and none when reading them fails, never an error)
|
||||
plus `commonFamilies` in `internal/gui/fonts.go`, in regular and bold.
|
||||
The tab keeps those it draws (`desktopFonts.here`: text in the family
|
||||
measures apart from a generic family's on a canvas), so another computer's
|
||||
fonts, and Safari's user-installed ones, aren't offered. When none is
|
||||
kept, the rows still offer System default. Until 10-28 the rows were
|
||||
gated on a boot `fonts` flag, so a nogui server had none, and what
|
||||
"flashed and vanished" on a refresh was Text size: the rows a tab never
|
||||
shows (Text size, the tray click, Open at login, the menu bar's
|
||||
allowances) are `.app-only`, which `body.web` hides before the first paint.
|
||||
|
||||
`settings.UIFont` and `settings.CodeFont` keep the family, style name,
|
||||
OpenType weight, CSS slope and width percentage. A missing choice keeps the
|
||||
|
||||
+2
-5
@@ -855,12 +855,9 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
if s.Colorblind {
|
||||
boot["colorblind"] = true
|
||||
}
|
||||
// a browser tab keeps its own font choice (fonts.js) and is told
|
||||
// whether there is a list to choose from
|
||||
// a browser tab keeps its own font choice (fonts.js)
|
||||
if !isWeb(w) {
|
||||
boot["uiFont"], boot["codeFont"] = s.UIFont, s.CodeFont
|
||||
} else if fonts.Available {
|
||||
boot["fonts"] = true
|
||||
}
|
||||
// and whether it is a gateway's page alone (gatewaymode.go), so the
|
||||
// pages left out never show
|
||||
@@ -906,7 +903,7 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
writeJSON(rw, nil)
|
||||
})
|
||||
omarchyRoutes(mux, w)
|
||||
fontRoutes(mux, !fonts.Available, fonts.List)
|
||||
fontRoutes(mux, isWeb(w), !fonts.Available, fonts.List)
|
||||
mux.HandleFunc("GET /api/state", func(rw http.ResponseWriter, r *http.Request) {
|
||||
// the panel and its model picker load from here: an account still
|
||||
// without its vendor's list (one whose try at start-up failed) is
|
||||
|
||||
@@ -159,6 +159,9 @@ button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); ou
|
||||
input { font: inherit; color: var(--fg); }
|
||||
.grow { flex: 1; }
|
||||
[hidden] { display: none !important; }
|
||||
/* the app's own rows (Text size, the tray, login, the menu bar's allowances)
|
||||
never paint in a browser tab, before renderSettings hides them too */
|
||||
body.web .app-only { display: none !important; }
|
||||
code { font: var(--code-style, normal) var(--code-weight, 400) 11.5px var(--code-font, var(--code)); font-stretch: var(--code-stretch, 100%); }
|
||||
|
||||
/* ---- brand icons: colour ones are images, mono ones take the text colour --- */
|
||||
|
||||
@@ -18864,7 +18864,6 @@ if (!web) addEventListener("keydown", (e) => {
|
||||
// keep the family/style controls usable while the shared save queue drains.
|
||||
let fontList = null, fontListError = false, fontFlight = null, fontRevision = 0;
|
||||
const fontDrafts = {};
|
||||
const fontsOn = !web || window.bootPrefs?.fonts;
|
||||
function fontChoices(s) {
|
||||
if (web) return { ...s, ...window.desktopFonts.own() };
|
||||
return { ...s, ...Object.fromEntries(Object.entries(fontDrafts).map(([k, d]) => [k, d.value])) };
|
||||
@@ -18880,7 +18879,7 @@ window.receiveFonts = (s) => {
|
||||
if (prefs && view === "settings") renderFonts(prefs);
|
||||
};
|
||||
async function loadFonts(refresh = false) {
|
||||
if (!fontsOn || fontFlight || (fontList !== null && !refresh)) return fontFlight;
|
||||
if (fontFlight || (fontList !== null && !refresh)) return fontFlight;
|
||||
fontListError = false;
|
||||
fontFlight = api("fonts" + (refresh ? "?refresh=1" : ""))
|
||||
.then((list) => {
|
||||
@@ -18918,7 +18917,7 @@ function renderFonts(s) {
|
||||
const current = fontChoices(s);
|
||||
for (const [key, id, label] of [["uiFont", "uiFontRow", "Interface font"], ["codeFont", "codeFontRow", "Code font"]]) {
|
||||
const row = $("#" + id);
|
||||
if (row.hidden = !fontsOn) continue;
|
||||
row.hidden = false;
|
||||
const chosen = current[key], family = fontList?.find((f) => f.name === chosen?.family);
|
||||
const missing = chosen && !window.desktopFonts.available(chosen);
|
||||
const note = row.querySelector(".font-note");
|
||||
@@ -19061,7 +19060,7 @@ function renderLoginAllow(s) {
|
||||
|
||||
async function loadSettings() {
|
||||
const since = prefsWrites;
|
||||
if (fontsOn && fontList === null && !fontListError) loadFonts();
|
||||
if (fontList === null && !fontListError) loadFonts();
|
||||
if (window.bootPrefs?.omarchy && !barIcon) api("omarchy/widget").then((b) => { barIcon = b; renderBarIcon(); }).catch(() => {});
|
||||
const s = await api("settings");
|
||||
if (!prefsSettled(since) && prefs) return; // the save draws the page when it's in
|
||||
|
||||
@@ -180,7 +180,7 @@
|
||||
<div class="who"><div class="name" data-t>Gateway mode</div><div class="sub" id="gatewayModeSub"></div></div>
|
||||
<div id="gatewayModeSegs"></div>
|
||||
</div>
|
||||
<div class="row pref" id="textSizeRow">
|
||||
<div class="row pref app-only" id="textSizeRow">
|
||||
<div class="who"><div class="name" data-t>Text size</div></div>
|
||||
<div id="textSizeSegs"></div>
|
||||
</div>
|
||||
@@ -200,7 +200,7 @@
|
||||
<div class="font-preview">Aa 0123 · 中文</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row pref">
|
||||
<div class="row pref app-only">
|
||||
<div class="who"><div class="name" data-t>Click the tray icon to</div></div>
|
||||
<div id="traySegs"></div>
|
||||
</div>
|
||||
@@ -214,7 +214,7 @@
|
||||
</div>
|
||||
<!-- Codex's and Claude Code's own settings are on the Agents page (AGENT_PREFS); while searching, a row here says where -->
|
||||
<div id="agentPrefLinks"></div>
|
||||
<div class="row pref" id="loginRow">
|
||||
<div class="row pref app-only" id="loginRow">
|
||||
<div class="who"><div class="name" data-t>Open at login</div></div>
|
||||
<div id="loginSegs"></div>
|
||||
</div>
|
||||
@@ -242,7 +242,7 @@
|
||||
</section>
|
||||
<section class="set-page" id="setPage-usage" role="tabpanel" aria-labelledby="setTab-usage">
|
||||
<div class="list prefs">
|
||||
<div class="row pref" id="trayUsageRow">
|
||||
<div class="row pref app-only" id="trayUsageRow">
|
||||
<div class="who"><div class="name" data-t>Allowances in the menu bar</div><div class="sub" id="trayUsageSub"></div></div>
|
||||
<div id="trayUsagePick"></div>
|
||||
</div>
|
||||
|
||||
+57
-11
@@ -3,6 +3,8 @@ package gui
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/yetone/magpie/internal/fonts"
|
||||
@@ -22,30 +24,74 @@ func fontSettingsJS(s settings.Settings) string {
|
||||
}
|
||||
|
||||
// The fonts installed on the computer magpie runs on, for its windows and
|
||||
// for a browser tab (which keeps the families it draws itself, fonts.js);
|
||||
// off where they can't be read (a nogui build). A failed refresh leaves
|
||||
// the last successful collection intact.
|
||||
func fontRoutes(mux *http.ServeMux, off bool, discover func() ([]fonts.Family, error)) {
|
||||
// for a browser tab (which keeps the families it draws itself, fonts.js).
|
||||
// A browser tab is also offered common families: it may be on another
|
||||
// computer, and a nogui build (Docker, magpie-cli) reads no fonts at all,
|
||||
// where its rows were left out and only Text size flashed by (Norcleeh).
|
||||
// A failed refresh leaves the last successful collection intact.
|
||||
func fontRoutes(mux *http.ServeMux, web, off bool, discover func() ([]fonts.Family, error)) {
|
||||
var mu sync.Mutex
|
||||
var cached []fonts.Family
|
||||
mux.HandleFunc("GET /api/fonts", func(rw http.ResponseWriter, r *http.Request) {
|
||||
if off {
|
||||
if off && !web {
|
||||
http.Error(rw, "installed fonts can't be read by this magpie", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if cached == nil || r.URL.Query().Get("refresh") == "1" {
|
||||
if !off && (cached == nil || r.URL.Query().Get("refresh") == "1") {
|
||||
found, err := discover()
|
||||
if err != nil {
|
||||
switch {
|
||||
case err == nil && found == nil:
|
||||
cached = []fonts.Family{}
|
||||
case err == nil:
|
||||
cached = found
|
||||
case !web: // a tab still has the common families
|
||||
http.Error(rw, "could not read installed fonts", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
cached = found
|
||||
if cached == nil {
|
||||
cached = []fonts.Family{}
|
||||
}
|
||||
}
|
||||
if web {
|
||||
writeJSON(rw, withCommon(cached))
|
||||
return
|
||||
}
|
||||
writeJSON(rw, cached)
|
||||
})
|
||||
}
|
||||
|
||||
// Families most computers have, by system and script; the tab keeps those
|
||||
// it draws. Each is offered in its regular and bold weights.
|
||||
var commonFamilies = []string{
|
||||
"Arial", "Avenir Next", "Calibri", "Cambria", "Cascadia Code", "Cascadia Mono", "Consolas", "Courier New",
|
||||
"DejaVu Sans", "DejaVu Sans Mono", "Fira Code", "Fira Sans", "Georgia", "Helvetica", "Helvetica Neue",
|
||||
"Hiragino Sans", "Hiragino Sans GB", "IBM Plex Mono", "IBM Plex Sans", "Inter", "JetBrains Mono",
|
||||
"Liberation Mono", "Liberation Sans", "Lucida Grande", "LXGW WenKai", "Malgun Gothic", "Maple Mono", "Menlo",
|
||||
"Microsoft JhengHei", "Microsoft YaHei", "Monaco", "Noto Sans", "Noto Sans CJK SC", "Noto Sans Mono",
|
||||
"Noto Serif", "Noto Serif CJK SC", "Palatino", "PingFang SC", "PingFang TC", "Roboto", "Roboto Mono",
|
||||
"Sarasa Gothic SC", "Segoe UI", "SF Mono", "SimHei", "SimSun", "Songti SC", "Source Code Pro",
|
||||
"Source Han Sans SC", "Tahoma", "Times New Roman", "Trebuchet MS", "Ubuntu", "Ubuntu Mono", "Verdana",
|
||||
"WenQuanYi Micro Hei", "Yu Gothic",
|
||||
}
|
||||
|
||||
// withCommon adds the common families the list lacks, by name in any case,
|
||||
// and keeps it in the order fonts.List gives (case-insensitive names).
|
||||
func withCommon(found []fonts.Family) []fonts.Family {
|
||||
out := slices.Clone(found)
|
||||
have := map[string]bool{}
|
||||
for _, f := range found {
|
||||
have[strings.ToLower(f.Name)] = true
|
||||
}
|
||||
for _, name := range commonFamilies {
|
||||
if have[strings.ToLower(name)] {
|
||||
continue
|
||||
}
|
||||
face := fonts.Face{Family: name, Name: "Regular", Weight: 400, Style: "normal", Stretch: 100}
|
||||
bold := face
|
||||
bold.Name, bold.Weight = "Bold", 700
|
||||
out = append(out, fonts.Family{Name: name, Styles: []fonts.Face{face, bold}})
|
||||
}
|
||||
slices.SortStableFunc(out, func(a, b fonts.Family) int {
|
||||
return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name))
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -19,7 +20,7 @@ func TestFontDiscoveryCacheAndFailure(t *testing.T) {
|
||||
want := []fonts.Family{{Name: face.Family, Styles: []fonts.Face{face}}}
|
||||
calls, broken := 0, false
|
||||
mux := http.NewServeMux()
|
||||
fontRoutes(mux, false, func() ([]fonts.Family, error) {
|
||||
fontRoutes(mux, false, false, func() ([]fonts.Family, error) {
|
||||
calls++
|
||||
if broken {
|
||||
return nil, errors.New("font service unavailable")
|
||||
@@ -57,15 +58,70 @@ func TestFontDiscoveryCacheAndFailure(t *testing.T) {
|
||||
if calls != 3 {
|
||||
t.Fatalf("refresh did not re-read fonts: %d", calls)
|
||||
}
|
||||
web := http.NewServeMux()
|
||||
fontRoutes(web, true, func() ([]fonts.Family, error) { t.Fatal("fonts read where they can't be"); return nil, nil })
|
||||
off := http.NewServeMux()
|
||||
fontRoutes(off, false, true, func() ([]fonts.Family, error) { t.Fatal("fonts read where they can't be"); return nil, nil })
|
||||
r = httptest.NewRecorder()
|
||||
web.ServeHTTP(r, httptest.NewRequest("GET", "/api/fonts", nil))
|
||||
off.ServeHTTP(r, httptest.NewRequest("GET", "/api/fonts", nil))
|
||||
if r.Code != 404 {
|
||||
t.Fatalf("font discovery turned off returned %d", r.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// Norcleeh: a nogui magpie's browser tab had no font rows. A tab is offered
|
||||
// the server's families and the common ones, whatever the server can read.
|
||||
func TestBrowserTabFontsWithoutInstalledFonts(t *testing.T) {
|
||||
read := func(off bool, discover func() ([]fonts.Family, error)) []fonts.Family {
|
||||
t.Helper()
|
||||
mux := http.NewServeMux()
|
||||
fontRoutes(mux, true, off, discover)
|
||||
r := httptest.NewRecorder()
|
||||
mux.ServeHTTP(r, httptest.NewRequest("GET", "/api/fonts", nil))
|
||||
if r.Code != 200 {
|
||||
t.Fatalf("a browser tab's fonts answered %d %s", r.Code, r.Body)
|
||||
}
|
||||
var got []fonts.Family
|
||||
if err := json.Unmarshal(r.Body.Bytes(), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return got
|
||||
}
|
||||
names := func(list []fonts.Family) []string {
|
||||
var out []string
|
||||
for _, f := range list {
|
||||
out = append(out, f.Name)
|
||||
}
|
||||
return out
|
||||
}
|
||||
nogui := read(true, func() ([]fonts.Family, error) { t.Fatal("fonts read where they can't be"); return nil, nil })
|
||||
if len(nogui) != len(commonFamilies) {
|
||||
t.Fatalf("a nogui magpie's tab got %v", names(nogui))
|
||||
}
|
||||
for _, f := range nogui {
|
||||
if len(f.Styles) != 2 || f.Styles[0].Family != f.Name || fonts.Validate(&f.Styles[0]) != nil || fonts.Validate(&f.Styles[1]) != nil {
|
||||
t.Fatalf("common family %#v", f)
|
||||
}
|
||||
}
|
||||
if failed := read(false, func() ([]fonts.Family, error) { return nil, errors.New("no font service") }); len(failed) != len(commonFamilies) {
|
||||
t.Fatalf("a failed read left the tab %v", names(failed))
|
||||
}
|
||||
own := fonts.Face{Family: "georgia", Name: "Light", Weight: 300, Style: "normal", Stretch: 100}
|
||||
odd := fonts.Face{Family: "Zzz Own Family", Name: "Regular", Weight: 400, Style: "normal", Stretch: 100}
|
||||
got := read(false, func() ([]fonts.Family, error) {
|
||||
return []fonts.Family{{Name: own.Family, Styles: []fonts.Face{own}}, {Name: odd.Family, Styles: []fonts.Face{odd}}}, nil
|
||||
})
|
||||
if len(got) != len(commonFamilies)+1 {
|
||||
t.Fatalf("the server's own families and the common ones: %v", names(got))
|
||||
}
|
||||
if !slices.IsSortedFunc(got, func(a, b fonts.Family) int { return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name)) }) {
|
||||
t.Fatalf("not in name order: %v", names(got))
|
||||
}
|
||||
for _, f := range got {
|
||||
if strings.EqualFold(f.Name, "Georgia") && !reflect.DeepEqual(f.Styles, []fonts.Face{own}) {
|
||||
t.Fatalf("the server's Georgia was replaced: %#v", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFontSettingsAPIAndBoot(t *testing.T) {
|
||||
testenv.SetHome(t, t.TempDir())
|
||||
notices := 0
|
||||
@@ -114,9 +170,11 @@ func TestFontSettingsAPIAndBoot(t *testing.T) {
|
||||
if _, ok := webBoot["uiFont"]; ok {
|
||||
t.Fatal("browser received a desktop font override")
|
||||
}
|
||||
// a browser tab is offered the font list wherever magpie can read one
|
||||
if _, ok := webBoot["fonts"]; ok != fonts.Available {
|
||||
t.Fatalf("browser boot fonts = %v, want %v", ok, fonts.Available)
|
||||
// a browser tab's rows show wherever it is served, nogui too
|
||||
r := httptest.NewRecorder()
|
||||
web.ServeHTTP(r, httptest.NewRequest("GET", "/api/fonts", nil))
|
||||
if r.Code != 200 || !strings.Contains(r.Body.String(), `"Georgia"`) {
|
||||
t.Fatalf("a browser tab's fonts answered %d", r.Code)
|
||||
}
|
||||
post(h, map[string]any{"uiFont": map[string]any{"family": "bad", "name": "Regular", "weight": 1001}}, 400)
|
||||
if !reflect.DeepEqual(settings.Load().UIFont, face) {
|
||||
|
||||
@@ -17,7 +17,7 @@ const catalogue = [
|
||||
|
||||
async function open(browser, lang = "en", options = {}) {
|
||||
const context = await browser.newContext({ locale: lang === "zh" ? "zh-CN" : "en-US", viewport: options.viewport || { width: 1000, height: 820 } });
|
||||
const api = { posts: [], reads: 0, fonts: structuredClone(catalogue), fontError: false, saveError: false, delay: 0,
|
||||
const api = { posts: [], reads: 0, fonts: structuredClone(options.list || catalogue), fontError: false, saveError: false, delay: 0,
|
||||
cur: { lang, theme: "light", textSize: 100, currency: "usd", tray: "panel", version: "0.1.0", visionModels: [], imageGenModels: [], ...options.settings } };
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
@@ -26,13 +26,14 @@ async function open(browser, lang = "en", options = {}) {
|
||||
await page.route("**/*", async route => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = data => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs=${JSON.stringify({ ...api.cur, web: !!options.web, ...(options.fonts ? { fonts: true } : {}), ...(options.omarchy ? { omarchy: { mode: "dark", stamp: "one", name: "Test theme", vars: { "--font": '"Theme Font", sans-serif', "--code": '"Theme Mono", monospace' } } } : {}) })};` });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs=${JSON.stringify({ ...api.cur, web: !!options.web, ...(options.omarchy ? { omarchy: { mode: "dark", stamp: "one", name: "Test theme", vars: { "--font": '"Theme Font", sans-serif', "--code": '"Theme Mono", monospace' } } } : {}) })};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/fonts") {
|
||||
api.reads++;
|
||||
return api.fontError ? route.fulfill({ status: 503, body: "could not read installed fonts" }) : json(api.fonts);
|
||||
}
|
||||
if (url.pathname === "/api/settings") {
|
||||
if (options.settingsDelay) await new Promise(r => setTimeout(r, options.settingsDelay));
|
||||
if (req.method() === "POST") {
|
||||
const body = req.postDataJSON();
|
||||
api.posts.push(body);
|
||||
@@ -53,6 +54,17 @@ async function open(browser, lang = "en", options = {}) {
|
||||
try { return await route.fulfill({ body: await fs.readFile(file), contentType }); }
|
||||
catch { return route.fulfill({ status: 404, body: "not found" }); }
|
||||
});
|
||||
// every frame's rows, from the first paint (Norcleeh: a row flashed and went)
|
||||
if (options.frames) await page.addInitScript(() => {
|
||||
window.__frames = [];
|
||||
const ids = ["uiFontRow", "codeFontRow", "textSizeRow", "loginRow", "trayUsageRow"];
|
||||
const look = () => {
|
||||
const tray = document.getElementById("traySegs")?.parentElement;
|
||||
if (document.getElementById("uiFontRow")) window.__frames.push(Object.fromEntries([...ids.map(id => [id, !!document.getElementById(id)?.getClientRects().length]), ["tray", !!tray?.getClientRects().length]]));
|
||||
requestAnimationFrame(look);
|
||||
};
|
||||
requestAnimationFrame(look);
|
||||
});
|
||||
await watchSettingsReads(page);
|
||||
await page.goto("http://magpie.test/?view=settings&tab=general");
|
||||
await settingsDrawn(page); // rows found are the ones that stay (#1659)
|
||||
@@ -60,7 +72,8 @@ async function open(browser, lang = "en", options = {}) {
|
||||
// A real assertion, also usable against the original assets, rather than
|
||||
// a timeout or a compile error as the negative-control result.
|
||||
assert.equal(await page.locator("#uiFontRow").count(), 1, "Settings must offer an interface font picker");
|
||||
if (!options.web || options.fonts) await page.waitForFunction(() => fontList !== null || fontListError);
|
||||
// (a row left hidden, as before 10-28 in a nogui magpie's tab, fails at its assertion, not here)
|
||||
await page.waitForFunction(() => fontList !== null || fontListError || document.getElementById("uiFontRow").hidden);
|
||||
await page.evaluate(async () => {
|
||||
await document.fonts.ready;
|
||||
await Promise.all(document.getAnimations().map(a => a.finished.catch(() => {})));
|
||||
@@ -272,12 +285,6 @@ for (const [engine, runtime] of engines) {
|
||||
assert.match((await css(page, "body")).family, /Theme Font/);
|
||||
assert.match((await css(page, "#codeFontRow .font-preview")).family, /Consolas/);
|
||||
assert.deepEqual(errors, []);
|
||||
// a magpie that can't read its fonts (nogui) offers none to a browser
|
||||
const web = await open(browser, "en", { web: true, settings: { uiFont: harmony[1] } });
|
||||
assert.equal(await web.page.locator("#uiFontRow").isVisible(), false);
|
||||
assert.equal(web.api.reads, 0);
|
||||
assert.doesNotMatch((await css(web.page, "body")).family, /HarmonyOS/);
|
||||
assert.deepEqual(web.errors, []);
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
@@ -288,7 +295,7 @@ for (const [engine, runtime] of engines) {
|
||||
try {
|
||||
const real = ["Georgia", "Courier New", "DejaVu Serif", "Liberation Serif"];
|
||||
const list = [{ name: "No Such Family Here", styles: [face("No Such Family Here")] }, ...real.map(n => ({ name: n, styles: [face(n), face(n, "Bold", 700)] }))];
|
||||
const { page, api, errors } = await open(browser, lang, { web: true, fonts: true, settings: { uiFont: harmony[1] } });
|
||||
const { page, api, errors } = await open(browser, lang, { web: true, settings: { uiFont: harmony[1] } });
|
||||
api.fonts = list;
|
||||
assert.equal(await page.locator("#uiFontRow").isVisible(), true, "a browser tab offers the interface font");
|
||||
assert.equal(await page.locator("#codeFontRow").isVisible(), true, "and the code font");
|
||||
@@ -321,6 +328,44 @@ for (const [engine, runtime] of engines) {
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
// Norcleeh again, after v0.1.1788: on a refresh a row "flashed and went".
|
||||
// A nogui magpie (Docker, magpie-cli) has no boot `fonts`, so the font
|
||||
// rows never showed, and Text size painted until the settings hid it.
|
||||
// The tab's rows show whatever the server can read, with System default
|
||||
// when the browser draws none of its families, and stay through every
|
||||
// later settings read; the app's own rows never paint at all.
|
||||
for (const lang of ["en", "zh"]) test(`${engine} ${lang}: a browser tab's font rows show on a nogui magpie and nothing flashes`, async () => {
|
||||
const browser = await runtime.launch();
|
||||
try {
|
||||
for (const fonts of [[{ name: "Georgia", styles: [face("Georgia"), face("Georgia", "Bold", 700)] }, { name: "No Such Family Here", styles: [face("No Such Family Here")] }], []]) {
|
||||
const { page, errors, close } = await open(browser, lang, { web: true, frames: true, settingsDelay: 300, list: fonts, settings: { uiFont: harmony[1] } });
|
||||
// what a later refresh of the settings or the state redraws
|
||||
await page.evaluate(() => loadSettings());
|
||||
await page.evaluate(() => new Promise(r => setTimeout(r, 500)));
|
||||
const frames = await page.evaluate(() => window.__frames);
|
||||
assert(frames.length > 5, "frames were watched: " + frames.length);
|
||||
for (const row of ["uiFontRow", "codeFontRow"]) {
|
||||
assert.equal(await page.locator("#" + row).isVisible(), true, row + " shows in a browser tab");
|
||||
const first = frames.findIndex(f => f[row]);
|
||||
assert(first >= 0, row + " never painted");
|
||||
assert(frames.slice(first).every(f => f[row]), row + " painted and then went: " + frames.map(f => +f[row]).join(""));
|
||||
}
|
||||
for (const row of ["textSizeRow", "loginRow", "trayUsageRow", "tray"]) {
|
||||
assert(!frames.some(f => f[row]), row + " is the app's and painted in a browser tab: " + frames.map(f => +f[row]).join(""));
|
||||
}
|
||||
const shown = await page.evaluate(() => fontList.map(f => f.name));
|
||||
assert(!shown.includes("No Such Family Here"), "a family this browser doesn't draw isn't offered: " + shown);
|
||||
await page.locator("#codeFontRow .font-family").click();
|
||||
const names = await page.locator(".font-menu .pm-item .pm-name").allTextContents();
|
||||
assert.equal(names[0], lang === "zh" ? "系统默认" : "System default", "System default is offered: " + names);
|
||||
if (!fonts.length) assert.deepEqual(shown, [], "no family this browser draws");
|
||||
await page.keyboard.press("Escape");
|
||||
assert.deepEqual(errors, []);
|
||||
await close();
|
||||
}
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
test(`${engine}: native notifications update the other webview without another save`, async () => {
|
||||
const browser = await runtime.launch();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user