fix: 修复 Sentry 启用条件,确保在生产环境中正确启用;优化设备过滤逻辑,避免潜在的空值错误

This commit is contained in:
康猛 2025-12-31 16:44:45 +08:00
parent 3d60954547
commit ddb7fda36f
3 changed files with 8 additions and 6 deletions

View File

@ -22,7 +22,7 @@ Sentry.init({
sendDefaultPii: true, sendDefaultPii: true,
enableLogs: true, enableLogs: true,
// debug: true, // debug: true,
// enabled: !__DEV__, // 仅在生产环境启用 Sentry enabled: !__DEV__, // 仅在生产环境启用 Sentry
}) })
// 目前无需求,先注释掉 // 目前无需求,先注释掉

View File

@ -143,7 +143,7 @@ export const useBleExplorer = () => {
logToSentry('device_discovered_batch') logToSentry('device_discovered_batch')
setState((prev) => { 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 if (newDevices.length === 0) return prev
console.debug(`Batch adding ${newDevices.length} devices`) console.debug(`Batch adding ${newDevices.length} devices`)
return { ...prev, discoveredDevices: [...prev.discoveredDevices, ...newDevices] } return { ...prev, discoveredDevices: [...prev.discoveredDevices, ...newDevices] }
@ -154,7 +154,7 @@ export const useBleExplorer = () => {
const queueDevice = useCallback( const queueDevice = useCallback(
(device: BleDevice) => { (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) pendingDevicesRef.current.push(device)
@ -348,12 +348,14 @@ export const useBleExplorer = () => {
// console.log('startScan--------', device) // console.log('startScan--------', device)
if (!hasTargetService || !device.id) { if (!hasTargetService || !device?.id) {
return return
} }
device.connected = false 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 // 使用队列批量更新,避免频繁触发 setState
queueDevice(device) queueDevice(device)

View File

@ -1,6 +1,6 @@
import * as Sentry from '@sentry/react-native'
import * as Updates from 'expo-updates' import * as Updates from 'expo-updates'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import * as Sentry from '@sentry/react-native'
interface UseUpdateCheckerOptions { interface UseUpdateCheckerOptions {
/** 检查更新的间隔时间毫秒默认1分钟 */ /** 检查更新的间隔时间毫秒默认1分钟 */