Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
Implement supersign cancellation
kabiroberai27eeddcdc596
diff --git a/Supersign/Installation/AppInstaller.swift b/Supersign/Installation/AppInstaller.swiftindex 4415100..c0ef14e 100644--- a/Supersign/Installation/AppInstaller.swift+++ b/Supersign/Installation/AppInstaller.swift@@ -12,10 +12,17 @@ import SwiftyMobileDevicepublic class AppInstaller {public enum Error: LocalizedError {+ case userCancelledcase invalidURLpublic var errorDescription: String? {switch self {+ case .userCancelled:+ return NSLocalizedString(+ "app_installer.error.user_cancelled",+ value: "The user cancelled the operation",+ comment: ""+ )case .invalidURL:return NSLocalizedString("app_installer.error.invalid_url",@@ -71,59 +78,85 @@ public class AppInstaller {label: "com.kabiroberai.Supersign.install-queue")- private init() {}- public static let shared = AppInstaller()+ private var needsCancellation = false+ // throws `Error.userCancelled` if the user cancelled this operation+ private func cancelPoint() throws {+ if needsCancellation {+ throw Error.userCancelled+ }+ }- // synchronous- private func installSync(+ public let ipa: URL+ public let bundleID: String+ public let udid: String+ public let pairingKeys: Data+ public init(ipa: URL,bundleID: String,udid: String,- pairingKeys: Data,+ pairingKeys: Data+ ) {+ self.ipa = ipa+ self.bundleID = bundleID+ self.udid = udid+ self.pairingKeys = pairingKeys+ }++ #warning("We should have some sort of `static` queue/lock")+ // because if two connections are attempted simultaneously,+ // the heartbeat will fail.++ // synchronous+ private func installSync(progress: @escaping (Stage) -> Void) throws {+ defer { needsCancellation = false }+ try cancelPoint()+let connection = try Connection(udid: udid, pairingKeys: pairingKeys) {progress(.connecting($0 * 4/6))}defer { connection.close() }+ try cancelPoint()+let uploader = try IPAUploader(connection: connection)progress(.connecting(5/6))+ try cancelPoint()+// we need to start the installer quickly because sometimes it fails if we do it after// uploading the ipa to the devicelet installer = try IPAInstaller(connection: connection)progress(.connecting(6/6))+ try cancelPoint()+let uploaded = try uploader.upload(ipa: ipa, withBundleID: bundleID) { currentProgress inprogress(.uploading(currentProgress))}defer { uploaded.delete() }+ try cancelPoint()+try installer.install(uploaded: uploaded, bundleID: bundleID) { currentProgress inprogress(.installing(currentProgress.details, currentProgress.progress))}}public func install(- ipa: URL,- bundleID: String,- udid: String,- pairingKeys: Data,progress: @escaping (Stage) -> Void,completion: @escaping (Result<(), Swift.Error>) -> Void) {installQueue.async {completion(Result {- try self.installSync(- ipa: ipa,- bundleID: bundleID,- udid: udid,- pairingKeys: pairingKeys,- progress: progress- )+ try self.installSync(progress: progress)})}}+ public func cancel() {+ needsCancellation = true+ }+}