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 Supersign API + speed, and add working demo to Supercharge

kabiroberaid6a7d213ac49
diff --git a/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift b/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift
index 5e91dc8..206cb45 100644
--- a/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift
+++ b/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift
@@ -23,18 +23,24 @@ public struct DeveloperServicesProvisioningOperation: DeveloperServicesOperation
public let context: SigningContext
public let app: URL
- public init(context: SigningContext, app: URL) {
+ public let progress: (Double) -> Void
+ public init(context: SigningContext, app: URL, progress: @escaping (Double) -> Void) {
self.context = context
self.app = app
+ self.progress = progress
}
public func perform(completion: @escaping (Result<Response, Error>) -> Void) {
+ progress(0/3)
DeveloperServicesFetchDeviceOperation(context: context).perform { result in
guard result.get(withErrorHandler: completion) != nil else { return }
+ self.progress(1/3)
DeveloperServicesFetchCertificateOperation(context: self.context).perform { result in
guard let signingInfo = result.get(withErrorHandler: completion) else { return }
+ self.progress(2/3)
DeveloperServicesAddAppOperation(context: self.context, root: self.app).perform { result in
guard let provisioningDict = result.get(withErrorHandler: completion) else { return }
+ self.progress(3/3)
completion(.success(.init(signingInfo: signingInfo, provisioningDict: provisioningDict)))
}
}
diff --git a/Supersign/GrandSlam/GrandSlamClient.swift b/Supersign/GrandSlam/GrandSlamClient.swift
index 76ddd22..b8d37aa 100644
--- a/Supersign/GrandSlam/GrandSlamClient.swift
+++ b/Supersign/GrandSlam/GrandSlamClient.swift
@@ -32,8 +32,6 @@ class GrandSlamClient {
url: URL,
completion: @escaping (Result<R.Decoder.Value, Swift.Error>) -> Void
) {
- print("Sending: \(request) to \(url)")
-
var urlRequest = URLRequest(url: url)
urlRequest.setValue("text/x-xml-plist", forHTTPHeaderField: "Content-Type")
urlRequest.setValue(deviceInfo.clientInfo.clientString, forHTTPHeaderField: DeviceInfo.clientInfoKey)
diff --git a/Supersign/Installation/AppInstaller.swift b/Supersign/Installation/AppInstaller.swift
index ac17b93..4415100 100644
--- a/Supersign/Installation/AppInstaller.swift
+++ b/Supersign/Installation/AppInstaller.swift
@@ -79,7 +79,7 @@ public class AppInstaller {
ipa: URL,
bundleID: String,
udid: String,
- pairingKeys: URL,
+ pairingKeys: Data,
progress: @escaping (Stage) -> Void
) throws {
let connection = try Connection(udid: udid, pairingKeys: pairingKeys) {
@@ -109,7 +109,7 @@ public class AppInstaller {
ipa: URL,
bundleID: String,
udid: String,
- pairingKeys: URL,
+ pairingKeys: Data,
progress: @escaping (Stage) -> Void,
completion: @escaping (Result<(), Swift.Error>) -> Void
) {
diff --git a/Supersign/Installation/Connection.swift b/Supersign/Installation/Connection.swift
index 9d56fcc..a1995bd 100644
--- a/Supersign/Installation/Connection.swift
+++ b/Supersign/Installation/Connection.swift
@@ -20,10 +20,10 @@ public class Connection {
public let client: LockdownClient
private let heartbeatHandler: HeartbeatHandler
- public init(udid: String, pairingKeys: URL, progress: (Double) -> Void) throws {
+ public init(udid: String, pairingKeys: Data, progress: (Double) -> Void) throws {
progress(0/4)
- usbmuxHandler = USBMuxHandler(udid: udid, pairingKeys: pairingKeys)
+ usbmuxHandler = try USBMuxHandler(udid: udid, pairingKeys: pairingKeys)
progress(1/4)
device = try Device(udid: udid)
diff --git a/Supersign/Installation/IPAUploader.swift b/Supersign/Installation/IPAUploader.swift
index 6c9f6e8..de50822 100644
--- a/Supersign/Installation/IPAUploader.swift
+++ b/Supersign/Installation/IPAUploader.swift
@@ -9,9 +9,10 @@
import Foundation
import SwiftyMobileDevice
-public class IPAUploader {
+public final class IPAUploader {
private static let packagePath = URL(fileURLWithPath: "PublicStaging")
+ private static let bufferSize = 1 << 20 // 1 MB
public class UploadedIPA {
public let uploader: IPAUploader
@@ -36,25 +37,26 @@ public class IPAUploader {
}
private func upload(_ src: URL, to dest: URL, progress: (Double) -> Void) throws {
- let srcHandle = try FileHandle(forReadingFrom: src)
- let size = srcHandle.seekToEndOfFile()
- srcHandle.seek(toFileOffset: 0)
-
+ let srcData = try Data(contentsOf: src)
+ let size = srcData.count
+ let sizeDouble = Double(size)
let destFile = try client.open(dest, mode: .writeOnly)
+ let bufferSize = Self.bufferSize
+
var totalWritten = 0
- var buf: Data
- repeat {
- buf = srcHandle.readData(ofLength: 1 << 20) // 1 MB
+ while totalWritten != size {
+ let buf = srcData.dropFirst(totalWritten).prefix(bufferSize)
+ let bufSize = buf.count
var bufWritten = 0
- while bufWritten < buf.count {
+ while bufWritten < bufSize {
// not sure if rewriting the same buf is a bug but ideviceinstaller does it this way
let written = try destFile.write(buf)
bufWritten += written
totalWritten += written
- progress(Double(totalWritten) / Double(size))
+ progress(Double(totalWritten) / sizeDouble)
}
- } while !buf.isEmpty
+ }
}
public func upload(ipa: URL, withBundleID bundleID: String, progress: (Double) -> Void) throws -> UploadedIPA {
diff --git a/Supersign/Signer/Signer.swift b/Supersign/Signer/Signer.swift
index cedcd33..ad889f6 100644
--- a/Supersign/Signer/Signer.swift
+++ b/Supersign/Signer/Signer.swift
@@ -70,6 +70,8 @@ public struct Signer {
}
let entitlements = provisioningDict.mapValues { $0.entitlements }
+
+ status(NSLocalizedString("signer.signing", value: "Signing", comment: ""))
context.signerImpl.sign(
app: app,
certificate: signingInfo.certificate,
@@ -86,8 +88,8 @@ public struct Signer {
progress: @escaping (Double) -> Void,
completion: @escaping (Result<(), Swift.Error>) -> Void
) {
- status(NSLocalizedString("signer.signing", value: "Signing", comment: ""))
- DeveloperServicesProvisioningOperation(context: context, app: app).perform { result in
+ status(NSLocalizedString("signer.provisioning", value: "Provisioning", comment: ""))
+ DeveloperServicesProvisioningOperation(context: context, app: app, progress: progress).perform { result in
guard let response = result.get(withErrorHandler: completion) else { return }
self.sign(
app: app,