You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
1.2 KiB

import { Capacitor } from '@capacitor/core'
import type { QRScannerService } from './types'
import { logger } from '../../utils/logger'
import { WebDialogQRScanner } from './WebDialogScanner'
import { CapacitorQRScanner } from './CapacitorScanner'
// 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
}
}
}