1import { NativeModules, NativeEventEmitter, EventSubscription } from 'react-native'; 2 3import { RecentApp } from '../providers/RecentlyOpenedAppsProvider'; 4 5const DevLauncher = NativeModules.EXDevLauncherInternal; 6const EventEmitter = new NativeEventEmitter(DevLauncher); 7 8const ON_NEW_DEEP_LINK_EVENT = 'expo.modules.devlauncher.onnewdeeplink'; 9 10export async function getRecentlyOpenedApps(): Promise<RecentApp[]> { 11 const recentlyOpenedApps = await DevLauncher.getRecentlyOpenedApps(); 12 return recentlyOpenedApps; 13} 14 15export async function clearRecentlyOpenedApps(): Promise<void> { 16 return await DevLauncher.clearRecentlyOpenedApps(); 17} 18 19export async function loadApp(url: string): Promise<void> { 20 return await DevLauncher.loadApp(url); 21} 22 23export async function loadUpdate(updateUrl: string, projectUrl: string) { 24 return await DevLauncher.loadUpdate(updateUrl, projectUrl); 25} 26 27export async function getNavigationStateAsync() { 28 return await DevLauncher.getNavigationState(); 29} 30 31export async function consumeNavigationStateAsync() { 32 const serializedNavigationState = await DevLauncher.getNavigationState(); 33 let navigationState; 34 35 try { 36 navigationState = JSON.parse(serializedNavigationState); 37 } catch (error) {} 38 39 // not necessary to await this as its effects are only applied on app launch 40 clearNavigationStateAsync(); 41 return navigationState; 42} 43 44export async function saveNavigationStateAsync(navigationState: string) { 45 return await DevLauncher.saveNavigationState(navigationState); 46} 47 48export async function clearNavigationStateAsync() { 49 return await DevLauncher.clearNavigationState(); 50} 51 52export async function getPendingDeepLink(): Promise<string | null> { 53 return await DevLauncher.getPendingDeepLink(); 54} 55 56export type CrashReport = { 57 timestamp: number; 58 message: string; 59 stack: string; 60}; 61 62export async function getCrashReport(): Promise<CrashReport | null> { 63 return await DevLauncher.getCrashReport(); 64} 65 66export async function openCamera(): Promise<void> { 67 return await DevLauncher.openCamera(); 68} 69 70export function addDeepLinkListener(callback: (string) => void): EventSubscription { 71 return EventEmitter.addListener(ON_NEW_DEEP_LINK_EVENT, callback); 72} 73 74export type BuildInfo = { 75 appName?: string; 76 appVersion?: string; 77 appIcon?: string; 78 sdkVersion?: string; 79 runtimeVersion?: string; 80 appId?: string; 81}; 82 83export async function getBuildInfoAsync(): Promise<BuildInfo> { 84 return DevLauncher.getBuildInfo(); 85} 86 87export async function copyToClipboardAsync(content: string): Promise<null> { 88 return DevLauncher.copyToClipboard(content); 89} 90 91export const clientUrlScheme = DevLauncher.clientUrlScheme; 92export const installationID = DevLauncher.installationID; 93export const isDevice = !!DevLauncher.isDevice; 94 95export type EXUpdatesConfig = { 96 runtimeVersion: string; 97 sdkVersion: string; 98 appId: string; 99 usesEASUpdates: boolean; 100 projectUrl: string; 101}; 102 103export const updatesConfig: EXUpdatesConfig = DevLauncher.updatesConfig; 104 105export async function loadFontsAsync() { 106 return await DevLauncher.loadFontsAsync(); 107} 108