1 | {"version":3,"file":"AppleDevice.js","names":["_debug","data","_interopRequireDefault","require","_fs","_getenv","path","_interopRequireWildcard","_lib","_xcode","_process","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","EXPO_USE_APPLE_DEVICE","boolish","debug","Debug","isEnabled","getConnectedDevices","usbmuxClient","UsbmuxdClient","connectUsbmuxdSocket","usbmuxDevices","getDevices","socket","end","Promise","all","map","d","connect","device","LockdowndClient","getAllValues","runOnDevice","udid","appPath","bundleId","waitForApp","deltaPath","onProgress","clientManager","ClientManager","create","mountDeveloperDiskImage","packageName","basename","destPackagePath","join","uploadApp","installer","getInstallationProxyClient","installApp","ApplicationsType","CFBundleIdentifier","CloseOnInvalidate","InvalidateOnDetach","IsUserInitiated","PreferWifi","PackageType","ShadowParentKey","appInfo","lookupApp","wait","debugServerClient","launchApp","detach","onBeforeExit","halt","result","continue","kill","imageMounter","getMobileImageMounterClient","lookupImage","ImageSignature","version","getLockdowndClient","getValue","developerDiskImagePath","getDeveloperDiskImagePath","developerDiskImageSig","readFileSync","uploadImage","mountImage","srcPath","destinationPath","afcClient","getAFCClient","getFileInfo","err","AFCError","status","AFC_STATUS","OBJECT_NOT_FOUND","makeDirectory","uploadDirectory","tries","getDebugserverClient","setMaxPacketSize","setWorkingDir","Container","Path","CFBundleExecutable","checkLaunchSuccess","res","sendCommand","console","warn","Error"],"sources":["../../src/apple/AppleDevice.ts"],"sourcesContent":["import Debug from 'debug';\nimport { readFileSync } from 'fs';\nimport { boolish } from 'getenv';\nimport * as path from 'path';\n\nimport {\n AFC_STATUS,\n AFCError,\n ClientManager,\n LockdowndClient,\n OnInstallProgressCallback,\n UsbmuxdClient,\n} from './native-run/ios/lib';\nimport type { DeviceValues, IPLookupResult } from './native-run/ios/lib';\nimport { getDeveloperDiskImagePath } from './native-run/ios/utils/xcode';\nimport { onBeforeExit, wait } from './native-run/utils/process';\n\nconst EXPO_USE_APPLE_DEVICE = boolish('EXPO_USE_APPLE_DEVICE', false);\n\nconst debug = Debug('expo:xdl:ios:utils:device');\n\nexport function isEnabled() {\n return EXPO_USE_APPLE_DEVICE;\n}\n\nexport async function getConnectedDevices(): Promise<DeviceValues[]> {\n const usbmuxClient = new UsbmuxdClient(UsbmuxdClient.connectUsbmuxdSocket());\n const usbmuxDevices = await usbmuxClient.getDevices();\n usbmuxClient.socket.end();\n\n return Promise.all(\n usbmuxDevices.map(\n async (d: any): Promise<DeviceValues> => {\n const socket = await new UsbmuxdClient(UsbmuxdClient.connectUsbmuxdSocket()).connect(\n d,\n 62078\n );\n const device = await new LockdowndClient(socket).getAllValues();\n socket.end();\n return device;\n }\n )\n );\n}\n\nexport async function runOnDevice({\n udid,\n appPath,\n bundleId,\n waitForApp,\n deltaPath,\n onProgress,\n}: {\n udid: string;\n appPath: string;\n bundleId: string;\n waitForApp: boolean;\n deltaPath: string;\n onProgress: OnInstallProgressCallback;\n}) {\n const clientManager = await ClientManager.create(udid);\n\n try {\n await mountDeveloperDiskImage(clientManager);\n\n const packageName = path.basename(appPath);\n const destPackagePath = path.join('PublicStaging', packageName);\n\n await uploadApp(clientManager, appPath, destPackagePath);\n\n const installer = await clientManager.getInstallationProxyClient();\n await installer.installApp(\n destPackagePath,\n bundleId,\n {\n // https://github.com/ios-control/ios-deploy/blob/0f2ffb1e564aa67a2dfca7cdf13de47ce489d835/src/ios-deploy/ios-deploy.m#L2491-L2508\n ApplicationsType: 'Any',\n\n CFBundleIdentifier: bundleId,\n CloseOnInvalidate: '1',\n InvalidateOnDetach: '1',\n IsUserInitiated: '1',\n // Disable checking for wifi devices, this is nominally faster.\n PreferWifi: '0',\n // Only info I could find on these:\n // https://github.com/wwxxyx/Quectel_BG96/blob/310876f90fc1093a59e45e381160eddcc31697d0/Apple_Homekit/homekit_certification_tools/ATS%206/ATS%206/ATS.app/Contents/Frameworks/CaptureKit.framework/Versions/A/Resources/MobileDevice/MobileInstallation.h#L112-L121\n PackageType: 'Developer',\n ShadowParentKey: deltaPath,\n // SkipUninstall: '1'\n },\n onProgress\n );\n\n const { [bundleId]: appInfo } = await installer.lookupApp([bundleId]);\n // launch fails with EBusy or ENotFound if you try to launch immediately after install\n await wait(200);\n const debugServerClient = await launchApp(clientManager, { appInfo, detach: !waitForApp });\n if (waitForApp) {\n onBeforeExit(async () => {\n // causes continue() to return\n debugServerClient.halt();\n // give continue() time to return response\n await wait(64);\n });\n\n debug(`Waiting for app to close...\\n`);\n const result = await debugServerClient.continue();\n // TODO: I have no idea what this packet means yet (successful close?)\n // if not a close (ie, most likely due to halt from onBeforeExit), then kill the app\n if (result !== 'W00') {\n await debugServerClient.kill();\n }\n }\n } finally {\n clientManager.end();\n }\n}\n\nasync function mountDeveloperDiskImage(clientManager: ClientManager) {\n const imageMounter = await clientManager.getMobileImageMounterClient();\n // Check if already mounted. If not, mount.\n if (!(await imageMounter.lookupImage()).ImageSignature) {\n // verify DeveloperDiskImage exists (TODO: how does this work on Windows/Linux?)\n // TODO: if windows/linux, download?\n const version = await (await clientManager.getLockdowndClient()).getValue('ProductVersion');\n const developerDiskImagePath = await getDeveloperDiskImagePath(version);\n const developerDiskImageSig = readFileSync(`${developerDiskImagePath}.signature`);\n await imageMounter.uploadImage(developerDiskImagePath, developerDiskImageSig);\n await imageMounter.mountImage(developerDiskImagePath, developerDiskImageSig);\n }\n}\n\nasync function uploadApp(clientManager: ClientManager, srcPath: string, destinationPath: string) {\n const afcClient = await clientManager.getAFCClient();\n try {\n await afcClient.getFileInfo('PublicStaging');\n } catch (err: any) {\n if (err instanceof AFCError && err.status === AFC_STATUS.OBJECT_NOT_FOUND) {\n await afcClient.makeDirectory('PublicStaging');\n } else {\n throw err;\n }\n }\n await afcClient.uploadDirectory(srcPath, destinationPath);\n}\n\nasync function launchApp(\n clientManager: ClientManager,\n { appInfo, detach }: { appInfo: IPLookupResult[string]; detach?: boolean }\n) {\n let tries = 0;\n while (tries < 3) {\n const debugServerClient = await clientManager.getDebugserverClient();\n await debugServerClient.setMaxPacketSize(1024);\n await debugServerClient.setWorkingDir(appInfo.Container);\n await debugServerClient.launchApp(appInfo.Path, appInfo.CFBundleExecutable);\n\n const result = await debugServerClient.checkLaunchSuccess();\n if (result === 'OK') {\n if (detach) {\n // https://github.com/libimobiledevice/libimobiledevice/blob/25059d4c7d75e03aab516af2929d7c6e6d4c17de/tools/idevicedebug.c#L455-L464\n const res = await debugServerClient.sendCommand('D', []);\n debug('Disconnect from debug server request:', res);\n if (res !== 'OK') {\n console.warn(\n 'Something went wrong while attempting to disconnect from iOS debug server, you may need to reopen the app manually.'\n );\n }\n }\n\n return debugServerClient;\n } else if (result === 'EBusy' || result === 'ENotFound') {\n debug('Device busy or app not found, trying to launch again in .5s...');\n tries++;\n debugServerClient.socket.end();\n await wait(500);\n } else {\n throw new Error(`There was an error launching app: ${result}`);\n }\n }\n throw new Error('Unable to launch app, number of tries exceeded');\n}\n"],"mappings":";;;;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,IAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,GAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,KAAA;EAAA,MAAAL,IAAA,GAAAM,uBAAA,CAAAJ,OAAA;EAAAG,IAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAO,KAAA;EAAA,MAAAP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