Fix JS exceptions crashing the app instantly

This commit is contained in:
2026-05-31 15:38:17 +02:00
parent bf642cd983
commit c338ef4247
3 changed files with 13 additions and 8 deletions
+8 -4
View File
@@ -9,9 +9,13 @@ import { logger } from './src/services/logger';
// Set up global error handler // Set up global error handler
const defaultErrorHandler = (global as any).ErrorUtils.getGlobalHandler(); const defaultErrorHandler = (global as any).ErrorUtils.getGlobalHandler();
(global as any).ErrorUtils.setGlobalHandler(async (error: any, isFatal: boolean) => { (global as any).ErrorUtils.setGlobalHandler((error: any, isFatal: boolean) => {
await logger.error(`Unhandled Exception (Fatal: ${isFatal})`, error); logger.error(`Unhandled Exception (Fatal: ${isFatal})`, error)
defaultErrorHandler(error, isFatal); .catch(console.error)
.finally(() => {
// Delay termination until log is written
defaultErrorHandler(error, isFatal);
});
}); });
import KioskMode from './modules/kiosk-mode'; import KioskMode from './modules/kiosk-mode';
@@ -83,7 +87,7 @@ export default function App() {
const handleReset = () => { const handleReset = () => {
setPhotoUris([]); setPhotoUris([]);
setCurrentScreen('home'); setCurrentScreen('home'); // Go to home when cancelled
}; };
const handleSaveSettings = (updated: AppSettings) => { const handleSaveSettings = (updated: AppSettings) => {
+4 -3
View File
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { import {
StyleSheet, StyleSheet,
Text, Text,
@@ -66,6 +66,7 @@ export default function AdminScreen({ currentSettings, onSave, onClose }: AdminS
const [printerIp, setPrinterIp] = useState<string>(currentSettings.printerIp); const [printerIp, setPrinterIp] = useState<string>(currentSettings.printerIp);
const [password, setPassword] = useState<string>(currentSettings.adminPassword); const [password, setPassword] = useState<string>(currentSettings.adminPassword);
const [logs, setLogs] = useState<string | null>(null); const [logs, setLogs] = useState<string | null>(null);
const scrollViewRef = useRef<ScrollView>(null);
const [kioskActive, setKioskActive] = useState<boolean>(false); const [kioskActive, setKioskActive] = useState<boolean>(false);
const [isDeviceOwner, setIsDeviceOwner] = useState<boolean>(false); const [isDeviceOwner, setIsDeviceOwner] = useState<boolean>(false);
@@ -509,8 +510,8 @@ export default function AdminScreen({ currentSettings, onSave, onClose }: AdminS
</View> </View>
<ScrollView <ScrollView
style={{ flex: 1, backgroundColor: '#000', padding: 10, borderRadius: 5 }} style={{ flex: 1, backgroundColor: '#000', padding: 10, borderRadius: 5 }}
ref={ref => { this.scrollView = ref }} ref={scrollViewRef}
onContentSizeChange={() => this.scrollView?.scrollToEnd({animated: true})} onContentSizeChange={() => scrollViewRef.current?.scrollToEnd({animated: true})}
> >
<Text style={{ color: '#0f0', fontFamily: 'monospace' }}>{logs}</Text> <Text style={{ color: '#0f0', fontFamily: 'monospace' }}>{logs}</Text>
</ScrollView> </ScrollView>
+1 -1
View File
@@ -160,7 +160,7 @@ export default function CameraScreen({
// Cancel capture process // Cancel capture process
const handleLocalCancel = () => { const handleLocalCancel = () => {
if (countdownTimerRef.current) clearInterval(countdownTimerRef.current); if (countdownTimerRef.current) clearTimeout(countdownTimerRef.current);
if (burstTimerRef.current) clearTimeout(burstTimerRef.current); if (burstTimerRef.current) clearTimeout(burstTimerRef.current);
setCountdown(countdownDuration); setCountdown(countdownDuration);
setIsCapturing(false); setIsCapturing(false);