fix: make the batch scanner and Add Book work on iPhone and iPad #71

Merged
jfro merged 4 commits from mobile/scanner into main 2026-10-25 18:31:55 +00:00
Owner

Part of the mobile pass. Makes the batch scanner and Add Book (with its camera modal) work well on iPhone (393x852) and iPad (820x1180, portrait and landscape), light and dark. Two commits, one per page.

Batch scanner (with a Bluetooth/USB scanner)

  • Scanner paused banner while the page doesn't have keyboard focus (Safari's address bar, another app): a HID scanner types into whatever has focus, so scans would otherwise go nowhere silently. Tapping the page brings focus back and hides it.
  • Tab ends a scan too (only mid-scan, so normal Tab still works), for scanners set to send Tab instead of Enter.
  • The media type select blurs after a change, so focus goes back to the page.
  • No field is ever focused, so the on-screen keyboard doesn't come up.
  • console.info('[batch-scanner] …') logs each scan (chars, ms, how it ended, queue length) and focus changes, for debugging on a device with Web Inspector.
  • Phones: the three stats in one compact row, status badges kept only for screen readers, less padding, so results get a readable width.
  • Touch screens (pointer-coarse:): 44px media type buttons, a plain View Book link instead of a one-item ⋮ menu, and the results list scrolls with the page instead of a nested max-h-96 box. Desktop (fine pointer) looks the same as before.
  • Toasts stack in one corner instead of drawing over each other; full width on phones.

Add Book + camera modal

  • app.css: on touch screens, fields get at least 16px text so iOS Safari doesn't zoom in on focus, and default-size .input/.select are 44px tall. This is global (all forms on touch devices); it's the standard iOS fix and the other-pages PR will build on it.
  • 44px tabs and buttons on this page; tab panels use less padding on phones.
  • Camera modal fills a phone screen; Quagga's video and overlay are scaled to the scanning area (object-fit: cover) instead of showing at native size cropped to the top-left; the guide box fits inside it on a phone; the info alert is hidden on phones to give the video room. Quagga is kept as is.

Checked

  • Playwright WebKit, iPhone 393x852 and iPad 820x1180 / 1180x820, light and dark, touch + coarse pointer: no horizontal overflow, no tap targets under 44px, no fields under 16px on either page or in the camera modal (fake camera stream). HID simulated as fast keydowns + Enter, with a tap on the select between scans: all 4 scans land (added, exists, added, invalid).
  • mix precommit: 635 tests pass, no warnings.
  • Merges cleanly with #70. One note for #70: the new Announce toggle is btn-xs; adding pointer-coarse:h-11 there would make it an easy tap on iPad.

Not covered

  • Not tried on a real iPhone/iPad with a real HID scanner: Safari on iOS may handle the focus/blur events a little differently from desktop WebKit. Worth one real scan session before shipping.
