diff --git a/app/_layout.tsx b/app/_layout.tsx index f8640ce..dee4645 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -22,7 +22,7 @@ Sentry.init({ sendDefaultPii: true, enableLogs: true, // debug: true, - // enabled: !__DEV__, // 仅在生产环境启用 Sentry + enabled: !__DEV__, // 仅在生产环境启用 Sentry }) // 目前无需求,先注释掉 diff --git a/ble/hooks/useBleExplorer.ts b/ble/hooks/useBleExplorer.ts index 52107a3..7ac6b75 100644 --- a/ble/hooks/useBleExplorer.ts +++ b/ble/hooks/useBleExplorer.ts @@ -143,7 +143,7 @@ export const useBleExplorer = () => { logToSentry('device_discovered_batch') setState((prev) => { - const newDevices = devicesToAdd.filter((nd) => !prev.discoveredDevices.some((ed) => ed.id === nd.id)) + const newDevices = devicesToAdd.filter((nd) => !prev.discoveredDevices?.some((ed) => ed?.id === nd?.id)) if (newDevices.length === 0) return prev console.debug(`Batch adding ${newDevices.length} devices`) return { ...prev, discoveredDevices: [...prev.discoveredDevices, ...newDevices] } @@ -154,7 +154,7 @@ export const useBleExplorer = () => { const queueDevice = useCallback( (device: BleDevice) => { // 检查是否已在队列中 - if (pendingDevicesRef.current.some((d) => d?.id === device?.id)) return + if (pendingDevicesRef.current?.some((d) => d?.id === device?.id)) return pendingDevicesRef.current.push(device) @@ -348,12 +348,14 @@ export const useBleExplorer = () => { // console.log('startScan--------', device) - if (!hasTargetService || !device.id) { + if (!hasTargetService || !device?.id) { return } device.connected = false - console.debug(`Device found: ${device.name} (${device.id}), serviceUUIDs: ${device.serviceUUIDs}`) + console.debug( + `Device found: ${device.name} (${device.id}), serviceUUIDs: ${JSON.stringify(device.serviceUUIDs)}`, + ) // 使用队列批量更新,避免频繁触发 setState queueDevice(device) diff --git a/hooks/use-update-checker.ts b/hooks/use-update-checker.ts index 298edde..95d545b 100644 --- a/hooks/use-update-checker.ts +++ b/hooks/use-update-checker.ts @@ -1,6 +1,6 @@ +import * as Sentry from '@sentry/react-native' import * as Updates from 'expo-updates' import { useEffect, useState } from 'react' -import * as Sentry from '@sentry/react-native' interface UseUpdateCheckerOptions { /** 检查更新的间隔时间(毫秒),默认1分钟 */