From c3ddb283dc584620b6c7b369c3b71fbbafac57ea Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Sat, 22 Aug 2026 18:51:45 +0200 Subject: [PATCH] Auto-Commit: 2026-08-22 18:51:45 --- android/app/build.gradle | 4 +- app.json | 4 +- .../expo/modules/usbcamera/UsbCameraView.kt | 52 +++++++++++++++---- package.json | 2 +- plugins/withLocalAars.js | 1 - src/screens/CameraScreen.tsx | 4 +- 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 433886b4..1646918f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -92,8 +92,8 @@ android { applicationId 'de.orfel.schnappix' minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 54 - versionName "23.01.54" + versionCode 55 + versionName "23.01.55" buildConfigField "String", "REACT_NATIVE_RELEASE_LEVEL", "\"${findProperty('reactNativeReleaseLevel') ?: 'stable'}\"" } diff --git a/app.json b/app.json index 69654630..cb72383b 100644 --- a/app.json +++ b/app.json @@ -3,7 +3,7 @@ "newArchEnabled": true, "name": "Schnappix", "slug": "Schnappix", - "version": "23.01.54", + "version": "23.01.55", "orientation": "landscape", "icon": "./Icon.png", "userInterfaceStyle": "dark", @@ -13,7 +13,7 @@ }, "android": { "package": "de.orfel.schnappix", - "versionCode": 54, + "versionCode": 55, "usesCleartextTraffic": true, "adaptiveIcon": { "backgroundColor": "#050510", diff --git a/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt b/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt index 46ac6dcb..aa68f335 100644 --- a/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt +++ b/modules/usb-camera/android/src/main/java/expo/modules/usbcamera/UsbCameraView.kt @@ -45,6 +45,34 @@ class UsbContextWrapper(base: Context) : android.content.ContextWrapper(base), L super.registerReceiver(receiver, filter, broadcastPermission, scheduler) } } + + override fun registerReceiver( + receiver: android.content.BroadcastReceiver?, + filter: android.content.IntentFilter?, + flags: Int + ): android.content.Intent? { + val newFlags = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { + flags or Context.RECEIVER_EXPORTED + } else { + flags + } + return super.registerReceiver(receiver, filter, newFlags) + } + + override fun registerReceiver( + receiver: android.content.BroadcastReceiver?, + filter: android.content.IntentFilter?, + broadcastPermission: String?, + scheduler: android.os.Handler?, + flags: Int + ): android.content.Intent? { + val newFlags = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { + flags or Context.RECEIVER_EXPORTED + } else { + flags + } + return super.registerReceiver(receiver, filter, broadcastPermission, scheduler, newFlags) + } } @Keep @@ -60,7 +88,13 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context private var registeredContext: Context? = null init { - textureView = AspectRatioTextureView(context) + val activityContext = appContext.currentActivity ?: context + if (activityContext !is androidx.lifecycle.LifecycleOwner) { + throw IllegalStateException("Cannot initialize UsbCameraView because activityContext is not a LifecycleOwner!") + } + val safeContext = UsbContextWrapper(activityContext) + + textureView = AspectRatioTextureView(safeContext) addView(textureView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) try { @@ -68,11 +102,6 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context .setFrontCamera(false) .create() - val activityContext = appContext.currentActivity ?: context - if (activityContext !is androidx.lifecycle.LifecycleOwner) { - throw IllegalStateException("Cannot initialize UsbCameraView because activityContext is not a LifecycleOwner!") - } - // Explicitly request permission for any connected USB camera before starting ausbc try { val usbManager = context.getSystemService(Context.USB_SERVICE) as android.hardware.usb.UsbManager @@ -124,8 +153,6 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context activityContext.registerReceiver(permissionReceiver, filter) } - val safeContext = UsbContextWrapper(activityContext) - cameraClient = CameraClient.newBuilder(safeContext) .setCameraStrategy(CameraUvcStrategy(safeContext)) .setCameraRequest(cameraRequest) @@ -227,7 +254,14 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context fun restartPreview() { try { if (cameraClient != null) { - cameraClient?.openCamera(textureView) + cameraClient?.closeCamera() + textureView.postDelayed({ + try { + cameraClient?.openCamera(textureView) + } catch (e: Exception) { + e.printStackTrace() + } + }, 300) } } catch (e: Exception) { e.printStackTrace() diff --git a/package.json b/package.json index 194c5373..1dc84eec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "schnappix", - "version": "23.01.54", + "version": "23.01.55", "main": "index.ts", "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.7.2", diff --git a/plugins/withLocalAars.js b/plugins/withLocalAars.js index 92cfa0ed..f6207bcd 100644 --- a/plugins/withLocalAars.js +++ b/plugins/withLocalAars.js @@ -8,7 +8,6 @@ const withLocalAars = (config) => { const dependencyBlock = ` // Added by withLocalAars plugin implementation files("../../modules/usb-camera/android/libs/immersionbar-3.0.0.aar") - implementation files("../../modules/usb-camera/android/libs/webpdecoder-1.6.4.9.0.aar") `; if (!contents.includes('immersionbar-3.0.0.aar')) { diff --git a/src/screens/CameraScreen.tsx b/src/screens/CameraScreen.tsx index 89e709ba..1d33387c 100644 --- a/src/screens/CameraScreen.tsx +++ b/src/screens/CameraScreen.tsx @@ -133,13 +133,13 @@ export default function CameraScreen({ // If we just became visible again (e.g. returning from PreviewScreen or AdminScreen) if (wasObscured && !isObscured) { - if (usbCameraRef.current && isUsbConnected) { + if (usbCameraRef.current && !useFrontCamera) { usbCameraRef.current.restartPreview().catch(e => { logger.error('Failed to restart preview natively', e); }); } } - }, [isObscured, isUsbConnected]); + }, [isObscured, useFrontCamera]); const { width } = useWindowDimensions(); const iconSize = width < 768 ? 18 : 32;