From 297a71bf9114295ba030ef9d7e44927222c4cacd Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 8 Sep 2023 16:34:07 -0500 Subject: [PATCH] [AltServer] Throws ALTServerError.deviceNotFound if altjit cannot find device Includes custom recovery suggestion to mention connecting via USB is required for iOS 17 or later. --- AltServer/JIT/JITManager.swift | 44 ++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/AltServer/JIT/JITManager.swift b/AltServer/JIT/JITManager.swift index 6d9befd7..b85abeff 100644 --- a/AltServer/JIT/JITManager.swift +++ b/AltServer/JIT/JITManager.swift @@ -108,7 +108,14 @@ private extension JITManager { func installPersonalizedDeveloperDisk(onto device: ALTDevice) async throws { - _ = try await Process.launchAndWait(.altjit, arguments: ["mount", "--udid", device.identifier]) + do + { + _ = try await Process.launchAndWait(.altjit, arguments: ["mount", "--udid", device.identifier]) + } + catch + { + try self.processAltJITError(error) + } } func enableModernUnsignedCodeExecution(process: AppProcess, device: ALTDevice) async throws @@ -132,9 +139,23 @@ private extension JITManager self.authorization = try Process.runAsAdmin(URL.altjit.path, arguments: arguments, authorization: self.authorization) } + catch + { + try self.processAltJITError(error) + } + } + + func processAltJITError(_ error: some Error) throws + { + do + { + throw error + } catch let error as ProcessError where error.code == .failed { - let regex = Regex { + guard let output = error.output else { throw error } + + let dependencyNotFoundRegex = Regex { "No module named" OneOrMore(.whitespace) @@ -144,10 +165,23 @@ private extension JITManager } } - guard let output = error.output, let match = output.firstMatch(of: regex) else { throw error } + let deviceNotFoundRegex = Regex { + "Device is not connected" + } - let dependency = String(match.1) - throw JITError.dependencyNotFound(dependency) + if let match = output.firstMatch(of: dependencyNotFoundRegex) + { + let dependency = String(match.1) + throw JITError.dependencyNotFound(dependency) + } + else if output.contains(deviceNotFoundRegex) + { + throw ALTServerError(.deviceNotFound, userInfo: [ + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString("Your device must be plugged into your computer to enable JIT on iOS 17 or later.", comment: "") + ]) + } + + throw error } } }