(
file: File,
simulator: SimulatorMetadata | null,
)
| 2733 | } |
| 2734 | |
| 2735 | async function installAppFile( |
| 2736 | file: File, |
| 2737 | simulator: SimulatorMetadata | null, |
| 2738 | ) { |
| 2739 | if (appInstallState?.phase === "installing") { |
| 2740 | setLocalError("Wait for the current app install to finish."); |
| 2741 | return; |
| 2742 | } |
| 2743 | if (!simulator) { |
| 2744 | setAppInstallState(null); |
| 2745 | setLocalError("Select a simulator before installing an app."); |
| 2746 | return; |
| 2747 | } |
| 2748 | if (!simulator.isBooted) { |
| 2749 | setAppInstallState(null); |
| 2750 | setLocalError("Boot the selected simulator before installing an app."); |
| 2751 | return; |
| 2752 | } |
| 2753 | |
| 2754 | const appKind = installableAppKind(file.name); |
| 2755 | const simulatorIsAndroid = isAndroidSimulator(simulator); |
| 2756 | if (!appKind) { |
| 2757 | setAppInstallState(null); |
| 2758 | setLocalError( |
| 2759 | simulatorIsAndroid |
| 2760 | ? "Drop an `.apk` file for Android emulators." |
| 2761 | : "Drop an `.ipa` file for iOS simulators.", |
| 2762 | ); |
| 2763 | return; |
| 2764 | } |
| 2765 | if (simulatorIsAndroid && appKind !== "apk") { |
| 2766 | setAppInstallState(null); |
| 2767 | setLocalError("Android emulators can only install `.apk` files."); |
| 2768 | return; |
| 2769 | } |
| 2770 | if (!simulatorIsAndroid && appKind !== "ipa") { |
| 2771 | setAppInstallState(null); |
| 2772 | setLocalError("iOS simulators can only install `.ipa` files."); |
| 2773 | return; |
| 2774 | } |
| 2775 | |
| 2776 | const fileName = file.name || "app"; |
| 2777 | setLocalError(""); |
| 2778 | setAppInstallState({ fileName, phase: "installing" }); |
| 2779 | try { |
| 2780 | await uploadSimulatorApp(simulator.udid, file); |
| 2781 | setAppInstallState({ fileName, phase: "installed" }); |
| 2782 | clearAppInstallStatusLater(fileName); |
| 2783 | await refresh(); |
| 2784 | } catch (error) { |
| 2785 | setAppInstallState(null); |
| 2786 | setLocalError(error instanceof Error ? error.message : "Install failed."); |
| 2787 | } |
| 2788 | } |
| 2789 | |
| 2790 | function clearAppInstallStatusLater(fileName: string) { |
| 2791 | if (appInstallStatusTimeoutRef.current) { |
no test coverage detected