Improve Supersign API + speed, and add working demo to Supercharge

This commit is contained in:
kabiroberai
2020-04-17 02:42:49 +05:30
committed by Kabir Oberai
Unverified
parent 9ab597d080
commit d6a7d213ac
6 changed files with 28 additions and 20 deletions
@@ -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)))
}
}
@@ -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)
+2 -2
View File
@@ -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
) {
+2 -2
View File
@@ -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)
+13 -11
View File
@@ -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 {
+4 -2
View File
@@ -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,