fix:优化storage逻辑、解绑后断开设备

This commit is contained in:
康猛 2026-01-14 18:13:49 +08:00
parent 7349d62046
commit 09e1caddf2
8 changed files with 24 additions and 30 deletions

View File

@ -46,7 +46,7 @@ const VideoBox = ({ url, needWeb = true, width = 256, style, ...videoProps }: Pr
try { try {
// 先尝试从缓存获取 // 先尝试从缓存获取
const cachedUrl = await videoUrlCache.get(url!, width) const cachedUrl = await videoUrlCache.get(url!, width)
console.log('getRedirectUrl cachedUrl-----------', url, cachedUrl) // console.log('getRedirectUrl cachedUrl-----------', url, cachedUrl)
if (cachedUrl) { if (cachedUrl) {
setUrlFinal(cachedUrl) setUrlFinal(cachedUrl)
return return
@ -56,7 +56,6 @@ const VideoBox = ({ url, needWeb = true, width = 256, style, ...videoProps }: Pr
const webpUrl = createUrl(url!) const webpUrl = createUrl(url!)
const finalUrl = await resolveRedirect(webpUrl) const finalUrl = await resolveRedirect(webpUrl)
console.log('getRedirectUrl finalUrl-----------', url, finalUrl)
// 缓存结果 // 缓存结果
await videoUrlCache.set(url!, finalUrl, width) await videoUrlCache.set(url!, finalUrl, width)

View File

@ -123,15 +123,13 @@ const Sync = observer(() => {
} }
}, [posts]) }, [posts])
console.log('selectedItem-----------', selectedItem) // console.log('selectedItem-----------', selectedItem)
const canSync = useMemo(() => { const canSync = useMemo(() => {
return !!connectedDevice?.id && !!selectedItem?.imageUrl return !!connectedDevice?.id && !!selectedItem?.imageUrl
}, [connectedDevice, selectedItem]) }, [connectedDevice, selectedItem])
const handleSync = useCallback(async () => { const handleSync = useCallback(async () => {
console.log('selectedItem?.imageUrl-----------', selectedItem?.imageUrl)
if (!canSync) { if (!canSync) {
Toast.show({ title: '请先连接设备' }) Toast.show({ title: '请先连接设备' })
return return
@ -505,7 +503,7 @@ const SpinningLoader = memo(() => {
const DeviceItem = observer(({ device }: { device: any }) => { const DeviceItem = observer(({ device }: { device: any }) => {
const { name = 'Unknown Device', id, connected: isConnected } = device const { name = 'Unknown Device', id, connected: isConnected } = device
const bindDevice = bleStore.bindDeviceList.find((d) => d?.id === id) const bindDevice = bleStore.bindDeviceList?.find((d) => d?.id === id)
const [nameShow, setNameShow] = useState(bindDevice ? `${bindDevice?.name}` : name) const [nameShow, setNameShow] = useState(bindDevice ? `${bindDevice?.name}` : name)
const tempName = useRef(nameShow) const tempName = useRef(nameShow)
@ -554,6 +552,7 @@ const DeviceItem = observer(({ device }: { device: any }) => {
onConfirm={() => { onConfirm={() => {
Toast.hideModal() Toast.hideModal()
unbindDevice(device) unbindDevice(device)
bleManager.disconnectDevice()
}} }}
/>, />,
) )

View File

@ -3,6 +3,7 @@ import 'react-native-reanimated'
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native' import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native'
import * as Sentry from '@sentry/react-native' import * as Sentry from '@sentry/react-native'
import { useKeepAwake } from 'expo-keep-awake'
import { Stack, useNavigationContainerRef } from 'expo-router' import { Stack, useNavigationContainerRef } from 'expo-router'
import { StatusBar } from 'expo-status-bar' import { StatusBar } from 'expo-status-bar'
import { useEffect } from 'react' import { useEffect } from 'react'
@ -100,6 +101,7 @@ function RootLayout() {
function Providers({ children }: { children: React.ReactNode }) { function Providers({ children }: { children: React.ReactNode }) {
const colorScheme = useColorScheme() const colorScheme = useColorScheme()
useUserSession() useUserSession()
useKeepAwake()
return ( return (
<SafeAreaProvider> <SafeAreaProvider>

View File

@ -37,6 +37,7 @@
"expo-image-manipulator": "~14.0.8", "expo-image-manipulator": "~14.0.8",
"expo-image-picker": "~17.0.8", "expo-image-picker": "~17.0.8",
"expo-insights": "~0.10.8", "expo-insights": "~0.10.8",
"expo-keep-awake": "~15.0.8",
"expo-linear-gradient": "^15.0.8", "expo-linear-gradient": "^15.0.8",
"expo-linking": "^8.0.10", "expo-linking": "^8.0.10",
"expo-media-library": "~18.2.0", "expo-media-library": "~18.2.0",

View File

@ -19,7 +19,6 @@ const BannerSection = memo<BannerProps>(function Banner({ bgVideo }) {
setBgurl(bgVideo) setBgurl(bgVideo)
}, [bgVideo]) }, [bgVideo])
return null
return ( return (
<Block className="absolute inset-0 z-0 overflow-hidden"> <Block className="absolute inset-0 z-0 overflow-hidden">
<VideoBox style={{ width: screenWidth, height: screenHeight }} url={bgUrl} width={512} /> <VideoBox style={{ width: screenWidth, height: screenHeight }} url={bgUrl} width={512} />

View File

@ -65,6 +65,7 @@
"expo-image-manipulator": "~14.0.8", "expo-image-manipulator": "~14.0.8",
"expo-image-picker": "~17.0.8", "expo-image-picker": "~17.0.8",
"expo-insights": "~0.10.8", "expo-insights": "~0.10.8",
"expo-keep-awake": "~15.0.8",
"expo-linear-gradient": "^15.0.8", "expo-linear-gradient": "^15.0.8",
"expo-linking": "^8.0.10", "expo-linking": "^8.0.10",
"expo-media-library": "~18.2.0", "expo-media-library": "~18.2.0",

View File

@ -71,33 +71,33 @@ class BleStore {
setGalleryList(contents: string[]) { setGalleryList(contents: string[]) {
this.galleryList = contents this.galleryList = contents
storage.set('ble_contents', JSON.stringify(contents)) storage.set('ble_contents', contents)
} }
addGalleryItem(content: string) { addGalleryItem(content: string) {
if (this.galleryList.includes(content)) return if (this.galleryList?.includes(content)) return
this.galleryList.push(content) this.galleryList?.push(content)
storage.set('ble_contents', JSON.stringify(this.galleryList)) storage.set('ble_contents', this.galleryList)
} }
removeGalleryItem(key: string) { removeGalleryItem(key: string) {
this.galleryList = this.galleryList.filter((c) => c !== key) this.galleryList = this.galleryList?.filter((c) => c !== key)
storage.set('ble_contents', JSON.stringify(this.galleryList)) storage.set('ble_contents', this.galleryList)
} }
addBindDeviceItem(item: bindDeviceItem) { addBindDeviceItem(item: bindDeviceItem) {
if (this.bindDeviceList.find((i) => i.id === item.id)) return if (this.bindDeviceList?.find((i) => i.id === item.id)) return
this.bindDeviceList.push({ ...item, createAt: Date.now() }) this.bindDeviceList?.push({ ...item, createAt: Date.now() })
storage.set('ble_bindDeviceList', JSON.stringify(this.bindDeviceList)) storage.set('ble_bindDeviceList', this.bindDeviceList)
} }
updateBindDeviceItem(item: bindDeviceItem) { updateBindDeviceItem(item: bindDeviceItem) {
const index = this.bindDeviceList.findIndex((i) => i.id === item.id) const index = this.bindDeviceList?.findIndex((i) => i.id === item.id)
if (index !== -1) { if (index !== -1) {
this.bindDeviceList[index] = item this.bindDeviceList[index] = item
storage.set('ble_bindDeviceList', JSON.stringify(this.bindDeviceList)) storage.set('ble_bindDeviceList', this.bindDeviceList)
} }
} }
removeBindDeviceItem(id: string) { removeBindDeviceItem(id: string) {
this.bindDeviceList = this.bindDeviceList.filter((i) => i.id !== id) this.bindDeviceList = this.bindDeviceList?.filter((i) => i.id !== id)
storage.set('ble_bindDeviceList', JSON.stringify(this.bindDeviceList)) storage.set('ble_bindDeviceList', this.bindDeviceList)
} }
// Actions // Actions

View File

@ -32,20 +32,13 @@ class Storage {
const value = this.cache[key] const value = this.cache[key]
if (value) { // console.log('get-----------', value)
// console.log('🎯 存储命中:', key)
try {
return JSON.parse(value)
} catch (error) {
return null
}
}
return null return value ? (value as unknown as T) : null
} }
// 设置存储 // 设置存储
async set(key: string, value: string): Promise<void> { async set(key: string, value: any): Promise<void> {
await this.init() await this.init()
this.cache[key] = value this.cache[key] = value