gui: a picked accent colours what is chosen (CHENGJIAHEGOXIS on X)
「选中任意强调色没反应」: picking an accent in Settings › General seemed
to do nothing. The token did apply. With the real server, in Chromium
and WebKit, under light, dark and system, with and without a background
image, --accent was set by lookCSS and kept. Neither the theme nor the
wallpaper overrode it. But nothing on Settings, the sidebar, the header
tabs or the panel's tabs used --accent: every chosen option is graphite,
var(--fg), by design. So the colour only showed in a few buttons
elsewhere.
The fix is a --mark token, the ink of what is chosen.
- It is var(--fg) by default, so magpie's own look is unchanged, like a
Mac's Graphite.
- accentVars sets it once the user picks an accent. It is moved toward
black (light) or white (dark) until it reads at 4.5:1 on the surfaces a
chosen option sits on: --pill-hover #e9e9ee, and the dark switch thumb
#4c4c52.
- It is used by .seg/.opt/.ptabs/.warm-tabs/.am-seg/.klf-tab/.day-chip/
.apptab .on, the header nav's chosen tab, the side-nav's open-page icon
and Settings icon, and Library's switches and radios. Each is the same
"chosen" role, so all of them follow the accent, not just one.
Tests:
- appearance_test.go's TestAccentReadable checks --mark's contrast on
each surface, in both themes.
- appearance-look.test.cjs adds 8 tests, in Chromium and WebKit, light
and dark:
- Settings' theme and bird options and the side-nav icon at 1200 with a
wallpaper set: graphite by default, the mark for #0d9488 and #db2777,
and back to graphite on Default.
- The header tabs at 900 and the panel's tabs at 380.
Run:
- gofmt clean. go vet ok on darwin, GOOS=linux -tags nogui and
GOOS=windows (at 75bdc85fe, the same change on an older main).
- At 6f5549b1f (this change on 08f77528f), on Linux (WSL magpie-desktop),
since mote's suite queue was hours deep:
- The whole GUI suite, Chromium and WebKit, every language and the
panel widths: 27231 tests, 1258 red in 183 files. The same 183 files
at the parent were 1226 red. The 70 tests red only with the change
were rerun with their 43 files at concurrency 2: 80 red with it, 89
at the parent 783b69b8c. Every one left has a language or width
sibling red at the parent too. None is about colour. They are the
Linux reds #5559 and #4388 track.
- go test -tags nogui ./... -timeout 45m: every package ok except
internal/usage's TestRequestStateKeptAcrossACatalogFetchedAgain,
red the same at the parent (#6572).
- At the pushed head, on mote (macOS):
- TestAccent*, TestWallpaper*, TestLook* ok.
- appearance-look 36/36, i18n-keys 4/4, library-all 26/26.
- segs-press-redraw 16 red and api-key-theme 6/6 red, the same counts
at the parent 6c88d61f0 (#4566, #3922, #6444).
- TestCoreScriptBudget is red (1269382 > 1268961), the same at the
parent. 92e760f3d took it over (#6518, taken). This change adds no
script.
- Broken by hand:
- With the old app.css and library.css, the 8 new GUI tests are red,
8 of 8.
- accentVars without --mark: TestAccentReadable fails ("…;--sel:#efefef",
no mark).
Not tried:
- The whole GUI suite and the Go suite on macOS at the pushed head. mote's
suite.lock queue was hours deep, so they ran on Linux instead.
- The real macOS app.
- Windows WebView2, and Linux WebKitGTK.
- Charts' --c1 series colour still does not follow the accent; that is
left as it was.
This commit is contained in:
@@ -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) 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) 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.
|
||||
|
||||
@@ -129,6 +129,11 @@ var (
|
||||
darkBg = rgb{0x1a, 0x1a, 0x1e}
|
||||
darkCard = rgb{0x23, 0x23, 0x27}
|
||||
accentInk = 4.5 // WCAG AA for text: the accent is a link's colour too
|
||||
// the surfaces a chosen option's text sits on (--mark): the light
|
||||
// theme's darkest, a tab's --pill-hover, and the dark theme's lightest,
|
||||
// the header switch's thumb (--seg-thumb over --seg-track)
|
||||
lightPick = rgb{0xe9, 0xe9, 0xee}
|
||||
darkPick = rgb{0x4c, 0x4c, 0x52}
|
||||
// how much of the theme's background lies over the picture
|
||||
wallVeil = "color-mix(in srgb,var(--bg) 84%,transparent)"
|
||||
)
|
||||
@@ -136,10 +141,14 @@ var (
|
||||
// accentOn is c, darkened (light theme) or lightened (dark theme) just
|
||||
// enough to read as text on that theme's background and cards.
|
||||
func accentOn(c rgb, dark bool) rgb {
|
||||
toward, against := black, lightBg
|
||||
if dark {
|
||||
toward, against = white, darkCard
|
||||
return inkOn(c, white, darkCard)
|
||||
}
|
||||
return inkOn(c, black, lightBg)
|
||||
}
|
||||
|
||||
// inkOn is c moved toward toward just enough to read as text on against.
|
||||
func inkOn(c, toward, against rgb) rgb {
|
||||
out := c
|
||||
for p := 0.0; p <= 1 && contrast(out, against) < accentInk; p += 0.02 {
|
||||
out = c.mix(toward, p)
|
||||
@@ -147,8 +156,12 @@ func accentOn(c rgb, dark bool) rgb {
|
||||
return out
|
||||
}
|
||||
|
||||
// accentVars are the theme's --accent, its soft fill, the text on it and
|
||||
// the selection, from c.
|
||||
// accentVars are the theme's --accent, its soft fill, the text on it, the
|
||||
// selection, and --mark, from c. --mark is the ink of what is chosen (the
|
||||
// open page's sidebar icon, a switch's or tab's chosen option), magpie's
|
||||
// own text colour without an accent of the user's, as a Mac's Graphite:
|
||||
// without it a colour picked showed nowhere on Settings, nor on most pages
|
||||
// (CHENGJIAHEGOXIS on X, 「选中任意强调色没反应」).
|
||||
func accentVars(c rgb, dark bool) string {
|
||||
a := accentOn(c, dark)
|
||||
fg := white
|
||||
@@ -156,10 +169,12 @@ func accentVars(c rgb, dark bool) string {
|
||||
fg = rgb{0x14, 0x14, 0x1a}
|
||||
}
|
||||
soft, sel := white.mix(a, 0.09), white.mix(a, 0.11)
|
||||
mark := inkOn(c, black, lightPick)
|
||||
if dark {
|
||||
soft, sel = darkBg.mix(a, 0.14), darkBg.mix(a, 0.2)
|
||||
mark = inkOn(c, white, darkPick)
|
||||
}
|
||||
return fmt.Sprintf("--accent:%s;--accent-soft:%s;--accent-fg:%s;--sel:%s", a.hex(), soft.hex(), fg.hex(), sel.hex())
|
||||
return fmt.Sprintf("--accent:%s;--accent-soft:%s;--accent-fg:%s;--sel:%s;--mark:%s", a.hex(), soft.hex(), fg.hex(), sel.hex(), mark.hex())
|
||||
}
|
||||
|
||||
// appearanceRoutes serve the look's stylesheet and the wallpaper, and take
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestAccentSetting(t *testing.T) {
|
||||
// Whatever colour is picked, the accent drawn reads as text on the
|
||||
// theme's background and cards, and the text on it reads too.
|
||||
func TestAccentReadable(t *testing.T) {
|
||||
re := regexp.MustCompile(`--accent:(#[0-9a-f]{6});--accent-soft:(#[0-9a-f]{6});--accent-fg:(#[0-9a-f]{6})`)
|
||||
re := regexp.MustCompile(`--accent:(#[0-9a-f]{6});--accent-soft:(#[0-9a-f]{6});--accent-fg:(#[0-9a-f]{6});--sel:#[0-9a-f]{6};--mark:(#[0-9a-f]{6})$`)
|
||||
for _, pick := range []string{"#ffffff", "#000000", "#ffff00", "#00ff00", "#0d9488", "#2563eb", "#ea580c", "#52525b", "#808080", "#1a1a1e", "#f4f4f6"} {
|
||||
c, _ := parseHex(pick)
|
||||
for _, dark := range []bool{false, true} {
|
||||
@@ -106,11 +106,24 @@ func TestAccentReadable(t *testing.T) {
|
||||
if r := contrast(a, fg); r < 4.4 {
|
||||
t.Errorf("%s dark=%v: text %s on accent %s is %.2f:1", pick, dark, m[3], m[1], r)
|
||||
}
|
||||
// what is chosen is in the colour picked (CHENGJIAHEGOXIS on X:
|
||||
// a colour picked showed nowhere on Settings), and reads as text
|
||||
// on every surface a chosen option sits on
|
||||
mark, _ := parseHex(m[4])
|
||||
on := []rgb{lightBg, white, lightPick}
|
||||
if dark {
|
||||
on = []rgb{darkBg, darkCard, darkPick}
|
||||
}
|
||||
for _, bg := range on {
|
||||
if r := contrast(mark, bg); r < 4.4 {
|
||||
t.Errorf("%s dark=%v: chosen ink %s on %s is %.2f:1", pick, dark, m[4], bg.hex(), r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// a colour that reads already is drawn as picked
|
||||
c, _ := parseHex("#2563eb")
|
||||
if got := accentVars(c, false); !strings.HasPrefix(got, "--accent:#2563eb;") {
|
||||
if got := accentVars(c, false); !strings.HasPrefix(got, "--accent:#2563eb;") || !strings.Contains(got, ";--mark:#") {
|
||||
t.Fatalf("a readable blue was changed: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
+15
-11
@@ -23,6 +23,10 @@
|
||||
--accent-soft: #eeedfd;
|
||||
--accent-fg: #ffffff;
|
||||
--sel: #ecebfb;
|
||||
/* the ink of what is chosen: the open page's sidebar icon, a switch's or
|
||||
tab's chosen option. The text's own, graphite as a Mac's sidebar is,
|
||||
until an accent of the user's own takes it (appearance.go accentVars) */
|
||||
--mark: var(--fg);
|
||||
--green: #189a58;
|
||||
--green-soft: #e4f6ec;
|
||||
--red: #d64545;
|
||||
@@ -280,7 +284,7 @@ body:not(.window.linux) #winclose { display: none; }
|
||||
.seg > .thumb { border-radius: 6px; background: var(--seg-thumb); box-shadow: var(--seg-edge); }
|
||||
body.panel .seg { display: none; }
|
||||
.seg button { position: relative; z-index: 1; white-space: nowrap; height: 24px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; color: var(--ctl-fg); transition: color .18s var(--ease), transform .14s var(--ease); }
|
||||
.seg button.on { color: var(--fg); }
|
||||
.seg button.on { color: var(--mark); }
|
||||
/* a plugin update waiting for the reader: a dot on Plugins */
|
||||
.seg button.has-dot::after { content: ""; position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
|
||||
.seg button:hover:not(.on) { color: var(--fg-2); }
|
||||
@@ -375,7 +379,7 @@ body:not(.side-nav) #nav button[data-view="groups"], body.side-nav .rt-togroups
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
|
||||
font-size: 10.5px; font-weight: 500; line-height: 1.1; color: var(--muted);
|
||||
}
|
||||
body.web:not(.panel) .top #nav > button.on { color: var(--fg); }
|
||||
body.web:not(.panel) .top #nav > button.on { color: var(--mark); }
|
||||
body.web:not(.panel) .top #nav > button > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
body.web:not(.panel) .top #nav .nav-ic { display: block; flex: none; width: 23px; height: 23px; }
|
||||
body.web:not(.panel) .top #nav > button.has-dot::after { top: 5px; right: calc(50% - 17px); }
|
||||
@@ -473,8 +477,8 @@ body.side-nav #nav.hl-on button[data-view] .nav-ic { transition: color .22s var(
|
||||
body.side-nav .nav-ic { display: block; flex: none; color: var(--muted); }
|
||||
body.side-nav #prefs svg { flex: none; width: 15px; height: 15px; margin: 0 .5px; color: var(--muted); }
|
||||
/* graphite, as a Mac sidebar is: no colour of its own, the page open in the
|
||||
text's own ink; the accent is kept for what acts */
|
||||
body.side-nav :is(#nav button.on .nav-ic, #prefs.on svg) { color: var(--fg); }
|
||||
text's own ink, until an accent of the user's own colours it (--mark) */
|
||||
body.side-nav :is(#nav button.on .nav-ic, #prefs.on svg) { color: var(--mark); }
|
||||
body.side-nav .side-l { display: inline; }
|
||||
body.side-nav #nav > button[data-plugin-page] { position: relative; }
|
||||
body.side-nav #nav > button[data-plugin-page]::before { content: ""; position: absolute; left: 2px; top: 50%; width: 6px; height: 11px; margin-top: -5.5px; background: radial-gradient(circle, var(--muted) .9px, transparent 1.2px) 0 0 / 3px 3.75px; opacity: 0; transition: opacity .15s; }
|
||||
@@ -2000,7 +2004,7 @@ body.panel .view { padding-top: 2px; }
|
||||
.ptabs[hidden] { display: none; }
|
||||
.ptabs button { position: relative; z-index: 1; flex: 1; display: flex; align-items: center; justify-content: center; gap: 3px; height: 26px; border-radius: 7px; font-size: 12px; color: var(--muted); transition: color .15s, background-color .15s; }
|
||||
.ptabs button:hover:not(.on) { color: var(--fg-2); }
|
||||
.ptabs button.on { color: var(--fg); font-weight: 550; }
|
||||
.ptabs button.on { color: var(--mark); font-weight: 550; }
|
||||
.ptabs button[hidden] { display: none; }
|
||||
.ptabs em { font-style: normal; font-weight: 400; color: var(--faint); font-variant-numeric: tabular-nums; }
|
||||
body.panel[data-ptab="usage"] :is(#agents, #panelRouting, #panelUsage),
|
||||
@@ -3206,7 +3210,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
#gatewayKeys .klf-which { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
|
||||
#gatewayKeys .klf-tab { height: 24px; padding: 0 10px; border-radius: 6px; font-size: 12px; color: var(--ctl-fg); white-space: nowrap; }
|
||||
#gatewayKeys .klf-tab:hover:not(.on) { color: var(--fg-2); }
|
||||
#gatewayKeys .klf-tab.on { color: var(--fg); background: var(--seg-thumb); box-shadow: var(--seg-edge); }
|
||||
#gatewayKeys .klf-tab.on { color: var(--mark); background: var(--seg-thumb); box-shadow: var(--seg-edge); }
|
||||
@media (max-width: 520px) { #gatewayKeys .klf, #gatewayKeys .klf.with-days { grid-template-columns: 1fr; } #gatewayKeys .klf-used { flex-wrap: wrap; } }
|
||||
/* the models a key may use (#882): a long model's id is cut, and the
|
||||
badge gives way first on a narrow window */
|
||||
@@ -3681,7 +3685,7 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { box-shadow: 0 1px 0 va
|
||||
sheet into a sideways scroll (German Routing at the 560px window) */
|
||||
.editor .segs { max-width: 100%; flex-wrap: wrap; }
|
||||
.opt { position: relative; z-index: 1; white-space: nowrap; height: 22px; padding: 0 10px; border-radius: 5px; font-size: 12px; color: var(--muted); transition: color .18s var(--ease), transform .14s var(--ease); }
|
||||
.opt.on { color: var(--fg); }
|
||||
.opt.on { color: var(--mark); }
|
||||
/* how often magpie checks for updates, while it doesn't by itself */
|
||||
.update-every-row.off .segs, .update-restart-row.off .segs, .search-all-row.off .segs { opacity: .55; }
|
||||
/* Command line: each shell's `magpie`, a dot for whether it runs this app */
|
||||
@@ -3988,7 +3992,7 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { box-shadow: 0 1px 0 va
|
||||
.warm-tabs { display: flex; align-items: center; gap: 2px; margin-left: -7px; }
|
||||
.warm-tabs button { height: 22px; padding: 0 7px; border-radius: 6px; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); transition: color .12s, background-color .12s; }
|
||||
.warm-tabs button:hover:not(.on) { color: var(--fg-2); }
|
||||
.warm-tabs button.on { color: var(--fg); background: var(--pill); }
|
||||
.warm-tabs button.on { color: var(--mark); background: var(--pill); }
|
||||
.warm-tabs button[hidden] { display: none; }
|
||||
/* the page's parts (#471): a tab each at the top in the same look, a line
|
||||
more when they don't fit across (a narrow window, a larger text size),
|
||||
@@ -4738,7 +4742,7 @@ body.panel .modal { padding: 16px 12px; }
|
||||
.editor.importapps .apptabs { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: var(--pill); overflow-x: auto; scrollbar-width: none; }
|
||||
.editor.importapps .apptab { flex: 1 1 0; min-width: max-content; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; }
|
||||
.editor.importapps .apptab:hover { color: var(--fg); }
|
||||
.editor.importapps .apptab.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.18); }
|
||||
.editor.importapps .apptab.on { background: var(--card); color: var(--mark); box-shadow: 0 1px 2px rgba(0,0,0,.18); }
|
||||
.editor.importapps .apptab.missing .applogo { filter: grayscale(1); opacity: .5; }
|
||||
.editor.importapps .apptab .count { min-width: 16px; padding: 0 5px; border-radius: 8px; font-size: 10.5px; line-height: 16px; text-align: center; color: var(--fg-2); background: var(--line); }
|
||||
.editor.importapps .apptab.missing .count { background: none; color: var(--faint); }
|
||||
@@ -4956,7 +4960,7 @@ body.window .row.agent .who.with-models { flex-wrap: wrap; row-gap: 0; }
|
||||
.am-search:focus-within { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
|
||||
.am-seg { display: inline-flex; flex: none; padding: 2px; border-radius: 8px; background: var(--seg-track); }
|
||||
.am-seg button { height: 24px; padding: 0 9px; border: 0; border-radius: 6px; background: none; color: var(--ctl-fg); font: inherit; font-size: 12px; cursor: pointer; transition: background-color .15s, color .15s; }
|
||||
.am-seg button.on { background: var(--seg-thumb); color: var(--fg); box-shadow: var(--seg-edge); }
|
||||
.am-seg button.on { background: var(--seg-thumb); color: var(--mark); box-shadow: var(--seg-edge); }
|
||||
.am-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 2px; }
|
||||
/* the providers down the left (蓝猫 on Discord), the models of the one
|
||||
picked beside them, each scrolling on its own */
|
||||
@@ -5399,7 +5403,7 @@ body .row.agent .ag-prefs .row.pref .who { display: block; }
|
||||
.rate-win { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
|
||||
.rate-win .day-chips { display: flex; gap: 2px; }
|
||||
.rate-win .day-chip { min-width: 24px; height: 24px; padding: 0 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--muted); font: inherit; font-size: 11px; }
|
||||
.rate-win .day-chip.on { color: var(--fg); background: var(--seg-thumb); box-shadow: var(--seg-edge); }
|
||||
.rate-win .day-chip.on { color: var(--mark); background: var(--seg-thumb); box-shadow: var(--seg-edge); }
|
||||
.rate-win input { width: 64px; height: 28px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--fg); font: inherit; font-size: 12px; }
|
||||
.rate-win .rate-rate { width: 56px; }
|
||||
.rate-win .rate-dash { color: var(--muted); }
|
||||
|
||||
@@ -258,7 +258,7 @@ button.row.lib-hubfolded:hover { background: var(--pill); }
|
||||
/* the switch */
|
||||
.lib-switch { flex: none; position: relative; width: 32px; height: 19px; border-radius: 10px; background: var(--line); transition: background .2s var(--ease); }
|
||||
.lib-switch i { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .22s var(--ease); }
|
||||
.lib-switch.on { background: var(--fg); }
|
||||
.lib-switch.on { background: var(--mark); }
|
||||
.lib-switch.on i { transform: translateX(13px); background: var(--card); }
|
||||
:root[data-theme="dark"] .lib-switch.on i { background: var(--bg); }
|
||||
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lib-switch.on i { background: var(--bg); } }
|
||||
@@ -267,8 +267,8 @@ button.row.lib-hubfolded:hover { background: var(--pill); }
|
||||
.lib-sets .lib-cardhead { padding-bottom: 8px; }
|
||||
.lib-radio { flex: none; width: 17px; height: 17px; border-radius: 50%; border: 1.5px solid var(--faint); display: grid; place-items: center; transition: border-color .14s; }
|
||||
.lib-radio:hover { border-color: var(--fg-2); }
|
||||
.lib-radio.on { border-color: var(--fg); }
|
||||
.lib-radio.on::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--fg); }
|
||||
.lib-radio.on { border-color: var(--mark); }
|
||||
.lib-radio.on::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--mark); }
|
||||
.lib-set.on .name { font-weight: 600; }
|
||||
.lib-sets .lib-detail { padding-left: 40px; }
|
||||
.lib-sets > .lib-cardhead + .row, .lib-sets .lib-detail + .row, .lib-sets .lib-detail + .lib-setadd, .lib-sets .row + .lib-setadd { border-top: 1px solid var(--line-2); }
|
||||
|
||||
@@ -21,17 +21,23 @@ const { chromium, webkit } = require("playwright");
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
// a 1×1 PNG
|
||||
const PNG = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", "base64");
|
||||
const accentCSS = (a) => (a ? `html:not(.omarchy):root{--accent:${a};--accent-soft:#e6f4f2;--accent-fg:#ffffff;--sel:#e1f1ef}` : "");
|
||||
// as appearance.go's lookCSS draws it: the light theme's, then the dark
|
||||
// one's, --mark the ink of what is chosen
|
||||
const DARK = { "#0d9488": "#5cc9bd", "#db2777": "#f08cbd", "#7c3aed": "#c4a6f8" };
|
||||
const accentCSS = (a) => (a ? `html:not(.omarchy):root{--accent:${a};--accent-soft:#e6f4f2;--accent-fg:#ffffff;--sel:#e1f1ef;--mark:${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}}}
|
||||
html:not(.omarchy):root[data-theme="dark"]{--accent:${DARK[a] || a};--accent-soft:#1a2c2e;--accent-fg:#14141a;--sel:#1a3435;--mark:${DARK[a] || a}}` : "");
|
||||
|
||||
function serve(st, log) {
|
||||
const settings = () => ({ lang: "en", theme: "light", searchVendors: [], searchAPIs: [], ...st });
|
||||
const theme = () => settings().theme;
|
||||
return async (r) => {
|
||||
const url = new URL(r.request().url());
|
||||
const json = (data) => r.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") {
|
||||
const look = (st.accent || "") + "," + (st.wallpaper || "");
|
||||
const css = accentCSS(st.accent);
|
||||
return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang: st.lang || "en", theme: "light", web: false, look })};` + (css ? `(function(){var e=document.createElement("style");e.id="lookCSS";e.textContent=${JSON.stringify(css)};document.head.appendChild(e)})();` : "") });
|
||||
return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang: st.lang || "en", theme: theme(), web: false, look })};` + (css ? `(function(){var e=document.createElement("style");e.id="lookCSS";e.textContent=${JSON.stringify(css)};document.head.appendChild(e)})();` : "") });
|
||||
}
|
||||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: settings() });
|
||||
@@ -70,15 +76,15 @@ function serve(st, log) {
|
||||
const NAMES = { en: "Accent color", zh: "强调色", "zh-TW": "強調色", ja: "アクセントカラー", de: "Akzentfarbe" };
|
||||
const PICTURE = { en: "Background image", zh: "背景图片", "zh-TW": "背景圖片", ja: "背景画像", de: "Hintergrundbild" };
|
||||
|
||||
async function open(browser, st, width) {
|
||||
async function open(browser, st, width, query = "view=settings", wait = "#accentPick .swatch") {
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 800 } })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], log = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(st, log));
|
||||
await page.goto("http://magpie.test/?view=settings");
|
||||
await page.locator("#accentPick .swatch").first().waitFor();
|
||||
await page.goto("http://magpie.test/?" + query);
|
||||
await page.locator(wait).first().waitFor();
|
||||
return { page, errors, log };
|
||||
}
|
||||
|
||||
@@ -116,6 +122,71 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
// CHENGJIAHEGOXIS on X: 「选中任意强调色没反应」. The accent reached
|
||||
// only buttons, links and bars, none of them on Settings, so a colour
|
||||
// picked changed nothing in sight. What is chosen (the open page in the
|
||||
// sidebar, a switch's or tab's chosen option) is in --mark: the text's
|
||||
// own ink by default, the colour picked once there is one, in the window
|
||||
// and the panel, light and dark, over a picture too.
|
||||
for (const theme of ["light", "dark"]) {
|
||||
// the chosen option's ink, and the probe's for a colour
|
||||
const inks = (page, sel) => page.evaluate((sel) => {
|
||||
const ink = (v) => { const p = document.createElement("i"); p.style.color = v; document.body.append(p); const c = getComputedStyle(p).color; p.remove(); return c; };
|
||||
return { got: sel.map((s) => { const e = document.querySelector(s); return e ? getComputedStyle(e).color : "missing " + s; }), fg: ink("var(--fg)"), mark: ink("var(--mark)") };
|
||||
}, sel);
|
||||
const same = (r, want, what) => assert.deepEqual(r.got, r.got.map(() => want), what);
|
||||
// what is chosen eases to its colour (.18s): read it once it stands still
|
||||
const settled = async (page, sel) => {
|
||||
let last = "";
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const r = await inks(page, sel), now = JSON.stringify(r);
|
||||
if (now === last) return r;
|
||||
last = now;
|
||||
await page.waitForTimeout(100);
|
||||
}
|
||||
return JSON.parse(last);
|
||||
};
|
||||
|
||||
test(`${engine}: ${theme}, a colour picked shows on what is chosen, in the window`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const st = { theme, wallpaper: 1700000000000 };
|
||||
const { page, errors } = await open(browser, st, 1200);
|
||||
await page.waitForFunction(() => document.body.classList.contains("side-nav"));
|
||||
const sel = ["#themeSegs .opt.on", "#birdSegs .opt.on", "body.side-nav #prefs.on svg"];
|
||||
const before = await settled(page, sel);
|
||||
same(before, before.fg, "magpie's own look: what is chosen is in the text's ink");
|
||||
for (const [v, light] of [["#0d9488", "#0d9488"], ["#db2777", "#db2777"]]) {
|
||||
await page.locator(`#accentPick .swatch[data-accent="${v}"]`).click();
|
||||
const want = theme === "dark" ? DARK[v] : light;
|
||||
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`);
|
||||
}
|
||||
await page.locator('#accentPick .swatch[data-accent=""]').click();
|
||||
await page.waitForFunction(() => !document.getElementById("lookCSS")?.textContent);
|
||||
const back = await settled(page, sel);
|
||||
same(back, back.fg, "back to magpie's own");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine}: ${theme}, the header's tabs and the panel's take the colour`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const [query, width, sel] of [["view=agents", 900, ["#nav button.on"]], ["mode=panel", 380, [".ptabs button.on"]]]) {
|
||||
for (const accent of ["", "#0d9488"]) {
|
||||
const { page, errors } = await open(browser, { theme, accent }, width, query, sel[0]);
|
||||
const r = await settled(page, sel);
|
||||
if (accent) assert.notEqual(r.mark, r.fg);
|
||||
same(r, accent ? r.mark : r.fg, `${query} ${accent || "default"}`);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.context().close();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user