Repository navigation
Milestone 2: artwork selection - #3
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asizesstring into{ widthPx, heightPx }entries. It acceptsxorX, treatsanyas infinitely scalable, and skips malformed or zero sizes.isUsableSrc(src)allows onlyhttps:URLs anddata:URLs with animage/*type. It rejectshttp:,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 thesrcof the smallest one at leastminPx, or the largest when none is big enough, ornullwhen 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 runspickArtworkon the artwork recorded on Zen 1.24.3b and checks thatminPx: 96picks the 120x120 image. Nothing was checked by hand in Zen, because the mod can't be installed until Milestone 5.Checklist
npm test)npm run lintandnpm run format:checkpassnpm run build) if anything insrc/changed (unchanged: nothing importssrc/artwork.jsyet)docs/manual-testing.mdchecked in a real Zen + Sine install (not applicable until Milestone 5)CHANGELOG.mdupdated under Unreleased