1import {
2  getBuildInfoAsync,
3  getCrashReport,
4  installationID,
5  isDevice,
6  updatesConfig,
7  loadFontsAsync,
8} from '../native-modules/DevLauncherInternal';
9import { getMenuPreferencesAsync } from '../native-modules/DevMenuPreferences';
10import { AppProvidersProps } from '../providers/AppProviders';
11import { defaultQueryOptions } from '../providers/QueryProvider';
12import { prefetchBranchesForApp } from '../queries/useBranchesForApp';
13import { getDevSessionsAsync } from './getDevSessionsAsync';
14import { restoreUserAsync } from './restoreUserAsync';
15
16export async function getInitialData(): Promise<Partial<AppProvidersProps>> {
17  const initialUserData = await restoreUserAsync();
18  const isAuthenticated = initialUserData != null;
19
20  await loadFontsAsync().catch((error) => console.log({ error }));
21
22  const initialDevSessions = await getDevSessionsAsync({
23    isAuthenticated,
24    installationID,
25    isDevice,
26  });
27
28  const initialBuildInfo = await getBuildInfoAsync();
29  const initialDevMenuPreferences = await getMenuPreferencesAsync();
30  const initialCrashReport = await getCrashReport();
31
32  if (isAuthenticated && updatesConfig.usesEASUpdates) {
33    prefetchBranchesForApp(
34      updatesConfig.appId,
35      updatesConfig.runtimeVersion,
36      defaultQueryOptions.pageSize
37    ).catch((error) => console.log({ error }));
38  }
39
40  return {
41    initialDevSessions,
42    initialUserData,
43    initialBuildInfo,
44    initialDevMenuPreferences,
45    initialCrashReport,
46  };
47}
48