From 2090915f5a93121947f935b8293a3ee73b1ef50b Mon Sep 17 00:00:00 2001 From: Ha1baraA11 <243105435+Ha1baraA11@users.noreply.github.com> Date: Tue, 8 Sep 2026 01:45:03 +0800 Subject: [PATCH] fix: keep menu available when device discovery fails --- MiniSim/Service/DeviceDiscoveryService.swift | 10 +++++++++- MiniSim/Service/DeviceServiceFactory.swift | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/MiniSim/Service/DeviceDiscoveryService.swift b/MiniSim/Service/DeviceDiscoveryService.swift index e29b9b0..6e7a775 100644 --- a/MiniSim/Service/DeviceDiscoveryService.swift +++ b/MiniSim/Service/DeviceDiscoveryService.swift @@ -91,6 +91,14 @@ class IOSDeviceDiscovery: DeviceDiscoveryService { } func checkSetup() throws -> Bool { - FileManager.default.fileExists(atPath: DeviceConstants.ProcessPaths.xcrun.rawValue) + guard FileManager.default.fileExists(atPath: DeviceConstants.ProcessPaths.xcrun.rawValue) else { + return false + } + + _ = try shell.execute( + command: DeviceConstants.ProcessPaths.xcrun.rawValue, + arguments: ["simctl", "list", "devices", "available", "-j"] + ) + return true } } diff --git a/MiniSim/Service/DeviceServiceFactory.swift b/MiniSim/Service/DeviceServiceFactory.swift index c656dcb..21490c8 100644 --- a/MiniSim/Service/DeviceServiceFactory.swift +++ b/MiniSim/Service/DeviceServiceFactory.swift @@ -36,11 +36,19 @@ class DeviceServiceFactory { var devicesArray: [Device] = [] if android { - try devicesArray.append(contentsOf: AndroidDeviceDiscovery().getDevices()) + do { + try devicesArray.append(contentsOf: AndroidDeviceDiscovery().getDevices()) + } catch { + // A broken Android installation must not prevent the iOS menu from opening. + } } if iOS { - try devicesArray.append(contentsOf: IOSDeviceDiscovery().getDevices()) + do { + try devicesArray.append(contentsOf: IOSDeviceDiscovery().getDevices()) + } catch { + // xcrun/simctl may be unavailable while the rest of MiniSim is usable. + } } completionQueue.async {