-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathApp.tsx
More file actions
93 lines (80 loc) · 3.08 KB
/
App.tsx
File metadata and controls
93 lines (80 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { StatusBar } from 'expo-status-bar';
import React, { useEffect } from 'react';
import { LogBox } from 'react-native';
import '../assets/global.css';
import { requireEnvVariables } from './src/config/env';
import { ErrorBoundary } from './src/components/common/ErrorBoundary';
import crashReportingService from './src/services/crashReporting';
import socketService from './src/services/socket';
import { useAppStore } from './src/store';
import logger from './src/utils/logger';
import AppNavigator from './src/navigation/AppNavigator';
requireEnvVariables();
// Notification imports
import { setupNotificationNavigation } from "./src/navigation/linking";
import apiClient from "./src/services/api/axios.config";
import requestQueue from "./src/services/api/requestQueue";
import {
addNotificationReceivedListener,
getLastNotificationResponse,
removeNotificationListener,
} from "./src/services/pushNotifications";
import { handleNotificationReceived } from "./src/utils/notificationHandlers";
// Centralized logging is handled by src/utils/logger.
// Suppress known non-actionable navigation warnings in all environments.
if (__DEV__) {
logger.debug("Development mode: centralized logger active");
LogBox.ignoreLogs([
"Non-serializable values were found in the navigation state",
]);
}
export default function App() {
const theme = useAppStore((state) => state.theme);
useEffect(() => {
// Initialize crash reporting at app startup
crashReportingService.init();
// Add global handler for unhandled promise rejections
const unhandledRejectionHandler = (reason: any) => {
const error =
reason instanceof Error ? reason : new Error(String(reason));
logger.error("Unhandled Promise Rejection:", error);
crashReportingService.reportError(error, "UnhandledPromiseRejection");
};
// Register unhandled rejection listener
if (global.onunhandledrejection === undefined) {
// @ts-ignore - Setting global error handler
global.onunhandledrejection = unhandledRejectionHandler;
}
// Connect to socket when app starts
socketService.connect();
// Start request queue monitoring
requestQueue.startMonitoring(apiClient);
// Set up notification navigation handler
const notificationCleanup = setupNotificationNavigation();
// Listen for notifications received while app is foregrounded
const subscription = addNotificationReceivedListener(
handleNotificationReceived,
);
// Check if app was launched from a notification
getLastNotificationResponse().then((response) => {
if (response) {
logger.info("App launched from notification:", response);
}
});
// Cleanup on unmount
return () => {
socketService.disconnect();
notificationCleanup();
removeNotificationListener(subscription);
// Clean up the unhandled rejection handler
// @ts-ignore
global.onunhandledrejection = undefined;
};
}, []);
return (
<ErrorBoundary>
<StatusBar style={theme === 'dark' ? 'light' : 'dark'} />
<AppNavigator />
</ErrorBoundary>
);
}