Files
magpie/internal/gui/trayimage_plain_darwin_test.go
T
yetone c5cb1c0588 gui: the tray's logo is 16pt, as large as other apps' menu bar icons
qingnianxiaozhe on X: magpie's A\ in the menu bar looked a size smaller
than another app's A\ beside it. magpie fitted each logo to a 14pt box,
so the A\ (about 1.37:1) drew 14x10pt. Claude.app's menu bar template
(TrayIconTemplate@2x.png, 48x48 px) has 32x32 px of ink, a 16pt glyph,
and in the reporter's screenshot the other A\ is 32x22 px against
magpie's 28x20 px at 2x. mpLogo is now 16; the letter in a ring (a logo
that can't be read) grows with it. The two 10pt rows of percentages are
unchanged and still fit the 22pt bar.

Tests: the logo boxes in the tray tests follow the 16pt box (offsets 28
-> 32, 34 -> 38 px at 2x); TestTrayImageLogoSizes now wants 27-33 px of
a 32 px box.

Run on mote (macOS 27.2):
- go test ./internal/gui -run Tray -count=1 -v: ok.
- Broken by hand (mpLogo back to 14): TestTrayImageLogoSizes FAILs
  ("alma spans 24 px of a 32 px box", codex/zcode/workbuddy 26 px) and
  TestTrayImagePlain FAILs ("238 px with logos, 182 without").
- Rendered by the real drawing code (trayImagePNG, 22pt bar at 2x)
  next to Claude.app's own template icon: the A\ is 28 px wide before
  and 32x24 px of ink after, as wide as Claude's 32 px spark; the
  percentages are the same text at the same size. The before/after
  strips are kept outside the repo (tray-toolbar-scratch/before and
  after/strip-{light,dark}.png).
Suite and checks, on mote at aa31e737c8d271455865615fafdf512e09073663 (this commit and its pair, the
tray logo size / the toolbar menu):
- go test -count=1 -timeout 45m ./... in a sandbox HOME, caches pinned:
  exit 0, 103 packages ok, none FAIL (internal/gateway 1633s,
  internal/agent 949s, internal/provider 470s, internal/gui 295s).
- gofmt -l internal/gui: nothing. go vet ./..., GOOS=linux go vet -tags
  nogui ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: all ok.
- No GUI asset changed, so the Playwright suite wasn't run.
After a rebase onto 42c43c002 (Antigravity sessions, internal/gui
sessions reads; no file in common), at the pushed head:
go vet, GOOS=windows and GOOS=linux -tags nogui go vet of ./internal/gui/...
and go test -count=1 ./internal/gui/...: ok.
Then rebased onto f7e0f68ca (Codex instructions, internal/provider
only), not run again.

Not tried: a screen screenshot of the real menu bar (no Screen
Recording permission over ssh on mote; the image is the one the app
hands NSStatusItem); the reporter's notch Mac, where the bar is 24pt.
2026-11-18 16:08:15 +08:00

76 lines
2.5 KiB
Go

//go:build darwin && cgo
package gui
import (
"bytes"
"image"
"image/png"
"os"
"path/filepath"
"testing"
"time"
)
// Without their logos the cells are their digits alone: narrower than with
// them, nothing drawn where the logo was, and a thin line between one card
// and the next. MAGPIE_TRAY_PREVIEW=<dir> writes them as PNGs to look at.
func TestTrayImagePlain(t *testing.T) {
bird, err := os.ReadFile("tray.png")
if err != nil {
t.Fatal(err)
}
cells, _, _ := trayUsageView(trayCards(), time.Now(), false, false)
cells = cells[:2]
plain := trayPlain(cells)
for _, dark := range []bool{false, true} {
_, logoW, _ := trayImagePNG(cells, bird, 22, 2, dark, false)
b, w, h := trayImagePNG(plain, bird, 22, 2, dark, false)
img, err := png.Decode(bytes.NewReader(b))
if err != nil {
t.Fatal(err)
}
// at 2x: the bird 44 px, then 2pt, 3pt, the first card's digits
_, oneW, _ := trayImagePNG(plain[:1], bird, 22, 2, dark, false)
_, birdW, _ := trayImagePNG(nil, bird, 22, 2, dark, false)
// two logos and their gaps (16+3 each) gone, 3 before the first
// card's digits and the line's 5+1+5 for the 8 between cards come
if d, want := logoW-w, 2*(2*(16+3)-3-(5+1+5-8)); d < want-2 || d > want+2 {
t.Errorf("dark %v: %d px with logos, %d without", dark, logoW, w)
}
// right after the bird come the digits, not an empty logo's room
if ink := inkIn(img, image.Rect(birdW, 0, birdW+10, h), dark); ink < 10 {
t.Errorf("dark %v: %d px of ink where the first card's digits start", dark, ink)
}
// the line between the two: faint, a column of its own in the gap,
// nothing on either side of it
gap := image.Rect(oneW-1, 0, oneW-1+2*(5+1+5), h)
line := 0
for x := gap.Min.X; x < gap.Max.X; x++ {
n := 0
for y := 0; y < h; y++ {
if _, _, _, a := img.At(x, y).RGBA(); a > 0x1000 {
n++
}
}
if n >= 20 {
line++
} else if n > 2 {
t.Errorf("dark %v: column %d has %d px, neither line nor gap", dark, x, n)
}
}
if line < 1 || line > 3 {
t.Errorf("dark %v: the line between cards is %d px wide", dark, line)
}
if ink := inkIn(img, image.Rect(gap.Max.X, 0, w, h), dark); ink < 60 {
t.Errorf("dark %v: the second card has %d px of ink", dark, ink)
}
if out := os.Getenv("MAGPIE_TRAY_PREVIEW"); out != "" {
bg, _, _ := trayImagePNG(plain, bird, 22, 2, dark, true)
if err := os.WriteFile(filepath.Join(out, map[bool]string{false: "plain-light.png", true: "plain-dark.png"}[dark]), bg, 0o644); err != nil {
t.Fatal(err)
}
}
}
}