themblem/scanner/QR_SCANNER_MODULE_PROGRESS.md
Fam Zheng 0aacad31f4 emblemscanner: add camera rules, web-view fallback, and loading state
Major enhancements to the emblemscanner module:

**Camera System:**
- Device-specific camera rules from Themblem API
- Web-view fallback for problematic devices in same page
- Loading spinner prevents camera mode jumping
- Debug mode with comprehensive diagnostics

**Self-contained Architecture:**
- Inline utility functions (no external dependencies)
- Camera rule matching and API integration
- Web-view URL generation with proper parameters
- Message handling for web-view QR results

**UI Improvements:**
- Hide overlays during loading state
- Enhanced debug overlay with camera rule info
- Worker/native camera mode detection
- Loading feedback with "初始化相机..." message

Module is now production-ready for camera setup and UI, with framework for QR processing integration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 21:27:29 +00:00

6.0 KiB

QR Scanner Module Development Progress

Project Goal

Create a self-contained, portable QR scanning page module that can be easily integrated into other WeChat Mini Programs. The module should include all scanning functionality in a single directory and accept an entry query parameter to redirect to different pages upon successful scan and verification.

Feature Checklist - Extracted from Existing Code

Core QR Processing

  • WebAssembly QR Tool Integration - qrtool.wx.js library for QR code processing (TODO: Add library)
  • Dual Processing Modes:
    • Worker-based processing (iPhone devices) - worker/index.js (TODO: Implement)
    • Synchronous processing (Android devices) - precheck.js (TODO: Implement)
  • QR Pattern Validation - Emblem-specific QR code pattern matching (TODO: Add validation)
  • Frame Pre-checking - Validate QR frames before full processing (TODO: Implement)
  • Angle Detection - QR code angle detection and correction (TODO: Implement)

Camera System

  • Native Camera Interface - WeChat camera component integration
  • Web-view Camera Fallback - Integrated web-view for problematic devices
  • Device-specific Camera Rules - API-driven zoom and camera settings per phone model
  • Loading State Management - Spinner while camera rules load, prevents mode jumping
  • Dynamic Zoom Control - Initial zoom + QR-found zoom adjustment (TODO: Implement)
  • Torch/Flash Control - Manual and automatic torch management
  • Auto-torch Detection - API-based torch recommendation system (TODO: Implement API integration)

UI Components & Visual Feedback

  • QR Targeting Overlay - Animated corner arcs for QR positioning
  • Visual State Indicators - Progress states (searching, found, verifying)
  • Hint Text System - Dynamic user guidance messages
  • Debug Overlay - Development/diagnostic information display
  • Modal System:
    • Verification spinner (verifyspin)
    • Failed verification (verifyfailed)
    • Scan guide tutorial (scanguide)
    • Service modal (servicemodal)
    • Tooltip component (tooltip)

API Integration & Data Flow

  • Image Upload System - Multi-frame submission to backend
  • Verification Pipeline - QR code verification with themblem.com API
  • Camera Rules API - Device-specific camera configuration fetching
  • Auto-torch API - Torch recommendation based on QR code
  • Event Tracking - Frame upload and analytics events
  • Session Management - Unique session ID generation and tracking

Phone Model & Runtime Configuration

  • Device Detection - Phone model identification and global data storage
  • Processing Mode Selection - Worker vs synchronous based on device type
  • Camera Sensitivity Adjustment - Device-specific camera sensitivity settings

Navigation & Integration

  • Entry Point Configuration - Support for return page query parameter
  • Return Page Routing - Navigate to specified page after successful scan and verification

Assets & Resources

  • Static Image Assets:
    • QR targeting arcs (arc.png)
    • QR positioning markers (qrmarkers.png)
    • UI action icons (play-button.png, flash-button.png)
  • WebAssembly Binary - qrtool.wx.js QR processing library (TODO: Add for QR detection)
  • CSS Animations - Pure CSS animations for QR targeting arcs and loading spinner

Integration Requirements

Required Query Parameters

  • return_page - Target page to navigate to after successful verification

Required Global Dependencies

  • WeChat Mini Program camera API
  • WebAssembly support
  • Worker thread support (iOS)
  • Canvas 2D context for image processing

External API Dependencies

  • {server_url}/api/v1/camera-rules/ - Camera configuration
  • {server_url}/api/v1/check-auto-torch/ - Torch recommendations
  • Verification endpoint for QR code validation
  • Event tracking endpoints

Success Criteria

  1. Self-contained Module - All functionality within single directory
  2. Platform Portability - Easy integration into other mini programs
  3. Device Compatibility - Support for iOS/Android with appropriate fallbacks
  4. Performance Optimization - Efficient WebAssembly + Worker threading
  5. Robust Error Handling - Graceful failure modes and user feedback
  6. Configurable Integration - Flexible redirect and mode parameters
  7. Asset Independence - Bundled resources with minimal external dependencies
  8. No External Dependencies - Cannot reference utils.js or other external files, all code must be inline

Current Status: CORE IMPLEMENTATION COMPLETE

COMPLETED FEATURES:

Core Infrastructure:

  • Self-contained module at pages/emblemscanner/
  • WeChat native camera with full overlay system
  • Web-view camera fallback for problematic devices
  • Device-specific camera rules from Themblem API
  • Loading state management with spinner
  • Debug mode with comprehensive diagnostics

UI & Visual Feedback:

  • Animated QR targeting arcs (sm/lg sizes)
  • QR markers overlay with proper positioning
  • Inline modal system (verification, failed, guide, service)
  • Torch/flash controls with visual feedback
  • Dynamic hint text system
  • Debug overlay with device/camera rule info

Integration & Navigation:

  • Return page routing via query parameter
  • Debug mode activation (5-tap or ?debug=1)
  • Complete asset bundle (arc.png, qrmarkers.png, buttons)
  • No external dependencies (all utility code inline)

🔧 NEXT STEPS:

  1. QR Processing Integration - Add WebAssembly qrtool.wx.js library
  2. Worker Implementation - iPhone WebAssembly worker setup
  3. Frame Processing - QR code detection and validation logic
  4. API Integration - Upload and verification pipeline
  5. Performance Optimization - Frame throttling and batch processing