Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

Improve installer progress reporting

kabiroberaibf2729321ea5
diff --git a/Supersign/Sources/Supersign/Installation/ConnectionManager.swift b/Supersign/Sources/Supersign/Installation/ConnectionManager.swift
index 4ba25bd..493e66e 100644
--- a/Supersign/Sources/Supersign/Installation/ConnectionManager.swift
+++ b/Supersign/Sources/Supersign/Installation/ConnectionManager.swift
@@ -87,13 +87,15 @@ public class ConnectionManager {
private var token: USBMux.SubscriptionToken?
- public weak var delegate: ConnectionManagerDelegate?
+ public let usbOnly: Bool
+ public private(set) weak var delegate: ConnectionManagerDelegate?
private func clientsDidChange() {
clients = clientsDict.sorted { $0.0 < $1.0 }.map(Client.init)
}
- public init(delegate: ConnectionManagerDelegate? = nil) throws {
+ public init(usbOnly: Bool = false, delegate: ConnectionManagerDelegate? = nil) throws {
+ self.usbOnly = usbOnly
self.delegate = delegate
self.token = try USBMux.subscribe { [weak self] event in
guard let self = self else { return }
@@ -102,8 +104,10 @@ public class ConnectionManager {
}
private func handleEvent(_ event: USBMux.Event) {
+ let connectionType = event.device.connectionType
+ guard !usbOnly || connectionType == .usb else { return }
let udid = event.device.udid
- let key = ConnectionKey(udid: udid, connectionType: event.device.connectionType)
+ let key = ConnectionKey(udid: udid, connectionType: connectionType)
switch event.kind {
case .removed:
clientsDict[key] = nil
diff --git a/Supersign/Sources/Supersign/Integration/SuperchargeInstaller.swift b/Supersign/Sources/Supersign/Integration/SuperchargeInstaller.swift
index f339201..ad0f8ef 100644
--- a/Supersign/Sources/Supersign/Integration/SuperchargeInstaller.swift
+++ b/Supersign/Sources/Supersign/Integration/SuperchargeInstaller.swift
@@ -125,10 +125,10 @@ public final class SuperchargeInstaller {
}
private var stage: String?
- private func updateStage(to stage: String, ignoreCancellation: Bool = false) -> Bool {
- guard ignoreCancellation || shouldContinue() else { return false }
+ private func updateStage(to stage: String, initialProgress: Double? = 0, ignoreCancellation: Bool = false) -> Bool {
+ guard ignoreCancellation || shouldContinue(), self.stage != stage else { return false }
self.stage = stage
- delegate?.installerDidUpdate(toStage: stage, progress: 0)
+ delegate?.installerDidUpdate(toStage: stage, progress: initialProgress)
return true
}
private func updateProgress(to progress: Double?, ignoreCancellation: Bool = false) -> Bool {
@@ -245,9 +245,13 @@ public final class SuperchargeInstaller {
try lockdownClient.pair(withRecord: record)
}
- return try PropertyListSerialization.data(
+ let data = try PropertyListSerialization.data(
fromPropertyList: plist, format: plistFormat, options: 0
)
+
+ guard updateProgress(to: 1) else { return nil }
+
+ return data
}
private func install(
@@ -278,8 +282,7 @@ public final class SuperchargeInstaller {
team: DeveloperServicesTeam,
appDir: URL
) {
- guard self.updateStage(to: "Packaging"),
- self.updateProgress(to: nil)
+ guard self.updateStage(to: "Packaging", initialProgress: nil)
else { return }
delegate?.compress(
@@ -288,6 +291,7 @@ public final class SuperchargeInstaller {
_ = self.updateProgress(to: progress, ignoreCancellation: true)
},
completion: { url in
+ guard self.updateProgress(to: 1) else { return self.completion(.failure(Error.userCancelled)) }
self.installQueue.async {
self.install(
deviceInfo: deviceInfo,
@@ -420,7 +424,7 @@ public final class SuperchargeInstaller {
}
private func installOnQueue(ipa: URL) {
- guard self.updateStage(to: "Unpacking app") else { return }
+ guard self.updateStage(to: "Unpacking app", initialProgress: nil) else { return }
if FileManager.default.fileExists(atPath: tempDir.path) {
try? FileManager.default.removeItem(at: tempDir)
@@ -439,7 +443,7 @@ public final class SuperchargeInstaller {
_ = self.updateProgress(to: progress, ignoreCancellation: true)
},
completion: { success in
- guard self.shouldContinue() else { return self.completion(.failure(Error.userCancelled)) }
+ guard self.updateProgress(to: 1) else { return self.completion(.failure(Error.userCancelled)) }
self.installQueue.async {
self.install(decompressionDidSucceed: success)
}
diff --git a/Supersign/Sources/SupersignCLI/main.swift b/Supersign/Sources/SupersignCLI/main.swift
index f3779dc..7f8146d 100644
--- a/Supersign/Sources/SupersignCLI/main.swift
+++ b/Supersign/Sources/SupersignCLI/main.swift
@@ -124,7 +124,7 @@ class SupersignCLIDelegate: SuperchargeInstallerDelegate {
print("\n[\(stage)] \(progString)", terminator: "")
fflush(stdout)
} else {
- print("\n===[\(stage)]===", terminator: "")
+ print("\n[\(stage)] ...", terminator: "")
fflush(stdout)
}
} else if progString != prevProgress {
@@ -139,7 +139,7 @@ class SupersignCLIDelegate: SuperchargeInstallerDelegate {
}
func installerDidComplete(withResult result: Result<(), Error>) {
- print()
+ print("\n")
switch result {
case .success:
print("Complete!")
@@ -186,18 +186,13 @@ class SupersignCLIDelegate: SuperchargeInstallerDelegate {
}
class ConnectionDelegate: ConnectionManagerDelegate {
- let usbOnly: Bool
var onConnect: (([ConnectionManager.Client]) -> Void)?
- init(usbOnly: Bool, onConnect: @escaping ([ConnectionManager.Client]) -> Void) {
- self.usbOnly = usbOnly
+ init(onConnect: @escaping ([ConnectionManager.Client]) -> Void) {
self.onConnect = onConnect
}
func connectionManager(_ manager: ConnectionManager, clientsDidChangeFrom oldValue: [ConnectionManager.Client]) {
- var usableClients = manager.clients
- if usbOnly {
- usableClients.removeAll { $0.connectionType != .usb }
- }
+ let usableClients = manager.clients
guard !usableClients.isEmpty else { return }
onConnect?(usableClients)
onConnect = nil
@@ -220,11 +215,11 @@ func main() throws {
print("Waiting for device to be connected...")
var clients: [ConnectionManager.Client]!
let semaphore = DispatchSemaphore(value: 0)
- let connDelegate = ConnectionDelegate(usbOnly: true) { currClients in
+ let connDelegate = ConnectionDelegate { currClients in
clients = currClients
semaphore.signal()
}
- try withExtendedLifetime(ConnectionManager(delegate: connDelegate)) {
+ try withExtendedLifetime(ConnectionManager(usbOnly: true, delegate: connDelegate)) {
semaphore.wait()
}