Skip to content

fix: prefer rear camera by default - #29

Merged
LittleSound merged 2 commits into
mainfrom
fix/default-rear-camera
Oct 20, 2026
Merged

LittleSound merged 2 commits into
mainfrom
fix/default-rear-camera

Conversation

@LittleSound

Copy link
Copy Markdown
Member

Fixes #26

Root cause

Scan.vue picked cameras[0] from enumerateDevices() (arbitrary order, often the front camera on phones), persisted it to localStorage, and passed it to qr-scanner as an exact deviceId on every visit — overriding qr-scanner's 'environment' default. Extra permission prompts came from useDevicesList({ requestPermissions: true }) opening its own stream, plus the scanner being recreated on every camera change.

Changes

  • Default to facingMode: environment; only an explicit user pick is persisted (new key qrs-camera-choice, legacy qrs-selected-camera is removed so users with an auto-saved front camera get the rear one again). Stale stored ids are cleared once enumeration proves they're gone.
  • Label-based rear-camera fallback for browsers that ignore facingMode (prefers iPhone "Back Triple/Dual Wide" virtual devices that auto-switch to macro; skips ultra-wide/telephoto).
  • No separate permission stream; camera switch is a single setCamera().
  • All scanner operations are serialized through a small queue (createCameraQueue) with a generation counter, so overlapping start/switch can't leak streams or override the user's choice; disposed on unmount (also fixes a pre-existing leak when unmounting during the scan-speed rebuild).
  • Pure logic in utils/camera.ts, covered by test/camera.test.ts and test/camera-queue.test.ts.

Verification

  • pnpm run lint, vue-tsc, pnpm run generate: pass
  • Camera tests (19): pass. test/slicing.test.ts snapshot and packages/generate resolve failures are pre-existing on main and fixed separately in the dependency-update branch.
  • Not yet tested on real devices.

Manual QA checklist

  • iOS Safari / Android Chrome first visit: rear main camera, single permission prompt
  • Pick front, reload → kept; pick rear again works; highlight matches active camera
  • Multi-lens Android: camera list & default lens
  • Fast camera switching leaves no camera light on for the unused camera
  • Change scan speed then leave the page within ~1s → camera turns off
  • Desktop: built-in camera still opens; permission denied shows error

@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for qrss ready!

Name Link
🔨 Latest commit 4b69502
🔍 Latest deploy log https://app.netlify.com/projects/qrss/deploys/6ad74ee3229184a596c37ac6
😎 Deploy Preview https://deploy-preview-29--qrss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@LittleSound
LittleSound merged commit fd1a428 into main Oct 20, 2026
6 checks passed
@LittleSound
LittleSound deleted the fix/default-rear-camera branch October 20, 2026 12:12
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.

Make it so the back:0 camera is the default to be turned on

1 participant