Skip to content

feat: implement QR scanner#106

Open
2witstudios wants to merge 3 commits intomainfrom
ppg/issue-81-qr-scanner
Open

feat: implement QR scanner#106
2witstudios wants to merge 3 commits intomainfrom
ppg/issue-81-qr-scanner

Conversation

@2witstudios
Copy link
Owner

Summary

  • Implements camera-based QR code scanner for pairing with ppg server
  • Parses ppg://connect?host=...&port=...&ca=...&token=... URL scheme
  • Adds ca (certificate authority) field to ServerConnection for TLS pinning

Changes

QRScannerView.swift (new)

  • QRScannerView — SwiftUI view with camera permission handling, error alerts, scan overlay
  • QRCameraViewUIViewRepresentable wrapping AVCaptureSession with AVCaptureMetadataOutput for QR detection
  • CameraPreviewViewUIView subclass with layoutSubviews for proper preview bounds
  • Double-scan prevention via hasScanned flag in coordinator
  • Session lifecycle: starts on creation, stops via dismantleUIView

ServerConnection.swift (updated)

  • New ca: String? field for TLS certificate pinning
  • Updated fromQRCode() to parse ppg://connect?... query-param format
  • baseURL/wsURL auto-select https/wss when ca is present

Test plan

  • Verify camera permission prompt appears on first launch
  • Verify denied permission shows "Open Settings" fallback UI
  • Scan valid ppg://connect?host=...&port=...&token=... QR — should connect
  • Scan valid QR with &ca=... — should connect over TLS
  • Scan non-ppg QR code — should show error alert
  • Scan invalid ppg QR (missing token) — should show error alert
  • Verify double-scan prevention (same QR not processed twice)
  • Verify camera preview resizes correctly on rotation

Closes #81

- QRScannerView with AVCaptureSession wrapped in UIViewRepresentable
- QR code detection via AVCaptureMetadataOutput for .qr type
- Parse ppg://connect?host=...&port=...&ca=...&token=... scheme
- Double-scan prevention via hasScanned flag in coordinator
- Error alerts for invalid QR codes with expected format hint
- CameraPreviewView subclass for proper bounds management via layoutSubviews
- Camera permission request handling with denied state UI and Settings link
- Session lifecycle: start on create, stop on dismantle via dismantleUIView
- ServerConnection updated with optional ca field for TLS certificate pinning
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Warning

Rate limit exceeded

@2witstudios has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 38 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 34deb69 and 81129df.

📒 Files selected for processing (4)
  • ios/PPGMobile/PPGMobile/Models/ServerConnection.swift
  • ios/PPGMobile/PPGMobile/Models/ServerConnectionTests.swift
  • ios/PPGMobile/PPGMobile/Views/Settings/QRScannerView.swift
  • src/commands/spawn.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ppg/issue-81-qr-scanner

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Percent-encode token in wsURL to prevent malformed URLs with special chars
- Use Dictionary(uniquingKeysWith:) to prevent crash on duplicate query params
- Validate ca field as base64 before accepting it
- Dispatch stopSession to background queue to avoid main thread blocking
- Add ServerConnectionTests with comprehensive fromQRCode parser coverage
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.

Implement QR scanner

1 participant