mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Rewrite SendAppOperation execution to allow to wait for shortcut execution.
This commit is contained in:
@@ -27,12 +27,10 @@ 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,20 +38,32 @@ final class SendAppOperation: ResultOperation<()>
|
|||||||
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
|
||||||
|
UIApplication.shared.open(shortcutURLoff, options: [:]) { _ in
|
||||||
|
print("Shortcut finished execution. Proceeding with file transfer.")
|
||||||
|
|
||||||
|
DispatchQueue.global().async {
|
||||||
|
self.processFile(at: fileURL, for: app.bundleIdentifier)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func processFile(at fileURL: URL, for bundleIdentifier: String) {
|
||||||
|
guard let data = NSData(contentsOf: fileURL) else {
|
||||||
|
print("IPA doesn't exist????")
|
||||||
|
return self.finish(.failure(OperationError(.appNotFound(name: bundleIdentifier))))
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let bytes = Data(data).toRustByteSlice()
|
let bytes = Data(data).toRustByteSlice()
|
||||||
try yeet_app_afc(app.bundleIdentifier, bytes.forRust())
|
try yeet_app_afc(bundleIdentifier, bytes.forRust())
|
||||||
self.progress.completedUnitCount += 1
|
self.progress.completedUnitCount += 1
|
||||||
self.finish(.success(()))
|
self.finish(.success(()))
|
||||||
} catch {
|
} catch {
|
||||||
@@ -61,9 +71,5 @@ final class SendAppOperation: ResultOperation<()>
|
|||||||
self.progress.completedUnitCount += 1
|
self.progress.completedUnitCount += 1
|
||||||
self.finish(.success(()))
|
self.finish(.success(()))
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
print("IPA doesn't exist????")
|
|
||||||
self.finish(.failure(OperationError(.appNotFound(name: resignedApp.name))))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user