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.

Progress fixes

Kabir Oberai5adf53108551
diff --git a/Sources/Supersign/Integration/SuperchargeInstaller.swift b/Sources/Supersign/Integration/SuperchargeInstaller.swift
index 77bd3f2..0487e9a 100644
--- a/Sources/Supersign/Integration/SuperchargeInstaller.swift
+++ b/Sources/Supersign/Integration/SuperchargeInstaller.swift
@@ -8,6 +8,7 @@
import Foundation
import SwiftyMobileDevice
+import ConcurrencyExtras
extension LockdownClient {
static let installerLabel = "supersign"
@@ -101,19 +102,24 @@ public actor IntegratedInstaller {
private var stage: String?
- private func updateStage(
- to stage: String,
- initialProgress: Double? = 0
- ) async throws {
- await Task.yield()
- try Task.checkCancellation()
- updateStageIgnoringCancellation(to: stage, initialProgress: initialProgress)
+ private nonisolated let updateTask = LockIsolated<Task<Void, Never>?>(nil)
+
+ private nonisolated func queueUpdateTask(
+ _ perform: @escaping @Sendable (isolated IntegratedInstaller) async -> Void
+ ) {
+ updateTask.withValue { task in
+ task = Task { [prev = task] in
+ await prev?.value
+ await perform(self)
+ }
+ }
}
private func updateStage(
to stage: String,
initialProgress: Double? = 0
- ) throws {
+ ) async throws {
+ await Task.yield()
try Task.checkCancellation()
updateStageIgnoringCancellation(to: stage, initialProgress: initialProgress)
}
@@ -133,11 +139,6 @@ public actor IntegratedInstaller {
updateProgressIgnoringCancellation(to: progress)
}
- private func updateProgress(to progress: Double?) throws {
- try Task.checkCancellation()
- updateProgressIgnoringCancellation(to: progress)
- }
-
private func updateProgressIgnoringCancellation(to progress: Double?) {
guard let stage = stage else {
preconditionFailure("Cannot change progress without setting stage at least once")
@@ -286,9 +287,9 @@ public actor IntegratedInstaller {
self.appInstaller = appInstaller
try await appInstaller.install(
progress: { stage in
- Task {
- await self.updateStageIgnoringCancellation(to: stage.displayName)
- await self.updateProgressIgnoringCancellation(to: stage.displayProgress)
+ self.queueUpdateTask {
+ $0.updateStageIgnoringCancellation(to: stage.displayName)
+ $0.updateProgressIgnoringCancellation(to: stage.displayProgress)
}
}
)
@@ -308,8 +309,8 @@ public actor IntegratedInstaller {
let ipa = try await delegate?.compress(
payloadDir: appDir.deletingLastPathComponent(),
progress: { progress in
- Task {
- await self.updateProgressIgnoringCancellation(to: progress)
+ self.queueUpdateTask {
+ $0.updateProgressIgnoringCancellation(to: progress)
}
}
)
@@ -353,13 +354,13 @@ public actor IntegratedInstaller {
let bundleID = try await signer.sign(
app: appDir,
status: { @Sendable status in
- Task {
- await self.updateStageIgnoringCancellation(to: status)
+ self.queueUpdateTask {
+ $0.updateStageIgnoringCancellation(to: status)
}
},
progress: { progress in
- Task {
- _ = await self.updateProgressIgnoringCancellation(to: progress)
+ self.queueUpdateTask {
+ $0.updateProgressIgnoringCancellation(to: progress)
}
},
didProvision: { @Sendable in
@@ -477,8 +478,8 @@ public actor IntegratedInstaller {
ipa: app,
in: tempDir,
progress: { progress in
- Task {
- await self.updateProgressIgnoringCancellation(to: progress)
+ self.queueUpdateTask {
+ $0.updateProgressIgnoringCancellation(to: progress)
}
}
)
diff --git a/Sources/Supersign/Signer/Signer.swift b/Sources/Supersign/Signer/Signer.swift
index f5a4425..83f9883 100644
--- a/Sources/Supersign/Signer/Signer.swift
+++ b/Sources/Supersign/Signer/Signer.swift
@@ -99,6 +99,7 @@ public struct Signer {
entitlementMapping: entitlements,
progress: progress
)
+ progress(1)
return mainInfo.newBundleID
}
diff --git a/Sources/SupersignCLISupport/SupersignCLIDelegate.swift b/Sources/SupersignCLISupport/SupersignCLIDelegate.swift
index 3cb3e64..ef1ea67 100644
--- a/Sources/SupersignCLISupport/SupersignCLIDelegate.swift
+++ b/Sources/SupersignCLISupport/SupersignCLIDelegate.swift
@@ -1,5 +1,6 @@
import Foundation
import Supersign
+import ConcurrencyExtras
private func _fetchCode() async -> String? {
Console.prompt("Code: ")
@@ -22,6 +23,8 @@ actor SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDelegate {
self.preferredTeam = preferredTeam
}
+ private let updateTask = LockIsolated<Task<Void, Never>?>(nil)
+
func fetchCode() async -> String? {
await _fetchCode()
}
@@ -100,7 +103,12 @@ actor SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDelegate {
}
nonisolated func installerDidUpdate(toStage stage: String, progress: Double?) {
- Task { await _installerDidUpdate(toStage: stage, progress: progress) }
+ updateTask.withValue { task in
+ task = Task { [prev = task] in
+ await prev?.value
+ await _installerDidUpdate(toStage: stage, progress: progress)
+ }
+ }
}
private static let expiryFormatter: DateFormatter = {