gui: a picked accent tints the theme's grounds (CHENGJIAHEGOXIS on X)

CHENGJIAHEGOXIS asked, on 0.1.4112 and again on 0.1.4116 ("依然没变,是不是
出bug了"), for the dark theme to follow the colour they picked. v0.1.4114
(a83fe2325) tinted only the chosen thumbs (--mark-fill). Their 0.1.4116
screenshot shows those thumbs purple, but the page, sidebar and cards are
still neutral grey: bg (25,25,27), card (32,32,34). Nothing tinted the
grounds.

lookCSS now also sets the theme's grounds from the picked colour.
- Window, light: --bg, --card-2, --pill, --pill-hover, --seg-track, --line,
  --line-2. Cards stay white.
- Window, dark: --bg, --card, --card-2, --pill, --pill-hover, --line,
  --line-2, plus the menus' --pop-bg.
- Tray panel: the body.panel grounds, in light and dark. tintPanel and the
  Windows title bar read --bg, so they follow.
Each ground takes 5% (light) or 8% (dark) of the colour's offset from its
own grey (base + k*(c - mean(c))). Lightness is kept, so a grey pick changes
nothing. With no accent, or under Omarchy, nothing is drawn.
accentOn and --mark are checked against the tinted grounds too.

Tests:
- TestAccentTintsGrounds covers:
  - every block is tinted;
  - lightness is kept (contrast to the base <= 1.1);
  - a grey pick changes nothing;
  - text is >= 7:1 and the accent >= 4.4:1 on the tinted --bg and --card,
    for many picks;
  - no accent gives no CSS.
- TestTintBasesAreAppCSS holds the Go bases to app.css.
- TestLookFixture holds tests/fixtures/look-accents.json to lookCSS
  (UPDATE=1 rewrites it).
- appearance-look.test.cjs now reads the real CSS from the fixture. A new
  case, in each engine and theme, picks a colour on Settings › General with
  and without a wallpaper, and checks:
  - the list, the sidebar and the body are tinted;
  - Default turns them grey again;
  - the panel's --bg is tinted.

Run on mote, at this commit rebased on origin/main 7b002b6be:
- gofmt -l internal/gui: clean.
- go vet -tags nogui ./internal/gui, the same with GOOS=linux, and
  GOOS=windows go vet ./internal/gui: ok.
- go test -tags nogui ./internal/gui: ok (126s).
- node --test, in both engines, of: appearance-look, omarchy,
  api-key-theme, checkbox-look, sidebar, settings-sections,
  settings-groups, i18n-keys, panel-options-fold and the seg-/theme files.
  Result: 120 of 138 pass. The 18 reds are api-key-theme (6, #6444),
  omarchy (#6027) and settings-groups' warm-ups case (#6597). On a fresh
  origin/main b005d1a47 the same three files give the same 18 reds.
- Screenshots in both engines: Settings › General, dark, zh, the reporter's
  purple #66258d. With no accent the ground is (26,26,30) and the card
  (35,35,39). Before this change the purple pick gives the same values.
  After it, the ground is (27,21,34) and the card (36,30,43).

Rebased on origin/main dc85a7ca5 (then e36541ddf, site/ only; 4 commits, none in appearance, app.css
or boot.js) and run again on mote at this head:
- go test -tags nogui -run 'TestAccent|TestLook|TestTint|TestWallpaper|Budget'
  ./internal/gui: ok.
- appearance-look and i18n-keys: 44 of 44.

Broken by hand: with both tints at 0.0 and the fixture regenerated,
TestAccentTintsGrounds fails and the four new GUI cases are red. Both pass
again with the change restored.

Not tried:
- the real macOS app, WebView2 and WebKitGTK;
- the full Go and GUI suites.
This commit is contained in:
yetone
2026-11-14 12:24:31 +08:00
parent e36541ddf2
commit 74c94b5db0
5 changed files with 282 additions and 20 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ three.
1. `magpie` with no arguments, `magpie app` or `magpie tray` calls `runGUI`, which starts the app's log (`startLog`, above) and calls `gui.Run`. A `nogui` build runs the TUI instead. A second launch hands over to the instance already running. On Windows, before any window is made, `webView2Check` asks Wails whether the WebView2 runtime is there (`Env.Info().PlatformInfo["WebView2"]`, "" when its lookup fails; a key Wails doesn't set counts as there). Without it Wails would exit on the first window with nothing on screen, so magpie logs it, shows a Windows message box in the reader's language naming the runtime, Microsoft's download page (`webView2Page`) and `magpie web` / `magpie tui`, opens the page on Yes, and `Run` ends (#1806, `webview2.go`, `TestWebView2MissingFromWails` on Windows). The box can't come from `ErrorHandler`, which runs on the thread Wails makes its windows on.
2. `startBackend` brings up the gateway, or finds another magpie serving it.
3. The panel and the window load `index.html` from `Handler`. `boot.js` passes the saved language, theme, colorblind mode, text size and desktop font choices before the first paint. It also puts in the look of the reader's own (`appearance.go`, CHENGJIAHEGOXIS on X): Settings › General's Accent color (`accent`, `#rrggbb`; `accentVars` darkens it on the light theme and lightens it on the dark one until it reads as text at 4.5:1; it also sets `--mark`, the ink of what is chosen: the open page's sidebar icon, a switch's or tab's chosen option, Library's switches and radios. `--mark` is `var(--fg)`, graphite, until the user picks an accent, so a picked colour shows on the page it is picked on) and Background image (a PNG, JPEG, GIF or WebP of 16 MB at most, saved as `wallpaper` in magpie's folder by `POST /api/appearance/wallpaper` as base64 JSON, `{remove: true}` to take it away; `settings.Wallpaper` is its stamp), drawn behind the window's pages under a veil of the theme's background, never in the tray panel or under Omarchy. `bootPrefs.look` says which look was drawn; `applyPrefs` asks `/api/appearance/css` again only when the settings' look differs, and the rows are drawn by the lazy `appearance.js` (`appearance-look.test.cjs`, `appearance_test.go`).
3. The panel and the window load `index.html` from `Handler`. `boot.js` passes the saved language, theme, colorblind mode, text size and desktop font choices before the first paint. It also puts in the look of the reader's own (`appearance.go`, CHENGJIAHEGOXIS on X): Settings › General's Accent color (`accent`, `#rrggbb`; `accentVars` darkens it on the light theme and lightens it on the dark one until it reads as text at 4.5:1; it also sets `--mark`, the ink of what is chosen: the open page's sidebar icon, a switch's or tab's chosen option, Library's switches and radios. `--mark` is `var(--fg)`, graphite, until the user picks an accent, so a picked colour shows on the page it is picked on. A picked colour also tints the theme's grounds, the window's and the tray panel's (`--bg`, `--card`, the pills, lines and the dark menus' `--pop-bg`; `tintVars`): each takes 5% (light) or 8% (dark) of the colour's hue, its own lightness kept, so a grey pick changes nothing and text keeps its contrast; with no accent, or under Omarchy, they are app.css's own. `TestTintBasesAreAppCSS` holds the Go bases to app.css, and `TestLookFixture` the GUI tests' `fixtures/look-accents.json` to `lookCSS`) and Background image (a PNG, JPEG, GIF or WebP of 16 MB at most, saved as `wallpaper` in magpie's folder by `POST /api/appearance/wallpaper` as base64 JSON, `{remove: true}` to take it away; `settings.Wallpaper` is its stamp), drawn behind the window's pages under a veil of the theme's background, never in the tray panel or under Omarchy. `bootPrefs.look` says which look was drawn; `applyPrefs` asks `/api/appearance/css` again only when the settings' look differs, and the rows are drawn by the lazy `appearance.js` (`appearance-look.test.cjs`, `appearance_test.go`).
4. The page reads `GET /api/state` and writes through `POST` routes. Each write answers with the new state, built under `held`.
5. Closing the window hides it. On the Mac a full-screen window first leaves full screen (`closeStep`). The system's close on the panel (a title bar's X, Alt+F4, a window manager's close key) hides it as Escape does, so the tray icon opens it again; a panel lightweight mode let go, no longer `h.panel`, closes (`makePanel`, `TestPanelCloseHidesIt`). A hidden macOS window keeps its WKWebView's page marked visible, so `hideWebview` tells the page it is out of sight before `orderOut`; that makes `document.hidden` and `visibilityState` true, stops the page's polling and frame loops, and pauses CSS animations. `showWebview` tells it it is visible again (#4293). Lightweight mode lets go only of a window closed this way: one covered by another app's window, minimised, or open as magpie was hidden is still open (`windowUp`, not Wails' `IsVisible`, which is the occlusion state), and so is it for the Dock while the window is open and for a restart (#1381, `TestCoveredWindowStaysUp`). On the Mac the tray icon and a usage cell close an open panel by the same test (`windowOpen` in `togglePanelNow` and `trayCellClick`, not Wails' `ToggleWindow`), so under a window over the whole screen, such as a remote-desktop server's privacy curtain, the icon still closes the panel instead of showing it again (#1661, `TestTrayCellClickReleasedPanel`). On Windows a hidden window's WebView2 is put on its low memory target (`lowWhileHidden`, [`memtarget_windows.go`](../../internal/gui/memtarget_windows.go): `ICoreWebView2_19::put_MemoryUsageTargetLevel`, on each hide, on a page that comes while hidden, and back to normal on each show), so the panel and the window kept loaded in the tray stop holding what they last drew; the page stays loaded and running, unlike lightweight mode. In the tray the WebView2 processes' private working set went from ~170 MB to 20 to 40 MB, while their commit charge stayed where it was (molamaker11 on X). WKWebView and WebKitGTK have nothing magpie can set for it.
6. The window opens as it was last left. Its settled size and whether it was maximised are kept in `settings.Window` and `settings.WindowMaximised` (`settle`; per machine, see `KeepOwn`). A maximised window keeps the size it restores to. `makeMain` opens it at that size (`openSize`). On its first show, `placeMain` maximises it again on the Mac and Windows (on Windows once the page has come). On Linux, `makeMain` makes it maximised with `StartState`. On Windows a size larger than the screen's work area is fitted and centred (`fitRoom`), and the larger size stays kept. Where it was left is kept too, in `settings.WindowAt` (its top left corner across every screen, in the system's coordinates), so after a restart or an update it opens there rather than in the middle (jorbenzhu on Discord). `keepAt` saves it once a move or resize has rested for half a second, unless the window is maximised, full screen, minimised or hidden; `settings.Save` writes through temp and rename, and a settings file that can't be read is left alone. On its first show `placeMain` puts it back (`putBack`): `openAt` takes the screen holding most of the window, moves the window fully onto that screen's work area, and leaves it centred when no screen holds any of it, such as a monitor that is gone, or when the screens or the file can't be read (`TestOpenAt`). Under Wayland a window can't place itself, so nothing is kept or put back there unless GDK_BACKEND is x11 (`keepsPlace`, `TestKeepsPlace`). The tray's panel isn't kept: on the Mac and Windows it opens under the tray icon, and on Linux where the click was.
+66 -6
View File
@@ -58,10 +58,18 @@ func lookKey(s settings.Settings) string {
func lookCSS(s settings.Settings) string {
var b strings.Builder
if c, ok := parseHex(s.Accent); ok {
light, dark := accentVars(c, false), accentVars(c, true)
light := accentVars(c, false) + ";" + tintVars(c, lightSurfaces, lightTint)
dark := accentVars(c, true) + ";" + tintVars(c, darkSurfaces, darkTint) + ";" + popVar(c)
fmt.Fprintf(&b, "html:not(.omarchy):root{%s}\n", light)
fmt.Fprintf(&b, "@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]){%s}}\n", dark)
fmt.Fprintf(&b, "html:not(.omarchy):root[data-theme=\"dark\"]{%s}\n", dark)
// the tray panel draws its surfaces on body.panel, so they are
// tinted there too, the frosted panel's tint (tintPanel) with them
lightP, darkP := tintVars(c, lightPanelSurfaces, lightTint), tintVars(c, darkPanelSurfaces, darkTint)
fmt.Fprintf(&b, "@media (prefers-color-scheme: light){html:not(.omarchy):root:not([data-theme=\"dark\"]) body.panel{%s}}\n", lightP)
fmt.Fprintf(&b, "html:not(.omarchy):root[data-theme=\"light\"] body.panel{%s}\n", lightP)
fmt.Fprintf(&b, "@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]) body.panel{%s}}\n", darkP)
fmt.Fprintf(&b, "html:not(.omarchy):root[data-theme=\"dark\"] body.panel{%s}\n", darkP)
}
if s.Wallpaper != 0 {
if fi, err := os.Stat(settings.WallpaperPath()); err == nil && fi.Mode().IsRegular() {
@@ -142,12 +150,13 @@ var (
)
// accentOn is c, darkened (light theme) or lightened (dark theme) just
// enough to read as text on that theme's background and cards.
// enough to read as text on that theme's background and cards, grey or
// tinted with c.
func accentOn(c rgb, dark bool) rgb {
if dark {
return inkOn(c, white, darkCard)
return inkOn(c, white, darkCard, tint(darkCard, c, darkTint), tint(darkBg, c, darkTint))
}
return inkOn(c, black, lightBg)
return inkOn(c, black, lightBg, tint(lightBg, c, lightTint))
}
// inkOn is c moved toward toward just enough to read as text on each of
@@ -186,15 +195,66 @@ func accentVars(c rgb, dark bool) string {
}
soft, sel := white.mix(a, 0.09), white.mix(a, 0.11)
fill := white.mix(a, 0.12)
mark := inkOn(c, black, lightPick, fill)
mark := inkOn(c, black, lightPick, tint(lightPick, c, lightTint), fill)
if dark {
soft, sel = darkBg.mix(a, 0.14), darkBg.mix(a, 0.2)
fill = darkFill.mix(a, 0.26)
mark = inkOn(c, white, darkPick, fill)
mark = inkOn(c, white, darkPick, tint(darkPick, c, darkTint), fill)
}
return fmt.Sprintf("--accent:%s;--accent-soft:%s;--accent-fg:%s;--sel:%s;--mark:%s;--mark-fill:%s", a.hex(), soft.hex(), fg.hex(), sel.hex(), mark.hex(), fill.hex())
}
// surface is one of a theme's grounds, as app.css draws it without an
// accent: its token and colour.
type surface struct {
name string
base rgb
}
// The themes' grounds (app.css :root and its dark blocks, and body.panel's
// own in each theme). The light theme's cards stay white, as on a Mac.
var (
lightSurfaces = []surface{{"--bg", lightBg}, {"--card-2", rgb{0xf9, 0xf9, 0xfb}}, {"--pill", rgb{0xf1, 0xf1, 0xf4}}, {"--pill-hover", lightPick}, {"--seg-track", rgb{0xe6, 0xe6, 0xeb}}, {"--line", rgb{0xe3, 0xe3, 0xe8}}, {"--line-2", rgb{0xec, 0xec, 0xf0}}}
darkSurfaces = []surface{{"--bg", darkBg}, {"--card", darkCard}, {"--card-2", rgb{0x1f, 0x1f, 0x23}}, {"--pill", rgb{0x2d, 0x2d, 0x33}}, {"--pill-hover", rgb{0x36, 0x36, 0x3d}}, {"--line", rgb{0x33, 0x33, 0x39}}, {"--line-2", rgb{0x2c, 0x2c, 0x32}}}
// --pop-bg, a menu's ground, is translucent: rgba(38, 38, 43, .96)
darkPop = rgb{38, 38, 43}
lightPanelSurfaces = []surface{{"--bg", rgb{0xf2, 0xf2, 0xf5}}, {"--card-2", rgb{0xf8, 0xf8, 0xfa}}, {"--pill-hover", rgb{0xf4, 0xf4, 0xf7}}, {"--skel", rgb{0xee, 0xee, 0xf2}}, {"--skel-hi", rgb{0xe2, 0xe2, 0xe8}}}
darkPanelSurfaces = []surface{{"--bg", rgb{0x1b, 0x1c, 0x20}}, {"--card", rgb{0x25, 0x26, 0x2c}}, {"--card-2", rgb{0x21, 0x22, 0x27}}, {"--pill", rgb{0x2e, 0x2f, 0x36}}, {"--pill-hover", rgb{0x38, 0x39, 0x42}}}
// how much of the colour's hue the grounds take: enough that the dark
// theme reads as the colour's, not grey (CHENGJIAHEGOXIS on X, 「目前我
// 个人感觉深色比较灰」), and only a breath of it on the light theme
lightTint = 0.05
darkTint = 0.08
)
// tint is base with k of c's hue added: c less its own grey, so the ground
// keeps its lightness (text on it reads as before) and a grey pick leaves
// it as it was.
func tint(base, c rgb, k float64) rgb {
g := (c[0] + c[1] + c[2]) / 3
var out rgb
for i := range out {
out[i] = min(255, max(0, base[i]+(c[i]-g)*k))
}
return out
}
// tintVars are surfaces tinted with c's hue, the theme's grounds once the user picked a colour of
// their own. Without one each keeps app.css's grey.
func tintVars(c rgb, surfaces []surface, k float64) string {
parts := make([]string, 0, len(surfaces))
for _, s := range surfaces {
parts = append(parts, s.name+":"+tint(s.base, c, k).hex())
}
return strings.Join(parts, ";")
}
// popVar is the dark theme's menu ground, tinted as its other grounds are.
func popVar(c rgb) string {
p := tint(darkPop, c, darkTint)
return fmt.Sprintf("--pop-bg:rgba(%d,%d,%d,.96)", int(math.Round(p[0])), int(math.Round(p[1])), int(math.Round(p[2])))
}
// appearanceRoutes serve the look's stylesheet and the wallpaper, and take
// a picture chosen or removed.
func appearanceRoutes(mux *http.ServeMux) {
+146
View File
@@ -221,3 +221,149 @@ func TestWallpaperStampWithoutFile(t *testing.T) {
t.Fatalf("magpie's own look drew: %s", css)
}
}
// A colour of the user's own tints the theme's grounds, not only what is
// chosen: the dark theme read as grey with a purple picked (CHENGJIAHEGOXIS
// on X, 「目前我个人感觉深色比较灰」, then 「依然没变」 on v0.1.4116 with the
// thumbs tinted). magpie's own look, and a grey pick, keep app.css's grey.
func TestAccentTintsGrounds(t *testing.T) {
vars := func(css, sel string) map[string]string {
i := strings.Index(css, sel+"{")
if i < 0 {
t.Fatalf("no %s in %s", sel, css)
}
body := css[i+len(sel)+1:]
body = body[:strings.IndexByte(body, '}')]
out := map[string]string{}
for _, kv := range strings.Split(body, ";") {
if k, v, ok := strings.Cut(kv, ":"); ok {
out[k] = v
}
}
return out
}
if css := lookCSS(settings.Settings{}); css != "" {
t.Fatalf("magpie's own look draws %q", css)
}
css := lookCSS(settings.Settings{Accent: "#7c3aed"})
for _, c := range []struct {
sel string
surfaces []surface
}{
{`html:not(.omarchy):root`, lightSurfaces},
{`html:not(.omarchy):root[data-theme="dark"]`, darkSurfaces},
{`html:not(.omarchy):root:not([data-theme="light"])`, darkSurfaces},
{`html:not(.omarchy):root[data-theme="light"] body.panel`, lightPanelSurfaces},
{`html:not(.omarchy):root:not([data-theme="dark"]) body.panel`, lightPanelSurfaces},
{`html:not(.omarchy):root[data-theme="dark"] body.panel`, darkPanelSurfaces},
{`html:not(.omarchy):root:not([data-theme="light"]) body.panel`, darkPanelSurfaces},
} {
v := vars(css, c.sel)
for _, s := range c.surfaces {
got, ok := parseHex(v[s.name])
if !ok {
t.Fatalf("%s: no %s in %v", c.sel, s.name, v)
}
// purple: more blue than green, and about as light as before
if got[2]-got[1] < 6 {
t.Errorf("%s %s: %s is still grey (was %s)", c.sel, s.name, got.hex(), s.base.hex())
}
if r := contrast(got, s.base); r > 1.1 {
t.Errorf("%s %s: %s is not as light as %s", c.sel, s.name, got.hex(), s.base.hex())
}
}
}
if !strings.Contains(vars(css, `html:not(.omarchy):root[data-theme="dark"]`)["--pop-bg"], "rgba(") {
t.Errorf("the dark theme's menus keep their grey: %s", css)
}
// a grey pick leaves the grounds as they were
g, _ := parseHex("#808080")
for _, s := range darkSurfaces {
if got := tint(s.base, g, darkTint); got.hex() != s.base.hex() {
t.Errorf("grey tints %s: %s", s.name, got.hex())
}
}
// text and the accent read on the tinted grounds, for any pick
for _, pick := range []string{"#ffffff", "#000000", "#ffff00", "#00ff00", "#ff0000", "#0000ff", "#7c3aed", "#0d9488", "#db2777"} {
c, _ := parseHex(pick)
for _, dark := range []bool{false, true} {
surfaces, k, fg, accent := lightSurfaces, lightTint, rgb{0x1c, 0x1c, 0x21}, accentOn(c, false)
if dark {
surfaces, k, fg, accent = darkSurfaces, darkTint, rgb{0xed, 0xed, 0xf1}, accentOn(c, true)
}
for _, s := range surfaces {
if strings.HasPrefix(s.name, "--line") || s.name == "--seg-track" {
continue
}
bg := tint(s.base, c, k)
if r := contrast(fg, bg); r < 7 {
t.Errorf("%s dark=%v: text on %s %s is %.2f:1", pick, dark, s.name, bg.hex(), r)
}
if s.name == "--bg" || s.name == "--card" {
if r := contrast(accent, bg); r < 4.4 {
t.Errorf("%s dark=%v: accent %s on %s %s is %.2f:1", pick, dark, accent.hex(), s.name, bg.hex(), r)
}
}
}
}
}
}
// The grounds tinted are app.css's own, so a theme changed there is
// changed here too.
func TestTintBasesAreAppCSS(t *testing.T) {
b, err := os.ReadFile("assets/app.css")
if err != nil {
t.Fatal(err)
}
css := string(b)
block := func(sel string) string {
i := strings.Index(css, sel+" {")
if i < 0 {
t.Fatalf("no %q in app.css", sel)
}
s := css[i:]
return s[:strings.IndexByte(s, '}')]
}
for _, c := range []struct {
sel string
surfaces []surface
}{
{":root", lightSurfaces},
{`:root[data-theme="dark"]`, darkSurfaces},
{`:root[data-theme="light"] body.panel`, lightPanelSurfaces},
{`:root[data-theme="dark"] body.panel`, darkPanelSurfaces},
} {
blk := block(c.sel)
for _, s := range c.surfaces {
if !regexp.MustCompile(regexp.QuoteMeta(s.name) + `:\s*` + s.base.hex() + `;`).MatchString(blk) {
t.Errorf("%s: app.css's %s is not %s", c.sel, s.name, s.base.hex())
}
}
}
if !strings.Contains(block(`:root[data-theme="dark"]`), "--pop-bg: rgba(38, 38, 43, .96)") {
t.Errorf("app.css's dark --pop-bg is not rgba(38, 38, 43, .96)")
}
}
// The GUI test's stand-in server hands the page lookCSS's own stylesheet
// for the colours it picks (tests/fixtures/look-accents.json). UPDATE=1
// writes it again.
func TestLookFixture(t *testing.T) {
want := map[string]string{}
for _, a := range []string{"#0d9488", "#db2777", "#7c3aed"} {
want[a] = lookCSS(settings.Settings{Accent: a})
}
b, _ := json.MarshalIndent(want, "", " ")
b = append(b, '\n')
const path = "tests/fixtures/look-accents.json"
if os.Getenv("UPDATE") == "1" {
if err := os.WriteFile(path, b, 0o644); err != nil {
t.Fatal(err)
}
}
got, err := os.ReadFile(path)
if err != nil || !bytes.Equal(got, b) {
t.Fatalf("%s is not lookCSS's (UPDATE=1 go test -run TestLookFixture writes it): %v", path, err)
}
}
+64 -13
View File
@@ -21,14 +21,17 @@ const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
// a 1×1 PNG
const PNG = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", "base64");
// as appearance.go's lookCSS draws it: the light theme's, then the dark
// one's, --mark the ink of what is chosen and --mark-fill the thumb under it
const DARK = { "#0d9488": "#5cc9bd", "#db2777": "#f08cbd", "#7c3aed": "#c4a6f8" };
const FILL = { "#0d9488": ["#e2efee", "#325354"], "#db2777": ["#f9e5ee", "#664155"], "#7c3aed": ["#efe7fd", "#55486e"] };
const fill = (a, dark) => (FILL[a] || ["#eeeeee", "#444444"])[dark ? 1 : 0];
const accentCSS = (a) => (a ? `html:not(.omarchy):root{--accent:${a};--accent-soft:#e6f4f2;--accent-fg:#ffffff;--sel:#e1f1ef;--mark:${a};--mark-fill:${fill(a)}}
@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme="light"]){--accent:${DARK[a] || a};--accent-soft:#1a2c2e;--accent-fg:#14141a;--sel:#1a3435;--mark:${DARK[a] || a};--mark-fill:${fill(a, 1)}}}
html:not(.omarchy):root[data-theme="dark"]{--accent:${DARK[a] || a};--accent-soft:#1a2c2e;--accent-fg:#14141a;--sel:#1a3435;--mark:${DARK[a] || a};--mark-fill:${fill(a, 1)}}` : "");
// appearance.go's lookCSS for the colours picked here, as it draws them
// (TestLookFixture keeps the file its own): the light theme's block first,
// then the dark one's, --mark the ink of what is chosen, --mark-fill the
// thumb under it, and the grounds tinted with the colour
const LOOK = require("./fixtures/look-accents.json");
const varOf = (a, name, dark) => {
const blocks = LOOK[a].split("\n");
const m = blocks[dark ? 2 : 0].match(new RegExp(`${name}:([^;}]+)`));
return m && m[1];
};
const accentCSS = (a) => (a ? LOOK[a] : "");
function serve(st, log) {
const settings = () => ({ lang: "en", theme: "light", searchVendors: [], searchAPIs: [], ...st });
@@ -106,7 +109,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(log.filter(([k]) => k === "css"), [], "magpie's own look needs no stylesheet");
await page.locator('#accentPick .swatch[data-accent="#0d9488"]').click();
await page.waitForFunction(() => getComputedStyle(document.documentElement).getPropertyValue("--accent").trim() === "#0d9488");
await page.waitForFunction((w) => getComputedStyle(document.documentElement).getPropertyValue("--accent").trim() === w, varOf("#0d9488", "--accent"));
assert.equal(log.find(([k]) => k === "settings")[1].accent, "#0d9488");
await page.waitForFunction(() => document.querySelector("#accentPick .swatch.on")?.dataset.accent === "#0d9488");
@@ -165,14 +168,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const card = await page.evaluate(() => { const p = document.createElement("i"); p.style.background = "var(--card)"; document.body.append(p); const c = getComputedStyle(p).backgroundColor; p.remove(); return c; });
assert.deepEqual(await grounds(), thumbs.map(() => card), "magpie's own look: the thumb is the card's grey");
const rgbOf = (h) => `rgb(${parseInt(h.slice(1, 3), 16)}, ${parseInt(h.slice(3, 5), 16)}, ${parseInt(h.slice(5, 7), 16)})`;
for (const [v, light] of [["#0d9488", "#0d9488"], ["#db2777", "#db2777"]]) {
for (const v of ["#0d9488", "#db2777"]) {
await page.locator(`#accentPick .swatch[data-accent="${v}"]`).click();
const want = theme === "dark" ? DARK[v] : light;
const want = varOf(v, "--mark", theme === "dark");
await page.waitForFunction((w) => getComputedStyle(document.documentElement).getPropertyValue("--mark").trim() === w, want);
const r = await settled(page, sel);
assert.notEqual(r.mark, r.fg);
same(r, r.mark, `${v}: what is chosen is in the colour picked`);
assert.deepEqual(await grounds(), thumbs.map(() => rgbOf(fill(v, theme === "dark"))), `${v}: the chosen thumb is tinted`);
assert.deepEqual(await grounds(), thumbs.map(() => rgbOf(varOf(v, "--mark-fill", theme === "dark"))), `${v}: the chosen thumb is tinted`);
}
await page.locator('#accentPick .swatch[data-accent=""]').click();
await page.waitForFunction(() => !document.getElementById("lookCSS")?.textContent);
@@ -196,13 +199,61 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
}
}
});
// CHENGJIAHEGOXIS on X: 「目前我个人感觉深色比较灰」, and on v0.1.4116,
// with the chosen thumbs tinted, 「依然没变」. The theme's own grounds
// (the page, the sidebar, Settings' list, the panel) take the colour's
// hue once one is picked, and are app.css's grey again on Default.
test(`${engine}: ${theme}, a colour picked tints the theme's grounds, in the window and the panel`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const rgbOf = (h) => `rgb(${parseInt(h.slice(1, 3), 16)}, ${parseInt(h.slice(3, 5), 16)}, ${parseInt(h.slice(5, 7), 16)})`;
const dark = theme === "dark";
// the window, as in the report: Settings › General at 1200 with the
// sidebar, with and without a picture behind the pages
for (const wallpaper of [0, 1700000000000]) {
const { page, errors } = await open(browser, { theme, wallpaper }, 1200);
await page.waitForFunction(() => document.body.classList.contains("side-nav"));
const grounds = () => page.evaluate(() => {
const bg = (e) => (e ? getComputedStyle(e).backgroundColor : "missing");
return { list: bg(document.querySelector("#setPage-general .list.prefs")), sidebar: bg(document.querySelector(".sidebar")), body: getComputedStyle(document.body).backgroundColor };
});
const grey = await grounds();
await page.locator('#accentPick .swatch[data-accent="#db2777"]').click();
await page.waitForFunction((w) => getComputedStyle(document.documentElement).getPropertyValue("--mark").trim() === w, varOf("#db2777", "--mark", dark));
const pink = await grounds();
const card = varOf("#db2777", dark ? "--card" : "--bg", dark);
if (dark) assert.equal(pink.list, rgbOf(card), "Settings' list is on the tinted card");
assert.notEqual(pink.list === grey.list && pink.sidebar === grey.sidebar && pink.body === grey.body, true, `wallpaper=${wallpaper}: something tinted`);
if (!wallpaper) {
assert.equal(pink.body, rgbOf(varOf("#db2777", "--bg", dark)), "the page's ground is tinted");
assert.equal(pink.sidebar, rgbOf(varOf("#db2777", "--bg", dark)), "the sidebar's ground is tinted");
}
await page.locator('#accentPick .swatch[data-accent=""]').click();
await page.waitForFunction(() => !document.getElementById("lookCSS")?.textContent);
assert.deepEqual(await grounds(), grey, "back to magpie's own grey");
assert.deepEqual(errors, []);
await page.context().close();
}
// the panel draws its own grounds on body.panel: tinted too
const panelBg = async (accent) => {
const { page, errors } = await open(browser, { theme, accent }, 380, "mode=panel", ".ptabs button.on");
const v = await page.evaluate(() => { const p = document.createElement("i"); p.style.background = "var(--bg)"; document.body.append(p); const c = getComputedStyle(p).backgroundColor; p.remove(); return c; });
assert.deepEqual(errors, []);
await page.context().close();
return v;
};
const plain = await panelBg(""), tinted = await panelBg("#db2777");
assert.notEqual(tinted, plain, "the panel's ground is tinted");
const want = LOOK["#db2777"].match(new RegExp(`root\\[data-theme="${theme}"\\] body\\.panel\\{--bg:(#[0-9a-f]{6})`))[1];
assert.equal(tinted, rgbOf(want));
});
}
test(`${engine}: a look boot.js drew is not asked for again`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const { page, errors, log } = await open(browser, { accent: "#0d9488" }, 1000);
assert.equal(await accentNow(page), "#0d9488", "drawn before the first paint");
assert.equal(await accentNow(page), varOf("#0d9488", "--accent"), "drawn before the first paint");
assert.deepEqual(await chosen(page), ["#0d9488"]);
await page.waitForTimeout(300);
assert.deepEqual(log.filter(([k]) => k === "css"), []);
+5
View File
@@ -0,0 +1,5 @@
{
"#0d9488": "html:not(.omarchy):root{--accent:#0b7c72;--accent-soft:#e9f3f2;--accent-fg:#ffffff;--sel:#e4f1f0;--mark:#0a766d;--mark-fill:#e2efee;--bg:#f0f6f8;--card-2:#f5fbfd;--pill:#edf3f6;--pill-hover:#e5ebf0;--seg-track:#e2e8ed;--line:#dfe5ea;--line-2:#e8eef2}\n@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]){--accent:#209d92;--accent-soft:#1b2c2e;--accent-fg:#14141a;--sel:#1b3435;--mark:#8bccc6;--mark-fill:#335454;--bg:#131e21;--card:#1c272a;--card-2:#182326;--pill:#263136;--pill-hover:#2f3a40;--line:#2c373c;--line-2:#253035;--pop-bg:rgba(31,42,46,.96)}}\nhtml:not(.omarchy):root[data-theme=\"dark\"]{--accent:#209d92;--accent-soft:#1b2c2e;--accent-fg:#14141a;--sel:#1b3435;--mark:#8bccc6;--mark-fill:#335454;--bg:#131e21;--card:#1c272a;--card-2:#182326;--pill:#263136;--pill-hover:#2f3a40;--line:#2c373c;--line-2:#253035;--pop-bg:rgba(31,42,46,.96)}\n@media (prefers-color-scheme: light){html:not(.omarchy):root:not([data-theme=\"dark\"]) body.panel{--bg:#eef4f7;--card-2:#f4fafc;--pill-hover:#f0f6f9;--skel:#eaf0f4;--skel-hi:#dee4ea}}\nhtml:not(.omarchy):root[data-theme=\"light\"] body.panel{--bg:#eef4f7;--card-2:#f4fafc;--pill-hover:#f0f6f9;--skel:#eaf0f4;--skel-hi:#dee4ea}\n@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]) body.panel{--bg:#142023;--card:#1e2a2f;--card-2:#1a262a;--pill:#273339;--pill-hover:#313d45}}\nhtml:not(.omarchy):root[data-theme=\"dark\"] body.panel{--bg:#142023;--card:#1e2a2f;--card-2:#1a262a;--pill:#273339;--pill-hover:#313d45}\n",
"#7c3aed": "html:not(.omarchy):root{--accent:#7c3aed;--accent-soft:#f3edfd;--accent-fg:#ffffff;--sel:#f1e9fd;--mark:#7c3aed;--mark-fill:#efe7fd;--bg:#f3f0fb;--card-2:#f8f5ff;--pill:#f0edf9;--pill-hover:#e8e5f3;--seg-track:#e5e2f0;--line:#e2dfed;--line-2:#ebe8f5}\n@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]){--accent:#a171f2;--accent-soft:#2d263c;--accent-fg:#14141a;--sel:#352b48;--mark:#cdb4f8;--mark-fill:#55486e;--bg:#191326;--card:#221c2f;--card-2:#1e182b;--pill:#2c263b;--pill-hover:#352f45;--line:#322c41;--line-2:#2b253a;--pop-bg:rgba(37,31,51,.96)}}\nhtml:not(.omarchy):root[data-theme=\"dark\"]{--accent:#a171f2;--accent-soft:#2d263c;--accent-fg:#14141a;--sel:#352b48;--mark:#cdb4f8;--mark-fill:#55486e;--bg:#191326;--card:#221c2f;--card-2:#1e182b;--pill:#2c263b;--pill-hover:#352f45;--line:#322c41;--line-2:#2b253a;--pop-bg:rgba(37,31,51,.96)}\n@media (prefers-color-scheme: light){html:not(.omarchy):root:not([data-theme=\"dark\"]) body.panel{--bg:#f1eefa;--card-2:#f7f4ff;--pill-hover:#f3f0fc;--skel:#edeaf7;--skel-hi:#e1deed}}\nhtml:not(.omarchy):root[data-theme=\"light\"] body.panel{--bg:#f1eefa;--card-2:#f7f4ff;--pill-hover:#f3f0fc;--skel:#edeaf7;--skel-hi:#e1deed}\n@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]) body.panel{--bg:#1a1528;--card:#241f34;--card-2:#201b2f;--pill:#2d283e;--pill-hover:#37324a}}\nhtml:not(.omarchy):root[data-theme=\"dark\"] body.panel{--bg:#1a1528;--card:#241f34;--card-2:#201b2f;--pill:#2d283e;--pill-hover:#37324a}\n",
"#db2777": "html:not(.omarchy):root{--accent:#ce2570;--accent-soft:#fbebf2;--accent-fg:#ffffff;--sel:#fae7ef;--mark:#c12269;--mark-fill:#f9e5ee;--bg:#f9f0f6;--card-2:#fef5fb;--pill:#f6edf4;--pill-hover:#eee5ee;--seg-track:#ebe2eb;--line:#e8dfe8;--line-2:#f1e8f0}\n@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]){--accent:#e35795;--accent-soft:#36222f;--accent-fg:#14141a;--sel:#422636;--mark:#f1a9c9;--mark-fill:#664155;--bg:#21131d;--card:#2a1c26;--card-2:#261822;--pill:#342632;--pill-hover:#3d2f3c;--line:#3a2c38;--line-2:#332531;--pop-bg:rgba(45,31,42,.96)}}\nhtml:not(.omarchy):root[data-theme=\"dark\"]{--accent:#e35795;--accent-soft:#36222f;--accent-fg:#14141a;--sel:#422636;--mark:#f1a9c9;--mark-fill:#664155;--bg:#21131d;--card:#2a1c26;--card-2:#261822;--pill:#342632;--pill-hover:#3d2f3c;--line:#3a2c38;--line-2:#332531;--pop-bg:rgba(45,31,42,.96)}\n@media (prefers-color-scheme: light){html:not(.omarchy):root:not([data-theme=\"dark\"]) body.panel{--bg:#f7eef5;--card-2:#fdf4fa;--pill-hover:#f9f0f7;--skel:#f3eaf2;--skel-hi:#e7dee8}}\nhtml:not(.omarchy):root[data-theme=\"light\"] body.panel{--bg:#f7eef5;--card-2:#fdf4fa;--pill-hover:#f9f0f7;--skel:#f3eaf2;--skel-hi:#e7dee8}\n@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme=\"light\"]) body.panel{--bg:#22151f;--card:#2c1f2b;--card-2:#281b26;--pill:#352835;--pill-hover:#3f3241}}\nhtml:not(.omarchy):root[data-theme=\"dark\"] body.panel{--bg:#22151f;--card:#2c1f2b;--card-2:#281b26;--pill:#352835;--pill-hover:#3f3241}\n"
}