[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.
This commit is contained in:
Riley Testut
2023-09-08 16:34:07 -05:00
committed by Magesh K
parent d657ffc8ca
commit 297a71bf91

View File

@@ -107,9 +107,16 @@ private extension JITManager
private extension JITManager
{
func installPersonalizedDeveloperDisk(onto device: ALTDevice) async throws
{
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"
}
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
}
}
}