From f7e34cbbe984449d14ef439bc7e809d38372a2bc Mon Sep 17 00:00:00 2001 From: spidy123222 Date: Tue, 1 Apr 2025 02:20:44 -0700 Subject: [PATCH] Rewrite SendAppOperation execution to allow to wait for shortcut execution. --- AltStore/Operations/SendAppOperation.swift | 52 ++++++++++++---------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/AltStore/Operations/SendAppOperation.swift b/AltStore/Operations/SendAppOperation.swift index 9580a3ca..28d58a4a 100644 --- a/AltStore/Operations/SendAppOperation.swift +++ b/AltStore/Operations/SendAppOperation.swift @@ -27,43 +27,49 @@ final class SendAppOperation: ResultOperation<()> self.progress.totalUnitCount = 1 } - override func main() - { + override func main() { super.main() - - if let error = self.context.error - { + + if let error = self.context.error { return self.finish(.failure(error)) } - + guard let resignedApp = self.context.resignedApp else { return self.finish(.failure(OperationError.invalidParameters("SendAppOperation.main: self.resignedApp is nil"))) } - - // self.context.resignedApp.fileURL points to the app bundle, but we want the .ipa. + let shortcutURLoff = URL(string: "shortcuts://run-shortcut?name=TurnOffData")! let shortcutURLon = URL(string: "shortcuts://run-shortcut?name=TurnOnData")! - UIApplication.shared.open(shortcutURLoff, options: [:], completionHandler: nil) - let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL, storeApp: nil) let fileURL = InstalledApp.refreshedIPAURL(for: app) print("AFC App `fileURL`: \(fileURL.absoluteString)") - - if let data = NSData(contentsOf: fileURL) { - do { - let bytes = Data(data).toRustByteSlice() - try yeet_app_afc(app.bundleIdentifier, bytes.forRust()) - self.progress.completedUnitCount += 1 - self.finish(.success(())) - } catch { - self.finish(.failure(MinimuxerError.RwAfc)) - self.progress.completedUnitCount += 1 - self.finish(.success(())) + + // Wait for Shortcut to Finish Before Proceeding + UIApplication.shared.open(shortcutURLoff, options: [:]) { _ in + print("Shortcut finished execution. Proceeding with file transfer.") + + DispatchQueue.global().async { + self.processFile(at: fileURL, for: app.bundleIdentifier) } - } else { + } + } + + private func processFile(at fileURL: URL, for bundleIdentifier: String) { + guard let data = NSData(contentsOf: fileURL) else { print("IPA doesn't exist????") - self.finish(.failure(OperationError(.appNotFound(name: resignedApp.name)))) + return self.finish(.failure(OperationError(.appNotFound(name: bundleIdentifier)))) + } + + do { + let bytes = Data(data).toRustByteSlice() + try yeet_app_afc(bundleIdentifier, bytes.forRust()) + self.progress.completedUnitCount += 1 + self.finish(.success(())) + } catch { + self.finish(.failure(MinimuxerError.RwAfc)) + self.progress.completedUnitCount += 1 + self.finish(.success(())) } } }