Clicking magpie's Dock icon plays the header logo's .logo.wag on the tile: the same keyframes, turn points, .9s and cubic-bezier(.3, 0, .3, 1), a frame every 30ms. The icon macOS draws (its glass tile and glossy bird) is cut into body, tail and wing by index.html's own clip paths, the tile under the bird filled with the tile's colour read either side of it, and each frame turns the pieces over it, set as the Dock tile's content view. The tile goes back to the system's icon after. It plays only when the Dock draws icons light (no AppleIconAppearanceTheme, RegularLight, or RegularAutomatic in light mode); a dark, clear or tinted Dock is left as it is. A click while it plays doesn't start another. Run: - go test ./internal/gui/ -run TestDockFlap: TestDockFlapIsTheLogos holds the keyframes, origins, length and easing to app.css and parses the bird and clips out of the embedded index.html. Broken by hand: changing one keyframe in flapkeys.go turns it red. - TestDockFlapFrames (MAGPIE_DOCK_APP=/Applications/magpie.app) wrote the 31 frames; looked at by eye. Frame 0 against the system's own 512px render: inside the tile 0.03% of pixels differ by over 40/255 (the tile's rim resampled); the pieces' seams were visible until they overlapped by 1px. - A sandbox bundle (own bundle id, sandbox HOME, ports 3446/3447) got the Dock's reopen event by pid: a burst of screen captures of the real Dock shows the tile in different poses. - go vet ./internal/gui/, GOOS=windows go vet, GOOS=linux go vet -tags nogui, GOOS=linux go build -tags nogui, GOOS=windows go build, gofmt -l. Not tried: a dark or tinted Dock (skipped by the gate, not drawn), a real mouse click on the Dock (the same reopen event, sent by pid).
74 lines
2.4 KiB
Go
74 lines
2.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestDockFlapIsTheLogos holds the Dock tile's flap to the header logo's:
|
|
// the same keyframes, turn points, length and easing as app.css plays,
|
|
// and the bird and clip paths read from index.html.
|
|
func TestDockFlapIsTheLogos(t *testing.T) {
|
|
css, err := assets.ReadFile("assets/app.css")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, c := range []struct {
|
|
name, part string
|
|
keys []flapKey
|
|
at [2]float64
|
|
}{{"wing-flap", "wing", wingKeys, wingAt}, {"tail-flick", "tail", tailKeys, tailAt}, {"bird-bob", "bird", bobKeys, bobAt}} {
|
|
body := regexp.MustCompile(`@keyframes ` + c.name + ` \{\n((?: .*\n)+)\}`).FindSubmatch(css)
|
|
if body == nil {
|
|
t.Fatalf("no @keyframes %s in app.css", c.name)
|
|
}
|
|
got := []flapKey{{0, 0}}
|
|
for _, m := range regexp.MustCompile(`(?m)^ (\d+)% \{ transform: rotate\((-?\d+)deg\); \}$`).FindAllSubmatch(body[1], -1) {
|
|
at, _ := strconv.ParseFloat(string(m[1]), 64)
|
|
deg, _ := strconv.ParseFloat(string(m[2]), 64)
|
|
got = append(got, flapKey{at / 100, deg})
|
|
}
|
|
got = append(got, flapKey{1, 0})
|
|
if fmt.Sprint(got) != fmt.Sprint(c.keys) {
|
|
t.Errorf("%s: app.css has %v, the Dock plays %v", c.name, got, c.keys)
|
|
}
|
|
origin := fmt.Sprintf(`.logo .%s { transform-box: view-box; transform-origin: %vpx %vpx; }`, c.part, c.at[0], c.at[1])
|
|
if !regexp.MustCompile(regexp.QuoteMeta(origin)).Match(css) {
|
|
t.Errorf("app.css has no %q", origin)
|
|
}
|
|
anim := fmt.Sprintf(`.logo.wag .%s { animation: %s %ss cubic-bezier(.3, 0, .3, 1); }`, c.part, c.name, strings.TrimPrefix(fmt.Sprint(flapSecs), "0"))
|
|
if !regexp.MustCompile(regexp.QuoteMeta(anim)).Match(css) {
|
|
t.Errorf("app.css has no %q", anim)
|
|
}
|
|
}
|
|
for x, prev := 0.0, -1.0; x <= 1; x += .01 {
|
|
if e := flapEase(x); e < prev || e < -1e-9 || e > 1+1e-9 {
|
|
t.Fatalf("the easing at %v is %v, after %v", x, e, prev)
|
|
} else {
|
|
prev = e
|
|
}
|
|
}
|
|
page, err := assets.ReadFile("assets/index.html")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
bird, clips, ok := logoPaths(string(page))
|
|
if !ok {
|
|
t.Fatal("index.html's bird or a clip path didn't parse")
|
|
}
|
|
if len(bird.ops) < 100 || bird.ops[0] != 'M' {
|
|
t.Errorf("the bird read as %d ops", len(bird.ops))
|
|
}
|
|
for i, c := range clips {
|
|
if len(c.ops) < 4 {
|
|
t.Errorf("clip %d read as %v", i, c.ops)
|
|
}
|
|
}
|
|
if _, ok := parseFlapPath("M1 2Q3 4 5 6"); ok {
|
|
t.Error("a path with Q read as good")
|
|
}
|
|
}
|