forked from trent_larson/crowd-funder-for-time-pwa
fix: update Vue template syntax and improve Vite config
- 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
This commit is contained in:
@@ -1,88 +1,88 @@
|
||||
import {
|
||||
BarcodeScanner,
|
||||
BarcodeFormat,
|
||||
LensFacing,
|
||||
} from "@capacitor-mlkit/barcode-scanning";
|
||||
import type { PluginListenerHandle } from "@capacitor/core";
|
||||
import { QRScannerService, ScanListener } from "./types";
|
||||
LensFacing
|
||||
} from '@capacitor-mlkit/barcode-scanning'
|
||||
import type { PluginListenerHandle } from '@capacitor/core'
|
||||
import { QRScannerService, ScanListener } from './types'
|
||||
|
||||
export class NativeQRScanner implements QRScannerService {
|
||||
private scanListener: ScanListener | null = null;
|
||||
private isScanning = false;
|
||||
private listenerHandle: PluginListenerHandle | null = null;
|
||||
private scanListener: ScanListener | null = null
|
||||
private isScanning = false
|
||||
private listenerHandle: PluginListenerHandle | null = null
|
||||
|
||||
async checkPermissions(): Promise<boolean> {
|
||||
const { camera } = await BarcodeScanner.checkPermissions();
|
||||
return camera === "granted";
|
||||
const { camera } = await BarcodeScanner.checkPermissions()
|
||||
return camera === 'granted'
|
||||
}
|
||||
|
||||
async requestPermissions(): Promise<boolean> {
|
||||
const { camera } = await BarcodeScanner.requestPermissions();
|
||||
return camera === "granted";
|
||||
const { camera } = await BarcodeScanner.requestPermissions()
|
||||
return camera === 'granted'
|
||||
}
|
||||
|
||||
async isSupported(): Promise<boolean> {
|
||||
const { supported } = await BarcodeScanner.isSupported();
|
||||
return supported;
|
||||
const { supported } = await BarcodeScanner.isSupported()
|
||||
return supported
|
||||
}
|
||||
|
||||
async startScan(): Promise<void> {
|
||||
if (this.isScanning) {
|
||||
throw new Error("Scanner is already running");
|
||||
throw new Error('Scanner is already running')
|
||||
}
|
||||
|
||||
try {
|
||||
this.isScanning = true;
|
||||
this.isScanning = true
|
||||
await BarcodeScanner.startScan({
|
||||
formats: [BarcodeFormat.QrCode],
|
||||
lensFacing: LensFacing.Back,
|
||||
});
|
||||
lensFacing: LensFacing.Back
|
||||
})
|
||||
|
||||
this.listenerHandle = await BarcodeScanner.addListener(
|
||||
"barcodesScanned",
|
||||
'barcodesScanned',
|
||||
async (result) => {
|
||||
if (result.barcodes.length > 0 && this.scanListener) {
|
||||
const barcode = result.barcodes[0];
|
||||
this.scanListener.onScan(barcode.rawValue);
|
||||
await this.stopScan();
|
||||
const barcode = result.barcodes[0]
|
||||
this.scanListener.onScan(barcode.rawValue)
|
||||
await this.stopScan()
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
)
|
||||
} catch (error) {
|
||||
this.isScanning = false;
|
||||
this.isScanning = false
|
||||
if (this.scanListener?.onError) {
|
||||
this.scanListener.onError(new Error(String(error)));
|
||||
this.scanListener.onError(new Error(String(error)))
|
||||
}
|
||||
throw error;
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async stopScan(): Promise<void> {
|
||||
if (!this.isScanning) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await BarcodeScanner.stopScan();
|
||||
this.isScanning = false;
|
||||
await BarcodeScanner.stopScan()
|
||||
this.isScanning = false
|
||||
} catch (error) {
|
||||
if (this.scanListener?.onError) {
|
||||
this.scanListener.onError(new Error(String(error)));
|
||||
this.scanListener.onError(new Error(String(error)))
|
||||
}
|
||||
throw error;
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
addListener(listener: ScanListener): void {
|
||||
this.scanListener = listener;
|
||||
this.scanListener = listener
|
||||
}
|
||||
|
||||
async cleanup(): Promise<void> {
|
||||
await this.stopScan();
|
||||
await this.stopScan()
|
||||
if (this.listenerHandle) {
|
||||
await this.listenerHandle.remove();
|
||||
this.listenerHandle = null;
|
||||
await this.listenerHandle.remove()
|
||||
this.listenerHandle = null
|
||||
}
|
||||
this.scanListener = null;
|
||||
this.scanListener = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user