forked from jsnbuchanan/crowd-funder-for-time-pwa
chore: updates for qr code reader rules, linting, and cleanup
This commit is contained in:
@@ -14,11 +14,11 @@ The QR code scanning functionality follows a platform-agnostic design using a fa
|
||||
1. **Factory Pattern**
|
||||
- `QRScannerFactory` - Creates appropriate scanner instance based on platform
|
||||
- Common interface `QRScannerService` implemented by all scanners
|
||||
- Platform detection via Vite config flags: `__USE_QR_READER__` and `__IS_MOBILE__`
|
||||
- Platform detection via Capacitor and build flags
|
||||
|
||||
2. **Platform-Specific Implementations**
|
||||
- `CapacitorQRScanner` - Native mobile implementation
|
||||
- `WebDialogQRScanner` - Web browser implementation
|
||||
- `CapacitorQRScanner` - Native mobile implementation using MLKit
|
||||
- `WebInlineQRScanner` - Web browser implementation using MediaDevices API
|
||||
- `QRScannerDialog.vue` - Shared UI component
|
||||
|
||||
## Mobile Implementation (Capacitor)
|
||||
@@ -54,13 +54,13 @@ MLKitBarcodeScanner: {
|
||||
## Web Implementation
|
||||
|
||||
### Technology Stack
|
||||
- Uses `vue-qrcode-reader` library
|
||||
- Browser's MediaDevices API
|
||||
- Vue.js dialog component
|
||||
- Uses browser's MediaDevices API
|
||||
- Vue.js components for UI
|
||||
- EventEmitter for stream management
|
||||
|
||||
### Key Features
|
||||
- Browser-based camera access
|
||||
- Fallback UI for unsupported browsers
|
||||
- Inline camera preview
|
||||
- Responsive design
|
||||
- Cross-browser compatibility
|
||||
- Progressive enhancement
|
||||
@@ -97,9 +97,10 @@ MLKitBarcodeScanner: {
|
||||
|
||||
### Platform Detection
|
||||
```typescript
|
||||
if (__IS_MOBILE__ || Capacitor.isNativePlatform()) {
|
||||
const isNative = QRScannerFactory.isNativePlatform();
|
||||
if (isNative) {
|
||||
// Use native scanner
|
||||
} else if (__USE_QR_READER__) {
|
||||
} else {
|
||||
// Use web scanner
|
||||
}
|
||||
```
|
||||
@@ -112,6 +113,9 @@ await scanner.startScan();
|
||||
scanner.addListener({
|
||||
onScan: (result) => {
|
||||
// Handle scan result
|
||||
},
|
||||
onError: (error) => {
|
||||
// Handle error
|
||||
}
|
||||
});
|
||||
```
|
||||
@@ -145,4 +149,29 @@ scanner.addListener({
|
||||
2. Verify permission flows
|
||||
3. Check error handling
|
||||
4. Validate cleanup
|
||||
5. Verify cross-platform behavior
|
||||
5. Verify cross-platform behavior
|
||||
|
||||
## Service Interface
|
||||
|
||||
```typescript
|
||||
interface QRScannerService {
|
||||
checkPermissions(): Promise<boolean>;
|
||||
requestPermissions(): Promise<boolean>;
|
||||
isSupported(): Promise<boolean>;
|
||||
startScan(options?: QRScannerOptions): Promise<void>;
|
||||
stopScan(): Promise<void>;
|
||||
addListener(listener: ScanListener): void;
|
||||
onStream(callback: (stream: MediaStream | null) => void): void;
|
||||
cleanup(): Promise<void>;
|
||||
}
|
||||
|
||||
interface ScanListener {
|
||||
onScan: (result: string) => void;
|
||||
onError?: (error: Error) => void;
|
||||
}
|
||||
|
||||
interface QRScannerOptions {
|
||||
camera?: "front" | "back";
|
||||
showPreview?: boolean;
|
||||
playSound?: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user