From c338ef4247b7d285852afe41c5cc6bb23a9196bc Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Sun, 31 May 2026 15:38:17 +0200 Subject: [PATCH] Fix JS exceptions crashing the app instantly --- App.tsx | 12 ++++++++---- src/screens/AdminScreen.tsx | 7 ++++--- src/screens/CameraScreen.tsx | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/App.tsx b/App.tsx index bca2270b..cc735b2a 100644 --- a/App.tsx +++ b/App.tsx @@ -9,9 +9,13 @@ import { logger } from './src/services/logger'; // Set up global error handler const defaultErrorHandler = (global as any).ErrorUtils.getGlobalHandler(); -(global as any).ErrorUtils.setGlobalHandler(async (error: any, isFatal: boolean) => { - await logger.error(`Unhandled Exception (Fatal: ${isFatal})`, error); - defaultErrorHandler(error, isFatal); +(global as any).ErrorUtils.setGlobalHandler((error: any, isFatal: boolean) => { + logger.error(`Unhandled Exception (Fatal: ${isFatal})`, error) + .catch(console.error) + .finally(() => { + // Delay termination until log is written + defaultErrorHandler(error, isFatal); + }); }); import KioskMode from './modules/kiosk-mode'; @@ -83,7 +87,7 @@ export default function App() { const handleReset = () => { setPhotoUris([]); - setCurrentScreen('home'); + setCurrentScreen('home'); // Go to home when cancelled }; const handleSaveSettings = (updated: AppSettings) => { diff --git a/src/screens/AdminScreen.tsx b/src/screens/AdminScreen.tsx index 1366c58c..fe5fa4ed 100644 --- a/src/screens/AdminScreen.tsx +++ b/src/screens/AdminScreen.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { StyleSheet, Text, @@ -66,6 +66,7 @@ export default function AdminScreen({ currentSettings, onSave, onClose }: AdminS const [printerIp, setPrinterIp] = useState(currentSettings.printerIp); const [password, setPassword] = useState(currentSettings.adminPassword); const [logs, setLogs] = useState(null); + const scrollViewRef = useRef(null); const [kioskActive, setKioskActive] = useState(false); const [isDeviceOwner, setIsDeviceOwner] = useState(false); @@ -509,8 +510,8 @@ export default function AdminScreen({ currentSettings, onSave, onClose }: AdminS { this.scrollView = ref }} - onContentSizeChange={() => this.scrollView?.scrollToEnd({animated: true})} + ref={scrollViewRef} + onContentSizeChange={() => scrollViewRef.current?.scrollToEnd({animated: true})} > {logs} diff --git a/src/screens/CameraScreen.tsx b/src/screens/CameraScreen.tsx index d8306ef9..f9ff8e1c 100644 --- a/src/screens/CameraScreen.tsx +++ b/src/screens/CameraScreen.tsx @@ -160,7 +160,7 @@ export default function CameraScreen({ // Cancel capture process const handleLocalCancel = () => { - if (countdownTimerRef.current) clearInterval(countdownTimerRef.current); + if (countdownTimerRef.current) clearTimeout(countdownTimerRef.current); if (burstTimerRef.current) clearTimeout(burstTimerRef.current); setCountdown(countdownDuration); setIsCapturing(false);