Rewrite SendAppOperation execution to allow to wait for shortcut execution.

This commit is contained in:
spidy123222
2025-04-01 02:20:44 -07:00
committed by Spidy123222
parent 0fe8d7fed9
commit f7e34cbbe9

View File

@@ -27,43 +27,49 @@ final class SendAppOperation: ResultOperation<()>
self.progress.totalUnitCount = 1 self.progress.totalUnitCount = 1
} }
override func main() override func main() {
{
super.main() super.main()
if let error = self.context.error if let error = self.context.error {
{
return self.finish(.failure(error)) return self.finish(.failure(error))
} }
guard let resignedApp = self.context.resignedApp else { guard let resignedApp = self.context.resignedApp else {
return self.finish(.failure(OperationError.invalidParameters("SendAppOperation.main: self.resignedApp is nil"))) 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 shortcutURLoff = URL(string: "shortcuts://run-shortcut?name=TurnOffData")!
let shortcutURLon = URL(string: "shortcuts://run-shortcut?name=TurnOnData")! 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 app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL, storeApp: nil)
let fileURL = InstalledApp.refreshedIPAURL(for: app) let fileURL = InstalledApp.refreshedIPAURL(for: app)
print("AFC App `fileURL`: \(fileURL.absoluteString)") print("AFC App `fileURL`: \(fileURL.absoluteString)")
if let data = NSData(contentsOf: fileURL) { // Wait for Shortcut to Finish Before Proceeding
do { UIApplication.shared.open(shortcutURLoff, options: [:]) { _ in
let bytes = Data(data).toRustByteSlice() print("Shortcut finished execution. Proceeding with file transfer.")
try yeet_app_afc(app.bundleIdentifier, bytes.forRust())
self.progress.completedUnitCount += 1 DispatchQueue.global().async {
self.finish(.success(())) self.processFile(at: fileURL, for: app.bundleIdentifier)
} catch {
self.finish(.failure(MinimuxerError.RwAfc))
self.progress.completedUnitCount += 1
self.finish(.success(()))
} }
} else { }
}
private func processFile(at fileURL: URL, for bundleIdentifier: String) {
guard let data = NSData(contentsOf: fileURL) else {
print("IPA doesn't exist????") 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(()))
} }
} }
} }