-
Notifications
You must be signed in to change notification settings - Fork 296
feat(get-app): smart-link QR + ship to logged-out desktop visitors (no flag) #6399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tsahimatsliah
wants to merge
7
commits into
main
Choose a base branch
from
claude/get-app-qr-smart-link
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
863df02
fix(get-app): point the QR at the OS-aware smart link with attribution
tsahimatsliah 4e36c9b
fix(get-app): correct attribution claims and add QR drift specs
tsahimatsliah 372549d
fix(get-app): describe the QR spec accurately and pin error correction H
github-actions[bot] 9c90de6
chore: retrigger CI (flaky MyFeedPage test)
tsahimatsliah 9d9e46b
feat(get-app): ship to anonymous desktop visitors and drop the flag
tsahimatsliah 678ba7f
chore(get-app): remove the dead attention dot and orphaned flag comment
tsahimatsliah 5ae72d2
fix(get-app): gate the desktop breakpoint in CSS to kill the hydratio…
tsahimatsliah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import jsQR from 'jsqr'; | ||
|
|
||
| // The repo ships two hand-committed QR matrices (the header get-app asset and | ||
| // the onboarding signup panel). Their destination URLs live in code, but the | ||
| // matrices are opaque path strings - if one moves without the other being | ||
| // regenerated, the only symptom is a scan landing on a stale destination. | ||
| // These helpers parse a committed path back into a module matrix and decode it | ||
| // the way a phone camera would (via jsQR), so a spec can assert the committed | ||
| // pixels still say what the code claims. Decoding rather than re-encoding | ||
| // keeps the assertion valid regardless of which generator or mask pattern | ||
| // produced the asset. | ||
|
|
||
| type Matrix = boolean[][]; | ||
|
|
||
| // Stroke-run format, as emitted by `npx qrcode -t svg`: rows drawn as | ||
| // 1px-tall horizontal strokes on half-pixel centres, e.g. | ||
| // `M4 4.5h7m2 0h2` = at row 4 draw 7 modules from col 4, skip 2, draw 2. | ||
| // `quietZone` is the generator's fixed 4-module margin baked into the coords. | ||
| export const parseStrokePath = (d: string, quietZone = 4): Matrix => { | ||
| const cells: Array<[number, number]> = []; | ||
| const rowRuns = d.split('M').filter(Boolean); | ||
|
|
||
| rowRuns.forEach((run) => { | ||
| const [, xStart, yCentre] = run.match(/^([\d.]+) ([\d.]+)/) ?? []; | ||
| const row = Math.floor(Number(yCentre)) - quietZone; | ||
| let col = Number(xStart) - quietZone; | ||
|
|
||
| Array.from(run.matchAll(/([hm])(-?[\d.]+)/g)).forEach(([, op, a]) => { | ||
| const n = Number(a); | ||
| if (op === 'h') { | ||
| for (let i = 0; i < n; i += 1) { | ||
| cells.push([row, col + i]); | ||
| } | ||
| } | ||
| col += n; | ||
| }); | ||
| }); | ||
|
|
||
| const size = Math.max(...cells.map(([row]) => row)) + 1; | ||
| const matrix: Matrix = Array.from({ length: size }, () => | ||
| Array.from({ length: size }, () => false), | ||
| ); | ||
| cells.forEach(([row, col]) => { | ||
| matrix[row][col] = true; | ||
| }); | ||
|
|
||
| return matrix; | ||
| }; | ||
|
|
||
| // Rect format, as used by the hand-flattened onboarding matrix: | ||
| // `M0 0h7v1h-7z` = a 7-module run at row 0, col 0. Coordinates are already | ||
| // module-space (the quiet zone lives in the viewBox origin instead). | ||
| export const parseRectPath = (d: string): Matrix => { | ||
| const rects = Array.from(d.matchAll(/M(\d+) (\d+)h(\d+)v1h-\3z/g)); | ||
| const size = Math.max(...rects.map(([, , y]) => Number(y))) + 1; | ||
| const matrix: Matrix = Array.from({ length: size }, () => | ||
| Array.from({ length: size }, () => false), | ||
| ); | ||
|
|
||
| rects.forEach(([, x, y, w]) => { | ||
| for (let i = 0; i < Number(w); i += 1) { | ||
| matrix[Number(y)][Number(x) + i] = true; | ||
| } | ||
| }); | ||
|
|
||
| return matrix; | ||
| }; | ||
|
|
||
| // Rasterises the matrix into greyscale RGBA (scaled up, with a real quiet | ||
| // zone) and runs the same decoder a scanner pipeline would. | ||
| export const decodeMatrix = (matrix: Matrix): string | null => { | ||
| const scale = 4; | ||
| const quiet = 4 * scale; | ||
| const px = matrix.length * scale + quiet * 2; | ||
| const rgba = new Uint8ClampedArray(px * px * 4).fill(255); | ||
|
|
||
| matrix.forEach((rowCells, row) => { | ||
| rowCells.forEach((dark, col) => { | ||
| if (!dark) { | ||
| return; | ||
| } | ||
| for (let dy = 0; dy < scale; dy += 1) { | ||
| for (let dx = 0; dx < scale; dx += 1) { | ||
| const x = quiet + col * scale + dx; | ||
| const y = quiet + row * scale + dy; | ||
| const at = (y * px + x) * 4; | ||
| rgba[at] = 0; | ||
| rgba[at + 1] = 0; | ||
| rgba[at + 2] = 0; | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| return jsQR(rgba, px, px)?.data ?? null; | ||
| }; |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.