From f74d5883052f0b4517ea0e1d25ac26fe99e48898 Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 31 Oct 2024 19:14:55 +0000 Subject: [PATCH] Update useNFC --- src/hooks/useNFC.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hooks/useNFC.ts b/src/hooks/useNFC.ts index 31985dd..5fd3dc6 100644 --- a/src/hooks/useNFC.ts +++ b/src/hooks/useNFC.ts @@ -1,25 +1,31 @@ import { useCallback, useEffect, useState } from 'react'; import { is_fully } from '../utils/is_fully'; -export const useNFC = (config?: - { onNdef: (serial: string, message: string, data: string) => void, onNfcTagDiscovered: (serial: string, type: string, message: string, data: string) => void, onNfcTagRemoved: (serial: string) => void }) => { - if (!is_fully()) { - return; +const preflight = () => { + if (!is_fully) { + alert('Fully not available'); + throw new Error('Fully not available'); } +}; +export const useNFC = (config?: + { onNdef?: (serial: string, message: string, data: string) => void, onNfcTagDiscovered?: (serial: string, type: string, message: string, data: string) => void, onNfcTagRemoved?: (serial: string) => void }) => { const [isScanning, setIsScanning] = useState(false); const start = useCallback(() => { + preflight(); fully.nfcScanStart(); setIsScanning(true); }, []); const stop = useCallback(() => { + preflight(); fully.nfcScanStop(); setIsScanning(false); }, []); useEffect(() => { + preflight(); // @ts-ignore window.onNdefDiscovered = (serial: string, message: string, data: string) => { if (config?.onNdef) {