From ddb7fda36f56831d3df5b35388e4d204ab118574 Mon Sep 17 00:00:00 2001 From: km2025 Date: Wed, 31 Dec 2025 16:44:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Sentry=20=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E6=9D=A1=E4=BB=B6=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83=E4=B8=AD=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=90=AF=E7=94=A8=EF=BC=9B=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E9=80=BB=E8=BE=91=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=BD=9C=E5=9C=A8=E7=9A=84=E7=A9=BA=E5=80=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/_layout.tsx | 2 +- ble/hooks/useBleExplorer.ts | 10 ++++++---- hooks/use-update-checker.ts | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) 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分钟 */