feat(mobile): package frontend into native Android APK with Capacitor (camera, cleartext LAN traffic & dynamic server IP)
This commit is contained in:
@@ -13,6 +13,8 @@ import {
|
||||
HybridBinarizer,
|
||||
GlobalHistogramBinarizer,
|
||||
} from '@zxing/library';
|
||||
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
import { accessApi } from '../../api/accessApi';
|
||||
import { DNIParsedResult } from '../../types';
|
||||
|
||||
@@ -560,6 +562,43 @@ export const CameraScannerModal: React.FC<CameraScannerModalProps> = ({
|
||||
reader.readAsDataURL(file);
|
||||
};
|
||||
|
||||
// Captura nativa con plugin oficial de Capacitor (Android Tablet Samsung)
|
||||
const handleCapacitorPhoto = async () => {
|
||||
if (!Capacitor.isNativePlatform()) {
|
||||
fileInputRef.current?.click();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const photo = await Camera.getPhoto({
|
||||
quality: 92,
|
||||
allowEditing: false,
|
||||
resultType: CameraResultType.DataUrl,
|
||||
source: CameraSource.Camera,
|
||||
});
|
||||
|
||||
if (photo.dataUrl) {
|
||||
stopCamera();
|
||||
const img = new Image();
|
||||
img.onload = async () => {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
setCapturedPhotoUrl(photo.dataUrl!);
|
||||
await processImageExtraction(canvas);
|
||||
}
|
||||
};
|
||||
img.src = photo.dataUrl;
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (err.message && !err.message.includes('User cancelled') && !err.message.includes('cancelled')) {
|
||||
setErrorMsg(`Error en cámara nativa: ${err.message}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Reintentar captura volviendo a la cámara en vivo
|
||||
const handleRetake = () => {
|
||||
setCapturedPhotoUrl(null);
|
||||
@@ -1002,11 +1041,11 @@ export const CameraScannerModal: React.FC<CameraScannerModalProps> = ({
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
onClick={handleCapacitorPhoto}
|
||||
style={{ minHeight: '54px', padding: '0 1rem', fontSize: '0.9rem' }}
|
||||
title="Tomar foto con app nativa o subir archivo"
|
||||
title="Tomar foto con app nativa de cámara o subir archivo"
|
||||
>
|
||||
📁 Galería / App
|
||||
📸 Cámara App / Galería
|
||||
</button>
|
||||
</>
|
||||
) : step === 'SUCCESS' ? (
|
||||
|
||||
Reference in New Issue
Block a user