Part of the mobile pass. Makes the batch scanner and Add Book (with its camera modal) work well on iPhone (393x852) and iPad (820x1180, portrait and landscape), light and dark. Two commits, one per page. ### Batch scanner (with a Bluetooth/USB scanner) - **Scanner paused banner** while the page doesn't have keyboard focus (Safari's address bar, another app): a HID scanner types into whatever has focus, so scans would otherwise go nowhere silently. Tapping the page brings focus back and hides it. - **Tab ends a scan** too (only mid-scan, so normal Tab still works), for scanners set to send Tab instead of Enter. - The media type select blurs after a change, so focus goes back to the page. - No field is ever focused, so the on-screen keyboard doesn't come up. - `console.info('[batch-scanner] …')` logs each scan (chars, ms, how it ended, queue length) and focus changes, for debugging on a device with Web Inspector. - Phones: the three stats in one compact row, status badges kept only for screen readers, less padding, so results get a readable width. - Touch screens (`pointer-coarse:`): 44px media type buttons, a plain **View Book** link instead of a one-item ⋮ menu, and the results list scrolls with the page instead of a nested `max-h-96` box. Desktop (fine pointer) looks the same as before. - Toasts stack in one corner instead of drawing over each other; full width on phones. ### Add Book + camera modal - `app.css`: on touch screens, fields get at least 16px text so iOS Safari doesn't zoom in on focus, and default-size `.input`/`.select` are 44px tall. **This is global** (all forms on touch devices); it's the standard iOS fix and the other-pages PR will build on it. - 44px tabs and buttons on this page; tab panels use less padding on phones. - Camera modal fills a phone screen; Quagga's video and overlay are scaled to the scanning area (`object-fit: cover`) instead of showing at native size cropped to the top-left; the guide box fits inside it on a phone; the info alert is hidden on phones to give the video room. Quagga is kept as is. ### Checked - Playwright WebKit, iPhone 393x852 and iPad 820x1180 / 1180x820, light and dark, touch + coarse pointer: no horizontal overflow, no tap targets under 44px, no fields under 16px on either page or in the camera modal (fake camera stream). HID simulated as fast keydowns + Enter, with a tap on the select between scans: all 4 scans land (added, exists, added, invalid). - `mix precommit`: 635 tests pass, no warnings. - Merges cleanly with #70. One note for #70: the new Announce toggle is `btn-xs`; adding `pointer-coarse:h-11` there would make it an easy tap on iPad. ### Not covered - Not tried on a real iPhone/iPad with a real HID scanner: Safari on iOS may handle the focus/blur events a little differently from desktop WebKit. Worth one real scan session before shipping.
On touch screens, fields get 16px text so iOS Safari doesn't zoom in on
focus, and default-size fields and this page's buttons and tabs are 44px
tall. The camera modal fills a phone screen, its video is scaled to the
scanning area instead of cropped to the frame's corner, and the guide box
fits inside it.
fix: make the batch scanner work on iPhone and iPad
All checks were successful
CI / test (pull_request) Successful in 47s
1f578f2267
- Show a 'Scanner paused' banner while the page doesn't have keyboard
  focus (Safari's address bar, another app), when a Bluetooth/USB
  scanner's input goes elsewhere, and hide it when focus is back
- Treat Tab as the end of a scan, for scanners set to send it
- Blur the media type select after a change so focus returns to the page
- Log each scan (chars, ms, how it ended, queue length) and focus changes
- Phones: stats in one compact row, status badges only for screen readers,
  less padding, so results are readable without a narrow column
- Touch screens: 44px tap targets for the media type picker, a plain
  View Book link instead of a one-item menu, the results list scrolls with
  the page instead of a nested scroll box
- Toasts stack instead of covering each other, full width on phones
Author
Owner

Screenshots (Playwright WebKit)

pr-batch-iphone

pr-batch-iphone

pr-batch-iphone-dark

pr-batch-iphone-dark

pr-paused-iphone

pr-paused-iphone

pr-batch-ipad-dark

pr-batch-ipad-dark

pr-batch-ipad-land

pr-batch-ipad-land

pr-new-iphone

pr-new-iphone

pr-camera-iphone

pr-camera-iphone

### Screenshots (Playwright WebKit) **pr-batch-iphone** ![pr-batch-iphone](https://git.knope.dev/attachments/cd1a3d85-90c9-41d1-a06a-a42d195c3c39) **pr-batch-iphone-dark** ![pr-batch-iphone-dark](https://git.knope.dev/attachments/fb768fde-0748-4051-a594-4fe7fabc3acb) **pr-paused-iphone** ![pr-paused-iphone](https://git.knope.dev/attachments/d73de010-731b-4b20-88d7-d23ff401f370) **pr-batch-ipad-dark** ![pr-batch-ipad-dark](https://git.knope.dev/attachments/93e37e60-7186-4b13-9f8f-86d3583fea73) **pr-batch-ipad-land** ![pr-batch-ipad-land](https://git.knope.dev/attachments/86b5b33e-156a-48a4-ba5c-f25ae2b81da3) **pr-new-iphone** ![pr-new-iphone](https://git.knope.dev/attachments/4f87751e-2f5e-46cf-80ef-a8e2fcce03ef) **pr-camera-iphone** ![pr-camera-iphone](https://git.knope.dev/attachments/bb5d8fd5-0434-434b-b111-6ccd506881e3)
jfro force-pushed mobile/scanner from 1f578f2267
All checks were successful
CI / test (pull_request) Successful in 47s
to 345b3887f3
All checks were successful
CI / test (pull_request) Successful in 50s
2026-10-25 17:47:33 +00:00
Compare
Author
Owner

Rebased onto main (v0.7.0, 902e363) and pushed. New head 345b388 adds one commit:

  • F1 fixed: short screens (max-height 500px, e.g. iPhone landscape) get a smaller scanner area, no tip banner and tighter spacing. At 852×393 the camera modal's ✕ is at y=56–100 and Cancel at y=293–337, both on screen.
  • The batch scanner's Announce toggle from #70 gets a 44px touch target (pointer-coarse:h-11).
  • F2 is fixed by this PR too: the global touch rule makes every input/select 16px; input-zoom check passes on /books, /books/new, /books/batch-scanner, /books/1/edit, /users/settings.

Full mobile check (393, 820, 1180, light+dark): 0 problems. mix precommit: 635 tests pass.

landscape camera modal

Rebased onto main (v0.7.0, 902e363) and pushed. New head **345b388** adds one commit: - **F1 fixed:** short screens (max-height 500px, e.g. iPhone landscape) get a smaller scanner area, no tip banner and tighter spacing. At 852×393 the camera modal's ✕ is at y=56–100 and Cancel at y=293–337, both on screen. - The batch scanner's Announce toggle from #70 gets a 44px touch target (pointer-coarse:h-11). - **F2 is fixed by this PR** too: the global touch rule makes every input/select 16px; input-zoom check passes on /books, /books/new, /books/batch-scanner, /books/1/edit, /users/settings. Full mobile check (393, 820, 1180, light+dark): 0 problems. mix precommit: 635 tests pass. ![landscape camera modal](https://git.knope.dev/attachments/9694d5e4-d8e6-40e5-9af8-3e59340fc64a)
feat: keep the screen on and harden HID input in the batch scanner
All checks were successful
CI / test (pull_request) Successful in 48s
2a6f174599
Takes a screen wake lock while the batch scanner is visible, taking it
again after the page is shown and on the first tap or key if Safari
refused it at load. The paused banner also follows visibilitychange.
Ignores 'Unidentified' and composing keys, logs the longest gap between
keys per scan, and unlocks speech on iOS on the first tap or scan.
Add Book's ISBN field opens the number pad with a Scan Text hint.
Author
Owner

Review from Nye (changes) — covers head 1f578f2

Ran the branch locally (dev, Playwright WebKit, iPhone 393x852 / 852x393) with the audit checks in scripts/mobile_check.py and hid_sim.py.

Works

  • F2 (14px inputs -> iOS zoom): mobile_check.py input-zoom now PASSES on /books, /books/new, /books/batch-scanner, /books/1/edit, /users/settings. The global pointer: coarse rule does it.
  • HID scans still land: hid_sim.py enter|tab|select-focused|button-focused all pass (2 of 2 scans POST each). Tab-ends-scan only mid-scan is the right call.
  • Merges cleanly onto current main 902e363 (with #70). No other review threads open.
  • Diagnostics ([batch-scanner] scan {chars, ms, endedBy, queued}, focus/blur) are good.

Blocking: F1 is not fixed on iPhone landscape
mobile_check.py camera-modal still FAILS at 852x393: {'vh': 393, 'box': 393, 'buttons': [['✕', 24, 68], ['Cancel', 399, 443]]}. Layout measured: header 24-68, info alert 84-130, scanner area 146-382 (236px), Cancel/status row 398-442.
Cause: the max-sm: variants (hide alert, full-width box, padding) don't apply in landscape because the width is 852 (>= sm). h-[min(600px,60svh)] + alert + header + footer is ~466px in a 393px viewport, so the status line and Cancel need an inner scroll.
Suggested fix (either):

  • make .modal-box flex flex-col max-h-[100svh] and give #barcode-scanner flex-1 min-h-0 (drop the fixed height on short screens), and hide the info alert on short screens with a height variant like [@media(max-height:500px)]:hidden; or
  • size the scan area h-[min(600px,calc(100svh-10rem))] and hide the alert under max-height:500px.
    Please prove F1 fixed with timeout 120 python3 mobile_check.py camera-modal (sent you the script).

Requested (from the iOS research; small)

  • Screen Wake Lock on the batch scanner: navigator.wakeLock?.request('screen') on load, re-request on visibilitychange when visible, console.info/warn on success/failure. Safari supports it (16.4+, and in Home Screen web apps since 18.4); without it an iPad on a stand auto-locks mid-batch and the HID scans go nowhere.
  • Also listen to visibilitychange (not only window blur/focus) for the "Scanner paused" banner: on iOS switching apps fires visibility changes more reliably than blur.

Not in this PR (fine): F3 row actions, F4 hover-only, F5 export/import sideways scroll still fail as expected; they're for mobile/pages.

Nit (pre-existing, not introduced here): result items build HTML with ${data.book.title}/author into innerHTML; a title with < would be parsed as markup. Worth escaping in a follow-up.

## Review from Nye (changes) — covers head 1f578f2 Ran the branch locally (dev, Playwright WebKit, iPhone 393x852 / 852x393) with the audit checks in scripts/mobile_check.py and hid_sim.py. **Works** - F2 (14px inputs -> iOS zoom): `mobile_check.py input-zoom` now PASSES on /books, /books/new, /books/batch-scanner, /books/1/edit, /users/settings. The global `pointer: coarse` rule does it. - HID scans still land: `hid_sim.py enter|tab|select-focused|button-focused` all pass (2 of 2 scans POST each). Tab-ends-scan only mid-scan is the right call. - Merges cleanly onto current main 902e363 (with #70). No other review threads open. - Diagnostics (`[batch-scanner] scan {chars, ms, endedBy, queued}`, focus/blur) are good. **Blocking: F1 is not fixed on iPhone landscape** `mobile_check.py camera-modal` still FAILS at 852x393: `{'vh': 393, 'box': 393, 'buttons': [['✕', 24, 68], ['Cancel', 399, 443]]}`. Layout measured: header 24-68, info alert 84-130, scanner area 146-382 (236px), Cancel/status row 398-442. Cause: the `max-sm:` variants (hide alert, full-width box, padding) don't apply in landscape because the width is 852 (>= sm). `h-[min(600px,60svh)]` + alert + header + footer is ~466px in a 393px viewport, so the status line and Cancel need an inner scroll. Suggested fix (either): - make `.modal-box` `flex flex-col max-h-[100svh]` and give `#barcode-scanner` `flex-1 min-h-0` (drop the fixed height on short screens), and hide the info alert on short screens with a height variant like `[@media(max-height:500px)]:hidden`; or - size the scan area `h-[min(600px,calc(100svh-10rem))]` and hide the alert under `max-height:500px`. Please prove F1 fixed with `timeout 120 python3 mobile_check.py camera-modal` (sent you the script). **Requested (from the iOS research; small)** - Screen Wake Lock on the batch scanner: `navigator.wakeLock?.request('screen')` on load, re-request on `visibilitychange` when visible, `console.info`/`warn` on success/failure. Safari supports it (16.4+, and in Home Screen web apps since 18.4); without it an iPad on a stand auto-locks mid-batch and the HID scans go nowhere. - Also listen to `visibilitychange` (not only window blur/focus) for the "Scanner paused" banner: on iOS switching apps fires visibility changes more reliably than blur. **Not in this PR (fine)**: F3 row actions, F4 hover-only, F5 export/import sideways scroll still fail as expected; they're for mobile/pages. Nit (pre-existing, not introduced here): result items build HTML with `${data.book.title}`/`author` into innerHTML; a title with `<` would be parsed as markup. Worth escaping in a follow-up.
Author
Owner

Review from Nye (approved) — covers head 2a6f174

Ran the branch locally (dev, Playwright WebKit at iPhone 393x852 / 852x393 and iPad 820x1180) with the audit checks.

Works

  • F6 fixed: the batch scanner takes a screen wake lock on load/first scan and takes it again after hidden -> visible (wake_lock_check.py, with the stub releasing locks on hide like the OS does: 1 then 2 requests).
  • HID scanner input still lands in all 4 cases (Enter suffix, Tab suffix, select focused, button focused): 2 batch-check POSTs each, focus untouched.
  • F1 camera modal (iPhone landscape) and F2 input zoom still pass.
  • Add Book ISBN field: inputmode=numeric, 16px on phone; the Scan Text hint shows on touch (pointer: coarse) and is hidden on desktop.
  • 'Unidentified'/isComposing guard and maxKeyGapMs in the scan log look right. CI green on 2a6f174; merges cleanly with #72.

Non-blocking notes

  • pointerdown from a touch isn't a user-activation event in the HTML spec (touch activation comes on pointerup/touchend/click), so on iPad/iPhone the first-tap retry may not unlock speech or get the wake lock. The first scan's keydown still does both, so it works in practice. If you touch it again, listen for click (or pointerup) instead of pointerdown.
  • Two requestWakeLock() calls racing before the first resolves could take two locks; harmless (both released on hide).
  • inputmode=numeric: fine to keep. Scanners and Scan Text read the EAN-13 (978...), and an ISBN-10 ending in X can still be pasted. Hand-typing an X ISBN-10 on iPhone isn't possible, which is rare enough to accept.
## Review from Nye (approved) — covers head 2a6f174 Ran the branch locally (dev, Playwright WebKit at iPhone 393x852 / 852x393 and iPad 820x1180) with the audit checks. **Works** - F6 fixed: the batch scanner takes a screen wake lock on load/first scan and takes it again after hidden -> visible (wake_lock_check.py, with the stub releasing locks on hide like the OS does: 1 then 2 requests). - HID scanner input still lands in all 4 cases (Enter suffix, Tab suffix, select focused, button focused): 2 batch-check POSTs each, focus untouched. - F1 camera modal (iPhone landscape) and F2 input zoom still pass. - Add Book ISBN field: inputmode=numeric, 16px on phone; the Scan Text hint shows on touch (pointer: coarse) and is hidden on desktop. - 'Unidentified'/isComposing guard and maxKeyGapMs in the scan log look right. CI green on 2a6f174; merges cleanly with #72. **Non-blocking notes** - `pointerdown` from a touch isn't a user-activation event in the HTML spec (touch activation comes on `pointerup`/`touchend`/`click`), so on iPad/iPhone the first-tap retry may not unlock speech or get the wake lock. The first scan's keydown still does both, so it works in practice. If you touch it again, listen for `click` (or `pointerup`) instead of `pointerdown`. - Two `requestWakeLock()` calls racing before the first resolves could take two locks; harmless (both released on hide). - inputmode=numeric: fine to keep. Scanners and Scan Text read the EAN-13 (978...), and an ISBN-10 ending in X can still be pasted. Hand-typing an X ISBN-10 on iPhone isn't possible, which is rare enough to accept.
jfro merged commit c56646920d into main 2026-10-25 18:31:55 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/fuzzy_catalog!71
No description provided.