gui: every page says it draws a dark theme, so browsers don't repaint it (xjp on X)
Chrome's Auto Dark Theme and Safari's Adaptive Dark Mode (Safari 27.3 beta) repaint pages that don't declare dark support. magpie's GUI draws both themes itself but never said so, so a browser's light magpie was repainted. WebKit's post (webkit.org/blog/18541) and Chrome's (developer.chrome.com/blog/auto-dark-theme) say: `color-scheme: light dark` (CSS on :root or the meta) is skipped; `light only` opts an element out (Safari 27.3 beta 1 doesn't honour `only` yet). - index.html: <meta name="color-scheme" content="light dark">. - app.css: :root takes `light dark` always (the signal browsers read); body takes the theme shown: Settings' Light is `light only`, Dark is `dark`, System follows the root. Native controls, scrollbars and a plugin's frame follow the theme shown. - pagebridge.js: a plugin page's light frame is `light only`. - The other pages magpie serves (magpie web's sign-in, a sign-in's end page, an MCP sign-in's end page, a plugin service's "starting" page) declare `light dark`; the MCP page drops its fixed #222 text so it reads on a dark canvas. keypage.html and the extension popup already did; site/ pages already do. Tests: color-scheme.test.cjs (chromium + webkit; system/light/dark on a dark OS: meta, root and body schemes), TestPagesDeclareBothColorSchemes, TestSignInPageDeclaresBothColorSchemes, TestPageDeclaresBothColorSchemes. Run (mote, before the rebase on origin/main6bcdc6468): the new GUI file 6/6 in chromium + webkit; checkbox-look 8/8, plugin-page, plugin-panels and plugin-page-idle 14/14; go test of the new tests and -run "PluginPage|Page|Bridge|SignIn" in internal/gui, internal/provider, internal/mcpauth ok; go vet darwin, linux (nogui), windows ok; gofmt clean. api-key-theme is red 6/6 here and on origin/main2f2a0afa5alone (#6444, a #lanList selector matches nothing). At the pushed head (after the rebase): color-scheme.test.cjs 6/6 and -run "ColorScheme|Budget" in the three packages ok. Broken by hand: the four new tests on origin/main's code (2f2a0afa5) are all red (GUI 0/6, three Go tests FAIL). Not tried: Safari 27.3 beta's Adaptive Dark Mode and Chrome's Auto Dark Theme themselves (no beta device here); the real app's windows (Wails WebKit, WebView2, WebKitGTK) with the root's new color-scheme; the full GUI suite.
This commit is contained in:
@@ -94,6 +94,15 @@
|
||||
--tk-s: #98d8a4; --tk-k: #c4b5fd; --tk-f: #93c5fd; --tk-n: #f2b544; --tk-v: #67e8f9; --tk-o: #f0abfc; --tk-c: #8b8b94;
|
||||
--c1: #a5b4fc; --c2: #7dd3fc; --c3: #6ee7b7; --c4: #fcd34d; --c5: #f9a8d4; --c6: #c4b5fd; --c7: #94a3b8;
|
||||
}
|
||||
/* magpie draws both themes itself. The root says so, as index.html's meta
|
||||
does, so a browser that repaints light pages dark (Chrome's Auto Dark
|
||||
Theme, Safari's Adaptive Dark Mode) leaves the page alone (xjp on X).
|
||||
The page under it takes the theme shown, so native controls, scrollbars
|
||||
and a plugin's frame match it, and a theme chosen in Settings is the
|
||||
only one: Light stays light on a dark system. */
|
||||
:root { color-scheme: light dark; }
|
||||
:root[data-theme="light"] body { color-scheme: light only; }
|
||||
:root[data-theme="dark"] body { color-scheme: dark; }
|
||||
/* Okabe–Ito qualitative series (#2073): adjacent series stay apart in hue and
|
||||
lightness in both light and dark themes */
|
||||
:root[data-colorblind="1"] {
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<!-- magpie draws a light and a dark theme of its own: a browser that
|
||||
repaints light pages dark (Chrome's Auto Dark Theme, Safari's Adaptive
|
||||
Dark Mode) leaves it alone (xjp on X); app.css says the same -->
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<title>magpie</title>
|
||||
<link rel="icon" href="icons/favicon.svg" type="image/svg+xml">
|
||||
<!-- added to a phone's home screen, magpie web opens as an app of its own,
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Every page magpie draws says it has a dark theme of its own, so a
|
||||
// browser that repaints light pages dark (Chrome's Auto Dark Theme,
|
||||
// Safari's Adaptive Dark Mode) leaves it alone (xjp on X).
|
||||
func TestPagesDeclareBothColorSchemes(t *testing.T) {
|
||||
const meta = `<meta name="color-scheme" content="light dark">`
|
||||
index, err := os.ReadFile("assets/index.html")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(index), meta) {
|
||||
t.Errorf("index.html has no %s", meta)
|
||||
}
|
||||
css, err := os.ReadFile("assets/app.css")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(css), ":root { color-scheme: light dark; }") {
|
||||
t.Error("app.css's root doesn't take both color schemes")
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
webTurnedAway(rec, httptest.NewRequest("GET", "/", nil), "/", "why")
|
||||
if !strings.Contains(rec.Body.String(), meta) {
|
||||
t.Errorf("magpie web's sign-in page has no %s:\n%s", meta, rec.Body.String())
|
||||
}
|
||||
}
|
||||
@@ -98,8 +98,10 @@
|
||||
function paint(theme) {
|
||||
const root = document.documentElement;
|
||||
root.dataset.theme = theme.dark ? "dark" : "light";
|
||||
// the frame's canvas matches the window's, not a white sheet in dark
|
||||
root.style.colorScheme = theme.dark ? "dark" : "light";
|
||||
// the frame's canvas matches the window's, not a white sheet in dark;
|
||||
// a light one is light only, so a browser that repaints light pages
|
||||
// dark leaves it as the window is left (xjp on X)
|
||||
root.style.colorScheme = theme.dark ? "dark" : "light only";
|
||||
root.lang = theme.lang || "en";
|
||||
for (const [k, v] of Object.entries(theme.tokens || {})) root.style.setProperty("--magpie-" + k, v);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ func servePageService(rw http.ResponseWriter, r *http.Request, p *pluginPage, to
|
||||
// sandboxed document refreshes only with allow-scripts
|
||||
h.Set("Content-Type", "text/html; charset=utf-8")
|
||||
rw.WriteHeader(http.StatusBadGateway)
|
||||
fmt.Fprint(rw, `<!doctype html><meta charset="utf-8"><meta http-equiv="refresh" content="2"><style>body{font:13px/1.5 system-ui,sans-serif;display:grid;place-items:center;height:90vh;margin:0;color:GrayText}</style><p>The plugin's service isn't answering yet. Trying again…</p>`)
|
||||
fmt.Fprint(rw, `<!doctype html><meta charset="utf-8"><meta name="color-scheme" content="light dark"><meta http-equiv="refresh" content="2"><style>body{font:13px/1.5 system-ui,sans-serif;display:grid;place-items:center;height:90vh;margin:0;color:GrayText}</style><p>The plugin's service isn't answering yet. Trying again…</p>`)
|
||||
return
|
||||
}
|
||||
http.Error(rw, "the plugin's service isn't answering", http.StatusBadGateway)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
const assert = require("node:assert/strict");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const { fixture } = require("./fixtures/caller-keys.cjs");
|
||||
|
||||
// magpie draws both themes itself, and says so: a browser that repaints
|
||||
// light pages dark (Chrome's Auto Dark Theme, Safari's Adaptive Dark Mode)
|
||||
// skips a page whose root takes dark too, and leaves an element that is
|
||||
// light only alone (xjp on X). The page under the root takes the theme
|
||||
// shown, so Settings' Light stays light on a dark system.
|
||||
const words = (v) => v.trim().split(/\s+/).sort().join(" ");
|
||||
const want = { system: "dark light", light: "light only", dark: "dark" };
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const theme of ["system", "light", "dark"]) {
|
||||
test(`${engine} ${theme}: the page declares both themes, the body the one shown`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const context = await browser.newContext({ viewport: { width: 1000, height: 700 }, reducedMotion: "reduce", colorScheme: "dark" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(6000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", fixture("en", theme, []));
|
||||
await page.goto("http://magpie.test/?view=gateway" + (theme === "system" ? "" : "&theme=" + theme));
|
||||
await page.locator("#gatewayKeys").waitFor({ state: "attached" });
|
||||
const got = await page.evaluate(() => ({
|
||||
meta: document.querySelector('meta[name="color-scheme"]')?.content || "",
|
||||
root: getComputedStyle(document.documentElement).colorScheme,
|
||||
body: getComputedStyle(document.body).colorScheme,
|
||||
theme: document.documentElement.dataset.theme || "system",
|
||||
}));
|
||||
assert.equal(got.theme, theme);
|
||||
assert.equal(words(got.meta), "dark light");
|
||||
assert.equal(words(got.root), "dark light");
|
||||
assert.equal(words(got.body), want[theme]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -339,7 +339,7 @@ func webTurnedAway(rw http.ResponseWriter, r *http.Request, back, why string) {
|
||||
rw.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
rw.Header().Set("Cache-Control", "no-store")
|
||||
rw.WriteHeader(http.StatusUnauthorized)
|
||||
fmt.Fprintf(rw, `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>magpie web</title>
|
||||
fmt.Fprintf(rw, `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light dark"><title>magpie web</title>
|
||||
<style>body{font:15px/1.5 system-ui,sans-serif;max-width:32em;margin:12vh auto;padding:0 16px;color:#222;background:#fafafa}@media(prefers-color-scheme:dark){body{color:#ddd;background:#1c1c1e}}input,button{font:inherit;padding:.4em .6em}input{width:100%%;box-sizing:border-box;margin:.5em 0}</style></head>
|
||||
<body><h1>magpie web</h1><p>%s</p><p>Paste the key (MAGPIE_WEB_KEY, or the k= in the link magpie web printed when it started):</p>
|
||||
<form method="post" action="%s"><input type="hidden" name="back" value="%s"><input type="password" name="key" autocomplete="current-password" autofocus required><button type="submit">Sign in</button></form></body></html>`,
|
||||
|
||||
@@ -1256,5 +1256,5 @@ func Cancel(id string) {
|
||||
func page(w http.ResponseWriter, status int, msg string) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
fmt.Fprintf(w, `<!doctype html><meta charset="utf-8"><title>Magpie</title><body style="font:15px -apple-system,system-ui,sans-serif;max-width:32em;margin:4em auto;padding:0 1em;color:#222">%s</body>`, html.EscapeString(msg))
|
||||
fmt.Fprintf(w, `<!doctype html><meta charset="utf-8"><meta name="color-scheme" content="light dark"><title>Magpie</title><body style="font:15px -apple-system,system-ui,sans-serif;max-width:32em;margin:4em auto;padding:0 1em">%s</body>`, html.EscapeString(msg))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package mcpauth
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The page an MCP sign-in ends on takes the reader's theme, and says so,
|
||||
// so a browser that repaints light pages dark leaves it alone (xjp on X).
|
||||
func TestPageDeclaresBothColorSchemes(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
page(rec, 200, "Signed in")
|
||||
b := rec.Body.String()
|
||||
if !strings.Contains(b, `<meta name="color-scheme" content="light dark">`) {
|
||||
t.Errorf("no color-scheme meta:\n%s", b)
|
||||
}
|
||||
if strings.Contains(b, "color:#222") {
|
||||
t.Errorf("a fixed dark text colour is unreadable on a dark canvas:\n%s", b)
|
||||
}
|
||||
}
|
||||
@@ -1018,8 +1018,9 @@ func signInPage(w http.ResponseWriter, ok bool, title, msg string) {
|
||||
mark = `<path d="M7 7l10 10M17 7L7 17"/>`
|
||||
}
|
||||
fmt.Fprintf(w, `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<title>magpie · %[1]s</title><style>
|
||||
:root{--bg:#fafafa;--fg:#111;--muted:#6b6b6b;--line:#e4e4e4;--card:#fff}
|
||||
:root{--bg:#fafafa;--fg:#111;--muted:#6b6b6b;--line:#e4e4e4;--card:#fff;color-scheme:light dark}
|
||||
@media (prefers-color-scheme:dark){:root{--bg:#0e0e0e;--fg:#f2f2f2;--muted:#9a9a9a;--line:#262626;--card:#161616}}
|
||||
*{box-sizing:border-box}html,body{height:100%%;margin:0}
|
||||
body{background:var(--bg);color:var(--fg);font:15px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif;display:grid;place-items:center;padding:16px}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The page a sign-in ends on draws a dark theme, and says so, so a browser
|
||||
// that repaints light pages dark leaves it alone (xjp on X).
|
||||
func TestSignInPageDeclaresBothColorSchemes(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
signInPage(rec, true, "Signed in", "You can close this tab.")
|
||||
if !strings.Contains(rec.Body.String(), `<meta name="color-scheme" content="light dark">`) {
|
||||
t.Errorf("no color-scheme meta:\n%s", rec.Body.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user