forked from jsnbuchanan/crowd-funder-for-time-pwa
- Fix Vue template syntax in App.vue by using proper event handler format - Update Vite config to properly handle ESM imports and crypto modules - Add manual chunks for better code splitting - Improve environment variable handling in vite-env.d.ts - Fix TypeScript linting errors in App.vue
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { Capacitor } from '@capacitor/core'
|
|
import { CapacitorQRScanner } from './CapacitorQRScanner'
|
|
import type { QRScannerService } from './types'
|
|
import { logger } from '../../utils/logger'
|
|
import { WebDialogQRScanner } from './WebDialogQRScanner'
|
|
|
|
// Import platform-specific flags from Vite config
|
|
declare const __USE_QR_READER__: boolean
|
|
declare const __IS_MOBILE__: boolean
|
|
|
|
export class QRScannerFactory {
|
|
private static instance: QRScannerService | null = null
|
|
|
|
static getInstance(): QRScannerService {
|
|
if (!this.instance) {
|
|
// Use platform-specific flags for more accurate detection
|
|
if (__IS_MOBILE__ || Capacitor.isNativePlatform()) {
|
|
logger.log('Creating native QR scanner instance')
|
|
this.instance = new CapacitorQRScanner()
|
|
} else if (__USE_QR_READER__) {
|
|
logger.log('Creating web QR scanner instance')
|
|
this.instance = new WebDialogQRScanner()
|
|
} else {
|
|
throw new Error(
|
|
'No QR scanner implementation available for this platform'
|
|
)
|
|
}
|
|
}
|
|
return this.instance
|
|
}
|
|
|
|
static async cleanup() {
|
|
if (this.instance) {
|
|
await this.instance.cleanup()
|
|
this.instance = null
|
|
}
|
|
}
|
|
}
|