From 09e1caddf2926ccd06ad2738278ac4def03f47a2 Mon Sep 17 00:00:00 2001 From: km2025 Date: Wed, 14 Jan 2026 18:13:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96storage=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E3=80=81=E8=A7=A3=E7=BB=91=E5=90=8E=E6=96=AD=E5=BC=80=E8=AE=BE?= =?UTF-8?q?=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @share/components/Video.tsx | 3 +-- app/(tabs)/sync.tsx | 7 +++---- app/_layout.tsx | 2 ++ bun.lock | 1 + components/BannerSection.tsx | 1 - package.json | 1 + stores/BleStore.ts | 26 +++++++++++++------------- utils/storage.ts | 13 +++---------- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/@share/components/Video.tsx b/@share/components/Video.tsx index 262dc20..94c28d2 100644 --- a/@share/components/Video.tsx +++ b/@share/components/Video.tsx @@ -46,7 +46,7 @@ const VideoBox = ({ url, needWeb = true, width = 256, style, ...videoProps }: Pr try { // 先尝试从缓存获取 const cachedUrl = await videoUrlCache.get(url!, width) - console.log('getRedirectUrl cachedUrl-----------', url, cachedUrl) + // console.log('getRedirectUrl cachedUrl-----------', url, cachedUrl) if (cachedUrl) { setUrlFinal(cachedUrl) return @@ -56,7 +56,6 @@ const VideoBox = ({ url, needWeb = true, width = 256, style, ...videoProps }: Pr const webpUrl = createUrl(url!) const finalUrl = await resolveRedirect(webpUrl) - console.log('getRedirectUrl finalUrl-----------', url, finalUrl) // 缓存结果 await videoUrlCache.set(url!, finalUrl, width) diff --git a/app/(tabs)/sync.tsx b/app/(tabs)/sync.tsx index 5b0fd24..795cd9e 100644 --- a/app/(tabs)/sync.tsx +++ b/app/(tabs)/sync.tsx @@ -123,15 +123,13 @@ const Sync = observer(() => { } }, [posts]) - console.log('selectedItem-----------', selectedItem) + // console.log('selectedItem-----------', selectedItem) const canSync = useMemo(() => { return !!connectedDevice?.id && !!selectedItem?.imageUrl }, [connectedDevice, selectedItem]) const handleSync = useCallback(async () => { - console.log('selectedItem?.imageUrl-----------', selectedItem?.imageUrl) - if (!canSync) { Toast.show({ title: '请先连接设备' }) return @@ -505,7 +503,7 @@ const SpinningLoader = memo(() => { const DeviceItem = observer(({ device }: { device: any }) => { 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 tempName = useRef(nameShow) @@ -554,6 +552,7 @@ const DeviceItem = observer(({ device }: { device: any }) => { onConfirm={() => { Toast.hideModal() unbindDevice(device) + bleManager.disconnectDevice() }} />, ) diff --git a/app/_layout.tsx b/app/_layout.tsx index fd4bdc0..9f4ed8e 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -3,6 +3,7 @@ import 'react-native-reanimated' import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native' import * as Sentry from '@sentry/react-native' +import { useKeepAwake } from 'expo-keep-awake' import { Stack, useNavigationContainerRef } from 'expo-router' import { StatusBar } from 'expo-status-bar' import { useEffect } from 'react' @@ -100,6 +101,7 @@ function RootLayout() { function Providers({ children }: { children: React.ReactNode }) { const colorScheme = useColorScheme() useUserSession() + useKeepAwake() return ( diff --git a/bun.lock b/bun.lock index 0996c97..d8464a9 100644 --- a/bun.lock +++ b/bun.lock @@ -37,6 +37,7 @@ "expo-image-manipulator": "~14.0.8", "expo-image-picker": "~17.0.8", "expo-insights": "~0.10.8", + "expo-keep-awake": "~15.0.8", "expo-linear-gradient": "^15.0.8", "expo-linking": "^8.0.10", "expo-media-library": "~18.2.0", diff --git a/components/BannerSection.tsx b/components/BannerSection.tsx index f6ba2f9..d84d527 100644 --- a/components/BannerSection.tsx +++ b/components/BannerSection.tsx @@ -19,7 +19,6 @@ const BannerSection = memo(function Banner({ bgVideo }) { setBgurl(bgVideo) }, [bgVideo]) - return null return ( diff --git a/package.json b/package.json index dd43f8a..ec63095 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "expo-image-manipulator": "~14.0.8", "expo-image-picker": "~17.0.8", "expo-insights": "~0.10.8", + "expo-keep-awake": "~15.0.8", "expo-linear-gradient": "^15.0.8", "expo-linking": "^8.0.10", "expo-media-library": "~18.2.0", diff --git a/stores/BleStore.ts b/stores/BleStore.ts index c377f06..ba2c814 100644 --- a/stores/BleStore.ts +++ b/stores/BleStore.ts @@ -71,33 +71,33 @@ class BleStore { setGalleryList(contents: string[]) { this.galleryList = contents - storage.set('ble_contents', JSON.stringify(contents)) + storage.set('ble_contents', contents) } addGalleryItem(content: string) { - if (this.galleryList.includes(content)) return - this.galleryList.push(content) - storage.set('ble_contents', JSON.stringify(this.galleryList)) + if (this.galleryList?.includes(content)) return + this.galleryList?.push(content) + storage.set('ble_contents', this.galleryList) } removeGalleryItem(key: string) { - this.galleryList = this.galleryList.filter((c) => c !== key) - storage.set('ble_contents', JSON.stringify(this.galleryList)) + this.galleryList = this.galleryList?.filter((c) => c !== key) + storage.set('ble_contents', this.galleryList) } addBindDeviceItem(item: bindDeviceItem) { - if (this.bindDeviceList.find((i) => i.id === item.id)) return - this.bindDeviceList.push({ ...item, createAt: Date.now() }) - storage.set('ble_bindDeviceList', JSON.stringify(this.bindDeviceList)) + if (this.bindDeviceList?.find((i) => i.id === item.id)) return + this.bindDeviceList?.push({ ...item, createAt: Date.now() }) + storage.set('ble_bindDeviceList', this.bindDeviceList) } 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) { this.bindDeviceList[index] = item - storage.set('ble_bindDeviceList', JSON.stringify(this.bindDeviceList)) + storage.set('ble_bindDeviceList', this.bindDeviceList) } } removeBindDeviceItem(id: string) { - this.bindDeviceList = this.bindDeviceList.filter((i) => i.id !== id) - storage.set('ble_bindDeviceList', JSON.stringify(this.bindDeviceList)) + this.bindDeviceList = this.bindDeviceList?.filter((i) => i.id !== id) + storage.set('ble_bindDeviceList', this.bindDeviceList) } // Actions diff --git a/utils/storage.ts b/utils/storage.ts index 8aa1a92..177c144 100644 --- a/utils/storage.ts +++ b/utils/storage.ts @@ -32,20 +32,13 @@ class Storage { const value = this.cache[key] - if (value) { - // console.log('🎯 存储命中:', key) - try { - return JSON.parse(value) - } catch (error) { - return null - } - } + // console.log('get-----------', value) - return null + return value ? (value as unknown as T) : null } // 设置存储 - async set(key: string, value: string): Promise { + async set(key: string, value: any): Promise { await this.init() this.cache[key] = value