Skip to content

Milestone 2: artwork selection - #3

Merged
rodzy merged 7 commits into
mainfrom
milestone-2-artwork
Nov 27, 2026
Merged

rodzy merged 7 commits into
mainfrom
milestone-2-artwork

Conversation

@rodzy

@rodzy rodzy commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

What does this change?

Milestone 2: adds src/artwork.js, which chooses the image to show from a media controller's Media Session artwork.

  • parseSizes(sizes) reads a sizes string into { widthPx, heightPx } entries. It accepts x or X, treats any as infinitely scalable, and skips malformed or zero sizes.
  • isUsableSrc(src) allows only https: URLs and data: URLs with an image/* type. It rejects http:, blob:, privileged schemes, relative paths and malformed URLs.
  • pickArtwork(artwork, { minPx }) measures each usable image by the shorter side of its largest size, and returns the src of the smallest one at least minPx, or the largest when none is big enough, or null when no image is usable. Ties keep the first image in the list.

Nothing imports the module yet; it's wired in at Milestone 5, so the bundle is unchanged. The roadmap now marks Milestone 2 Done and Milestone 3 Next.

How was it tested?

New unit tests in test/artwork.test.js, written first. One runs pickArtwork on the artwork recorded on Zen 1.24.3b and checks that minPx: 96 picks the 120x120 image. Nothing was checked by hand in Zen, because the mod can't be installed until Milestone 5.

Checklist

  • Tests were written first and cover the change (npm test)
  • npm run lint and npm run format:check pass
  • Bundle rebuilt and committed (npm run build) if anything in src/ changed (unchanged: nothing imports src/artwork.js yet)
  • Relevant items in docs/manual-testing.md checked in a real Zen + Sine install (not applicable until Milestone 5)
  • CHANGELOG.md updated under Unreleased

parseSizes reads Media Session sizes strings, isUsableSrc limits sources to https and data URLs, and pickArtwork chooses the smallest image wide enough for the card, falling back to the widest.
A data: URL of any media type was passed on as artwork. Only data: URLs with an image/* media type are usable now.
Spreading every parsed size into Math.max threw a RangeError for a page-supplied sizes string with hundreds of thousands of tokens. Reduce over the sizes instead.
Measuring by width let a wide banner such as 200x40 beat a square cover. Compare the shorter edge so an image counts as big enough only when both dimensions are.
@rodzy
rodzy merged commit 8cf2e99 into main Nov 27, 2026
1 check passed
@rodzy
rodzy deleted the milestone-2-artwork branch November 27, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant