2024-05-14 20:50:45 +05:30
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
|
|
import { NavigationContainer } from '@react-navigation/native';
|
2024-05-10 12:32:34 +05:30
|
|
|
import React, { useEffect } from 'react';
|
2023-04-01 10:27:23 +05:30
|
|
|
import {
|
2023-04-18 01:27:28 +05:30
|
|
|
AppState,
|
|
|
|
|
LogBox,
|
|
|
|
|
PermissionsAndroid,
|
|
|
|
|
Platform,
|
|
|
|
|
StatusBar,
|
2024-05-14 20:50:45 +05:30
|
|
|
type Permission,
|
2023-04-01 10:27:23 +05:30
|
|
|
} from 'react-native';
|
2024-10-08 17:34:39 +05:30
|
|
|
import {
|
|
|
|
|
default as codePush,
|
|
|
|
|
default as CodePush,
|
|
|
|
|
DownloadProgress,
|
|
|
|
|
DownloadProgressCallback,
|
|
|
|
|
SyncStatusChangedCallback,
|
|
|
|
|
} from 'react-native-code-push';
|
2023-04-01 10:27:23 +05:30
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
|
import { PersistGate } from 'redux-persist/integration/react';
|
2023-08-31 14:51:03 +05:30
|
|
|
import store, { persistor } from './src/store/store';
|
|
|
|
|
|
2022-12-06 18:22:09 +05:30
|
|
|
import FullScreenLoader from './RN-UI-LIB/src/components/FullScreenLoader';
|
2023-04-18 01:27:28 +05:30
|
|
|
import { toastConfigs, ToastContainer } from './RN-UI-LIB/src/components/toast';
|
2024-08-26 17:00:35 +05:30
|
|
|
import { navigationRef } from '@utils/navigationUtlis';
|
2023-01-06 20:11:05 +05:30
|
|
|
|
2024-04-30 19:23:19 +05:30
|
|
|
import { sendDeviceDetailsToClickstream } from '@components/utlis/commonFunctions';
|
|
|
|
|
import { linkingConf } from '@components/utlis/deeplinkingUtils';
|
2024-08-26 17:04:06 +05:30
|
|
|
import { getBuildFlavour } from '@components/utlis/DeviceUtils';
|
2025-02-21 21:55:25 +05:30
|
|
|
import { GLOBAL, setGlobalBuildFlavour } from '@constants/Global';
|
2024-04-30 19:23:19 +05:30
|
|
|
import analytics from '@react-native-firebase/analytics';
|
|
|
|
|
import dayJs from 'dayjs';
|
2024-08-26 17:00:35 +05:30
|
|
|
import { COLORS } from '@rn-ui-lib/colors';
|
|
|
|
|
import { MILLISECONDS_IN_A_SECOND } from '@rn-ui-lib/utils/common';
|
|
|
|
|
import { hydrateGlobalImageMap } from '@common/CachedImage';
|
|
|
|
|
import { CLICKSTREAM_EVENT_NAMES, LocalStorageKeys } from '@common/Constants';
|
2023-04-18 01:27:28 +05:30
|
|
|
import ErrorBoundary from './src/common/ErrorBoundary';
|
2024-08-26 17:00:35 +05:30
|
|
|
import { getPermissionsToRequest } from '@utils/PermissionUtils';
|
2024-04-30 19:23:19 +05:30
|
|
|
import ScreenshotBlocker from './src/components/utlis/ScreenshotBlocker';
|
2024-10-08 17:34:39 +05:30
|
|
|
import { setItem } from './src/components/utlis/storageHelper';
|
|
|
|
|
import { ENV } from './src/constants/config';
|
2024-04-30 19:23:19 +05:30
|
|
|
import AuthRouter from './src/screens/auth/AuthRouter';
|
2024-08-26 17:00:35 +05:30
|
|
|
import { type TDocumentObj } from '@screens/caseDetails/interface';
|
2024-04-30 19:23:19 +05:30
|
|
|
import Permissions from './src/screens/permissions/Permissions';
|
2024-08-26 17:00:35 +05:30
|
|
|
import { addClickstreamEvent } from '@services/clickstreamEventService';
|
|
|
|
|
import { setJsErrorHandler } from '@services/exception-handler.service';
|
2024-04-30 19:23:19 +05:30
|
|
|
import fetchUpdatedRemoteConfig from './src/services/firebaseFetchAndUpdate.service';
|
|
|
|
|
import { StorageKeys } from './src/types/storageKeys';
|
2024-10-08 17:34:39 +05:30
|
|
|
import CodePushLoadingModal, { CodePushLoadingModalRef } from './CodePushModal';
|
2024-11-11 16:56:00 +05:30
|
|
|
import { initSentry } from '@components/utlis/sentry';
|
2025-01-15 19:37:26 +05:30
|
|
|
import { AppStates } from '@interfaces/appStates';
|
2025-02-21 21:55:25 +05:30
|
|
|
import syncSelfCallData from '@services/syncSelfCallData';
|
2024-11-11 16:25:08 +05:30
|
|
|
|
2024-11-11 16:56:00 +05:30
|
|
|
if (!__DEV__) {
|
|
|
|
|
initSentry();
|
2024-11-11 16:25:08 +05:30
|
|
|
}
|
2023-03-21 12:59:44 +05:30
|
|
|
|
2023-06-05 12:26:34 +05:30
|
|
|
if (ENV !== 'prod') {
|
|
|
|
|
// mockApiServer();
|
2023-02-16 15:47:43 +05:30
|
|
|
}
|
2023-05-25 13:55:15 +05:30
|
|
|
|
2023-03-24 14:36:10 +05:30
|
|
|
setJsErrorHandler();
|
2023-02-28 14:29:38 +05:30
|
|
|
LogBox.ignoreAllLogs();
|
|
|
|
|
|
2023-09-07 22:44:04 +05:30
|
|
|
export let GlobalDocumentMap: Record<string, TDocumentObj | string> = {};
|
2023-03-03 10:02:54 +05:30
|
|
|
|
2024-10-08 17:34:39 +05:30
|
|
|
async function checkCodePushAndSync(
|
|
|
|
|
onSyncStatusChange: SyncStatusChangedCallback,
|
|
|
|
|
onDownloadProgress: DownloadProgressCallback
|
|
|
|
|
) {
|
2023-04-18 01:27:28 +05:30
|
|
|
try {
|
2024-10-08 17:34:39 +05:30
|
|
|
await CodePush.sync(
|
|
|
|
|
{
|
|
|
|
|
installMode: codePush.InstallMode.IMMEDIATE,
|
|
|
|
|
},
|
|
|
|
|
onSyncStatusChange,
|
|
|
|
|
onDownloadProgress
|
|
|
|
|
);
|
2023-04-18 01:27:28 +05:30
|
|
|
} catch (error) {}
|
2023-03-30 10:42:53 +05:30
|
|
|
}
|
|
|
|
|
|
2024-10-08 17:34:39 +05:30
|
|
|
function handleAppStateChange(
|
|
|
|
|
nextAppState: any,
|
|
|
|
|
onSyncStatusChange: SyncStatusChangedCallback,
|
|
|
|
|
onDownloadProgress: DownloadProgressCallback
|
|
|
|
|
) {
|
2023-04-18 01:27:28 +05:30
|
|
|
if (nextAppState == 'active') {
|
2024-10-08 17:34:39 +05:30
|
|
|
checkCodePushAndSync(onSyncStatusChange, onDownloadProgress);
|
2023-04-18 01:27:28 +05:30
|
|
|
}
|
2023-03-30 10:42:53 +05:30
|
|
|
}
|
|
|
|
|
|
2023-08-30 11:57:55 +05:30
|
|
|
const PERMISSION_CHECK_POLL_INTERVAL = 5 * MILLISECONDS_IN_A_SECOND;
|
2023-03-03 10:02:54 +05:30
|
|
|
|
2023-08-31 14:51:03 +05:30
|
|
|
function App() {
|
2023-04-18 01:27:28 +05:30
|
|
|
const [permissions, setPermissions] = React.useState(true);
|
2024-10-08 17:34:39 +05:30
|
|
|
const modalRef = React.useRef<CodePushLoadingModalRef>(null);
|
|
|
|
|
|
2023-08-29 17:00:05 +05:30
|
|
|
const askForPermissions = async () => {
|
2023-08-30 11:57:55 +05:30
|
|
|
const permissionsToRequest = await getPermissionsToRequest();
|
2023-08-29 17:00:05 +05:30
|
|
|
if (Platform.OS === 'android') {
|
2023-08-30 11:57:55 +05:30
|
|
|
PermissionsAndroid.requestMultiple(permissionsToRequest)
|
2023-08-29 17:00:05 +05:30
|
|
|
.then(async (result) => {
|
|
|
|
|
let isAllPermissionsGranted = true;
|
|
|
|
|
for (const permission in result) {
|
|
|
|
|
if (result?.[permission as Permission] !== PermissionsAndroid.RESULTS.GRANTED) {
|
|
|
|
|
isAllPermissionsGranted = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setPermissions(isAllPermissionsGranted);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
setPermissions(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-04-12 23:03:42 +05:30
|
|
|
|
2024-10-08 17:34:39 +05:30
|
|
|
const onSyncStatusChange = (syncStatus: codePush.SyncStatus) => {
|
|
|
|
|
switch (syncStatus) {
|
|
|
|
|
case codePush.SyncStatus.DOWNLOADING_PACKAGE:
|
|
|
|
|
modalRef.current?.show();
|
|
|
|
|
break;
|
|
|
|
|
case codePush.SyncStatus.INSTALLING_UPDATE:
|
|
|
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_INSTALLING_CODEPUSH, {});
|
|
|
|
|
break;
|
|
|
|
|
case codePush.SyncStatus.UP_TO_DATE:
|
|
|
|
|
modalRef.current?.hide();
|
|
|
|
|
break;
|
2024-12-02 15:41:47 +05:30
|
|
|
case codePush.SyncStatus.UNKNOWN_ERROR:
|
|
|
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_CODEPUSH_UNKNOWN_ERROR, {});
|
|
|
|
|
modalRef.current?.hide();
|
|
|
|
|
break;
|
2024-10-08 17:34:39 +05:30
|
|
|
default:
|
|
|
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_CODEPUSH_DEFAULT_STATUS, {});
|
|
|
|
|
modalRef.current?.hide();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onDownloadProgress = (downloadProgress: DownloadProgress) => {
|
|
|
|
|
if (downloadProgress) {
|
|
|
|
|
modalRef.current?.updateProgress(downloadProgress);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-06 18:09:10 +05:30
|
|
|
const getActiveRouteName = (state) => {
|
|
|
|
|
if (!state || typeof state.index !== 'number') {
|
|
|
|
|
return 'Unknown';
|
|
|
|
|
}
|
|
|
|
|
const route = state.routes[state.index];
|
|
|
|
|
if (route.state) {
|
|
|
|
|
return getActiveRouteName(route.state);
|
|
|
|
|
}
|
|
|
|
|
return route?.name || '';
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-19 12:49:35 +05:30
|
|
|
async function setForegroundTimeStampAndClickstream() {
|
2023-09-15 01:45:42 +05:30
|
|
|
const now = dayJs().toString();
|
|
|
|
|
await setItem(StorageKeys.APP_FOREGROUND_TIMESTAMP, now);
|
2024-10-08 17:34:39 +05:30
|
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_APP_FOREGROUND, { now }, true);
|
2023-09-15 01:45:42 +05:30
|
|
|
}
|
|
|
|
|
|
2023-09-13 14:13:20 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
ScreenshotBlocker.unblockScreenshots();
|
2023-12-26 22:10:47 +05:30
|
|
|
getBuildFlavour().then((flavour) => {
|
|
|
|
|
setGlobalBuildFlavour(flavour);
|
|
|
|
|
});
|
2024-04-04 12:22:18 +05:30
|
|
|
// Device Details
|
2024-04-04 17:25:49 +05:30
|
|
|
sendDeviceDetailsToClickstream();
|
2023-09-13 14:13:20 +05:30
|
|
|
}, []);
|
2023-04-18 16:02:24 +05:30
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
React.useEffect(() => {
|
2023-10-19 18:34:25 +05:30
|
|
|
fetchUpdatedRemoteConfig();
|
2023-08-30 11:57:55 +05:30
|
|
|
askForPermissions();
|
2023-08-29 13:17:02 +05:30
|
|
|
const appStateChange = AppState.addEventListener('change', async (change) => {
|
2025-01-24 14:53:48 +05:30
|
|
|
if (change === AppStates.ACTIVE) {
|
2025-01-15 19:37:26 +05:30
|
|
|
askForPermissions();
|
2025-02-21 21:55:25 +05:30
|
|
|
if (GLOBAL.AGENT_ID) {
|
|
|
|
|
syncSelfCallData(GLOBAL.AGENT_ID);
|
|
|
|
|
}
|
2025-01-15 19:37:26 +05:30
|
|
|
}
|
2024-10-08 17:34:39 +05:30
|
|
|
handleAppStateChange(change, onSyncStatusChange, onDownloadProgress);
|
2023-09-13 14:50:17 +05:30
|
|
|
hydrateGlobalImageMap();
|
2023-04-18 01:27:28 +05:30
|
|
|
});
|
|
|
|
|
(async () => {
|
|
|
|
|
const data = await AsyncStorage.getItem(LocalStorageKeys.GLOBAL_DOCUMENT_MAP);
|
|
|
|
|
if (data) {
|
|
|
|
|
const parsedData = JSON.parse(data);
|
|
|
|
|
GlobalDocumentMap = parsedData;
|
|
|
|
|
}
|
|
|
|
|
})();
|
2024-10-08 17:34:39 +05:30
|
|
|
checkCodePushAndSync(onSyncStatusChange, onDownloadProgress);
|
2023-09-19 12:49:35 +05:30
|
|
|
setForegroundTimeStampAndClickstream();
|
2023-09-15 01:45:42 +05:30
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
return () => {
|
|
|
|
|
appStateChange.remove();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
return (
|
|
|
|
|
<Provider store={store}>
|
2023-09-07 13:34:19 +05:30
|
|
|
<PersistGate
|
|
|
|
|
loading={<FullScreenLoader loading isTranslucent={false} />}
|
|
|
|
|
persistor={persistor}
|
|
|
|
|
>
|
2023-08-31 14:51:03 +05:30
|
|
|
<NavigationContainer
|
2024-01-24 16:00:09 +05:30
|
|
|
linking={linkingConf}
|
2023-08-31 14:51:03 +05:30
|
|
|
ref={navigationRef}
|
|
|
|
|
onStateChange={async (state) => {
|
|
|
|
|
const currentRouteName = getActiveRouteName(state);
|
2024-05-10 12:32:34 +05:30
|
|
|
await analytics().logScreenView({
|
|
|
|
|
screen_name: currentRouteName,
|
|
|
|
|
screen_class: currentRouteName,
|
|
|
|
|
});
|
2023-08-31 14:51:03 +05:30
|
|
|
}}
|
|
|
|
|
>
|
2023-04-18 01:27:28 +05:30
|
|
|
<StatusBar backgroundColor={COLORS.BACKGROUND.INDIGO_DARK} />
|
2023-11-08 22:30:55 +05:30
|
|
|
<ErrorBoundary>{permissions ? <AuthRouter /> : <Permissions />}</ErrorBoundary>
|
2023-04-18 01:27:28 +05:30
|
|
|
</NavigationContainer>
|
2023-05-11 18:48:56 +05:30
|
|
|
<ToastContainer config={toastConfigs} position="top" topOffset={18} />
|
2024-10-08 17:34:39 +05:30
|
|
|
<CodePushLoadingModal ref={modalRef} />
|
2023-04-18 01:27:28 +05:30
|
|
|
</PersistGate>
|
|
|
|
|
</Provider>
|
|
|
|
|
);
|
2023-08-31 14:51:03 +05:30
|
|
|
}
|
2022-11-30 10:13:33 +05:30
|
|
|
|
2024-11-06 18:23:37 +05:30
|
|
|
export default App;
|