mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-21 02:41:46 +03:00
Update to Swift 6
This commit is contained in:
+210
-202
@@ -1,205 +1,213 @@
|
||||
{
|
||||
"object": {
|
||||
"pins": [
|
||||
{
|
||||
"package": "async-http-client",
|
||||
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "0a9b72369b9d87ab155ef585ef50700a34abf070",
|
||||
"version": "1.23.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "BigInt",
|
||||
"repositoryURL": "https://github.com/attaswift/BigInt",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "a7ee11486233ba45f5ceee0b8cb3d6629ed450ef",
|
||||
"version": "5.5.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "SuperchargeCore",
|
||||
"repositoryURL": "https://github.com/SuperchargeApp/SuperchargeCore",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "570d27aa538379f94196ec44bae440ef243bb666",
|
||||
"version": "1.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-algorithms",
|
||||
"repositoryURL": "https://github.com/apple/swift-algorithms.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "f6919dfc309e7f1b56224378b11e28bab5bccc42",
|
||||
"version": "1.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-argument-parser",
|
||||
"repositoryURL": "https://github.com/apple/swift-argument-parser",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "41982a3656a71c768319979febd796c6fd111d5c",
|
||||
"version": "1.5.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-asn1",
|
||||
"repositoryURL": "https://github.com/apple/swift-asn1.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6",
|
||||
"version": "1.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-atomics",
|
||||
"repositoryURL": "https://github.com/apple/swift-atomics.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "cd142fd2f64be2100422d658e7411e39489da985",
|
||||
"version": "1.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-certificates",
|
||||
"repositoryURL": "https://github.com/apple/swift-certificates",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "1fbb6ef21f1525ed5faf4c95207b9c11bea27e94",
|
||||
"version": "1.6.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-collections",
|
||||
"repositoryURL": "https://github.com/apple/swift-collections.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "671108c96644956dddcd89dd59c203dcdb36cec7",
|
||||
"version": "1.1.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-crypto",
|
||||
"repositoryURL": "https://github.com/apple/swift-crypto",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "06dc63c6d8da54ee11ceb268cde1fa68161afc96",
|
||||
"version": "3.9.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-http-types",
|
||||
"repositoryURL": "https://github.com/apple/swift-http-types",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "ef18d829e8b92d731ad27bb81583edd2094d1ce3",
|
||||
"version": "1.3.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-log",
|
||||
"repositoryURL": "https://github.com/apple/swift-log.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "9cb486020ebf03bfa5b5df985387a14a98744537",
|
||||
"version": "1.6.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-nio",
|
||||
"repositoryURL": "https://github.com/apple/swift-nio.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "914081701062b11e3bb9e21accc379822621995e",
|
||||
"version": "2.76.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-nio-extras",
|
||||
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "2e9746cfc57554f70b650b021b6ae4738abef3e6",
|
||||
"version": "1.24.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-nio-http2",
|
||||
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "eaa71bb6ae082eee5a07407b1ad0cbd8f48f9dca",
|
||||
"version": "1.34.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-nio-ssl",
|
||||
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "c7e95421334b1068490b5d41314a50e70bab23d1",
|
||||
"version": "2.29.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-nio-transport-services",
|
||||
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "bbd5e63cf949b7db0c9edaf7a21e141c52afe214",
|
||||
"version": "1.23.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-numerics",
|
||||
"repositoryURL": "https://github.com/apple/swift-numerics.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "0a5bc04095a675662cf24757cc0640aa2204253b",
|
||||
"version": "1.0.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-system",
|
||||
"repositoryURL": "https://github.com/apple/swift-system.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "c8a44d836fe7913603e246acab7c528c2e780168",
|
||||
"version": "1.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "SwiftyMobileDevice",
|
||||
"repositoryURL": "https://github.com/SuperchargeApp/SwiftyMobileDevice",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "1823b7de02130e64ca4e42947056f78a85a12b39",
|
||||
"version": "1.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "websocket-kit",
|
||||
"repositoryURL": "https://github.com/vapor/websocket-kit.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "4232d34efa49f633ba61afde365d3896fc7f8740",
|
||||
"version": "2.15.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "zsign",
|
||||
"repositoryURL": "https://github.com/kabiroberai/zsign",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "45fa854a214c5a68bd35d1e35e90dfe9be28c7d4",
|
||||
"version": "1.2.4"
|
||||
}
|
||||
"originHash" : "f5935ae26f2a05b003fab58924d18ded1d3eb79e578be093e900459aaaae1468",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "async-http-client",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/swift-server/async-http-client.git",
|
||||
"state" : {
|
||||
"revision" : "0a9b72369b9d87ab155ef585ef50700a34abf070",
|
||||
"version" : "1.23.1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"version": 1
|
||||
},
|
||||
{
|
||||
"identity" : "bigint",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/attaswift/BigInt",
|
||||
"state" : {
|
||||
"revision" : "a7ee11486233ba45f5ceee0b8cb3d6629ed450ef",
|
||||
"version" : "5.5.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "superchargecore",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/SuperchargeApp/SuperchargeCore",
|
||||
"state" : {
|
||||
"revision" : "e409f42fd5736fac149c8288eba69c50e7eac5c2",
|
||||
"version" : "1.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-algorithms",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-algorithms.git",
|
||||
"state" : {
|
||||
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
|
||||
"version" : "1.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-argument-parser",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-argument-parser",
|
||||
"state" : {
|
||||
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
|
||||
"version" : "1.5.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-asn1",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-asn1.git",
|
||||
"state" : {
|
||||
"revision" : "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6",
|
||||
"version" : "1.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-atomics",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-atomics.git",
|
||||
"state" : {
|
||||
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
|
||||
"version" : "1.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-certificates",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-certificates",
|
||||
"state" : {
|
||||
"revision" : "1fbb6ef21f1525ed5faf4c95207b9c11bea27e94",
|
||||
"version" : "1.6.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-collections",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-collections.git",
|
||||
"state" : {
|
||||
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
|
||||
"version" : "1.1.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-concurrency-extras",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/pointfreeco/swift-concurrency-extras.git",
|
||||
"state" : {
|
||||
"revision" : "163409ef7dae9d960b87f34b51587b6609a76c1f",
|
||||
"version" : "1.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-crypto",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-crypto",
|
||||
"state" : {
|
||||
"revision" : "06dc63c6d8da54ee11ceb268cde1fa68161afc96",
|
||||
"version" : "3.9.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-http-types",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-http-types",
|
||||
"state" : {
|
||||
"revision" : "ef18d829e8b92d731ad27bb81583edd2094d1ce3",
|
||||
"version" : "1.3.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-log",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-log.git",
|
||||
"state" : {
|
||||
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
|
||||
"version" : "1.6.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-nio",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio.git",
|
||||
"state" : {
|
||||
"revision" : "914081701062b11e3bb9e21accc379822621995e",
|
||||
"version" : "2.76.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-nio-extras",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-extras.git",
|
||||
"state" : {
|
||||
"revision" : "2e9746cfc57554f70b650b021b6ae4738abef3e6",
|
||||
"version" : "1.24.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-nio-http2",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-http2.git",
|
||||
"state" : {
|
||||
"revision" : "eaa71bb6ae082eee5a07407b1ad0cbd8f48f9dca",
|
||||
"version" : "1.34.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-nio-ssl",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-ssl.git",
|
||||
"state" : {
|
||||
"revision" : "c7e95421334b1068490b5d41314a50e70bab23d1",
|
||||
"version" : "2.29.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-nio-transport-services",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-transport-services.git",
|
||||
"state" : {
|
||||
"revision" : "bbd5e63cf949b7db0c9edaf7a21e141c52afe214",
|
||||
"version" : "1.23.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-numerics",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-numerics.git",
|
||||
"state" : {
|
||||
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
|
||||
"version" : "1.0.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-system",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-system.git",
|
||||
"state" : {
|
||||
"revision" : "c8a44d836fe7913603e246acab7c528c2e780168",
|
||||
"version" : "1.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftymobiledevice",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/SuperchargeApp/SwiftyMobileDevice",
|
||||
"state" : {
|
||||
"revision" : "c7772fb58452c9df727568dda3ca08cf716ef608",
|
||||
"version" : "1.2.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "websocket-kit",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/vapor/websocket-kit.git",
|
||||
"state" : {
|
||||
"revision" : "4232d34efa49f633ba61afde365d3896fc7f8740",
|
||||
"version" : "2.15.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "zsign",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/kabiroberai/zsign",
|
||||
"state" : {
|
||||
"revision" : "c3fea016227f595cd51f037450650a2ff362f7db",
|
||||
"version" : "1.3.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
}
|
||||
|
||||
+7
-5
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.3
|
||||
// swift-tools-version:6.0
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -27,15 +27,16 @@ let package = Package(
|
||||
),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/SuperchargeApp/SuperchargeCore", .upToNextMinor(from: "1.1.1")),
|
||||
.package(url: "https://github.com/SuperchargeApp/SwiftyMobileDevice", .upToNextMinor(from: "1.1.1")),
|
||||
.package(url: "https://github.com/kabiroberai/zsign", .upToNextMinor(from: "1.2.4")),
|
||||
.package(url: "https://github.com/SuperchargeApp/SuperchargeCore", .upToNextMinor(from: "1.2.0")),
|
||||
.package(url: "https://github.com/SuperchargeApp/SwiftyMobileDevice", .upToNextMinor(from: "1.2.1")),
|
||||
.package(url: "https://github.com/kabiroberai/zsign", .upToNextMinor(from: "1.3.0")),
|
||||
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0"),
|
||||
.package(url: "https://github.com/vapor/websocket-kit.git", from: "2.15.0"),
|
||||
.package(url: "https://github.com/apple/swift-certificates", from: "1.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-crypto", from: "3.9.1"),
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
|
||||
.package(url: "https://github.com/attaswift/BigInt", from: "5.5.0"),
|
||||
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras.git", from: "1.3.0"),
|
||||
],
|
||||
targets: [
|
||||
.systemLibrary(name: "CSupersette"),
|
||||
@@ -51,6 +52,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
"CSupersign",
|
||||
.byName(name: "CSupersette", condition: .when(platforms: [.linux])),
|
||||
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
|
||||
.product(name: "SwiftyMobileDevice", package: "SwiftyMobileDevice"),
|
||||
.product(name: "Zupersign", package: "zsign"),
|
||||
.product(name: "SignerSupport", package: "SuperchargeCore"),
|
||||
@@ -96,7 +98,7 @@ let package = Package(
|
||||
],
|
||||
cSettings: cSettings
|
||||
),
|
||||
.target(
|
||||
.executableTarget(
|
||||
name: "SupersignCLI",
|
||||
dependencies: [
|
||||
"SwiftyMobileDevice",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
inline static FILE *get_stdout() {
|
||||
return stdout;
|
||||
}
|
||||
+3
-3
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesAddAppGroupRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
let applicationGroup: DeveloperServicesAppGroup
|
||||
}
|
||||
public typealias Value = DeveloperServicesAppGroup
|
||||
@@ -29,8 +29,8 @@ public struct DeveloperServicesAddAppGroupRequest: DeveloperServicesPlatformRequ
|
||||
]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.applicationGroup))
|
||||
public func parse(_ response: Response) -> DeveloperServicesAppGroup {
|
||||
response.applicationGroup
|
||||
}
|
||||
|
||||
public init(
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesAppGroup: Decodable {
|
||||
public struct ID: RawRepresentable, Decodable {
|
||||
public struct DeveloperServicesAppGroup: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public struct DeveloperServicesAppGroup: Decodable {
|
||||
|
||||
public let name: String
|
||||
|
||||
public struct GroupID: RawRepresentable, Hashable, Codable {
|
||||
public struct GroupID: RawRepresentable, Hashable, Codable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public class DeveloperServicesAssignAppGroupRequest: DeveloperServicesPlatformRequest {
|
||||
public final class DeveloperServicesAssignAppGroupRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {}
|
||||
public struct Response: Decodable, Sendable {}
|
||||
public typealias Value = Response
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesListAppGroupsRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let applicationGroupList: [DeveloperServicesAppGroup]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesAppGroup]
|
||||
@@ -23,8 +23,8 @@ public struct DeveloperServicesListAppGroupsRequest: DeveloperServicesPlatformRe
|
||||
return ["teamId": teamID.rawValue]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.applicationGroupList))
|
||||
public func parse(_ response: Response) -> [DeveloperServicesAppGroup] {
|
||||
response.applicationGroupList
|
||||
}
|
||||
|
||||
public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesAddAppIDRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
let appId: DeveloperServicesAppID
|
||||
}
|
||||
public typealias Value = DeveloperServicesAppID
|
||||
@@ -41,8 +41,8 @@ public struct DeveloperServicesAddAppIDRequest: DeveloperServicesPlatformRequest
|
||||
return parameters
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.appId))
|
||||
public func parse(_ response: Response) -> DeveloperServicesAppID {
|
||||
response.appId
|
||||
}
|
||||
|
||||
public init(
|
||||
|
||||
@@ -98,7 +98,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
|
||||
var entitlements: Entitlements
|
||||
// if the executable doesn't already have entitlements, that's
|
||||
// okay. We don't have to throw an error.
|
||||
if let entitlementsData = try? context.signerImpl.analyze(executable: executableURL),
|
||||
if let entitlementsData = try? await context.signerImpl.analyze(executable: executableURL),
|
||||
let decodedEntitlements = try? PropertyListDecoder().decode(Entitlements.self, from: entitlementsData) {
|
||||
entitlements = decodedEntitlements
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
import Foundation
|
||||
import ProtoCodable
|
||||
|
||||
public struct DeveloperServicesAppID: Decodable {
|
||||
public struct ID: RawRepresentable, Decodable {
|
||||
public struct DeveloperServicesAppID: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesDeleteAppIDRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {}
|
||||
public struct Response: Decodable, Sendable {}
|
||||
public typealias Value = Response
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesListAppIDsRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let appIds: [DeveloperServicesAppID]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesAppID]
|
||||
@@ -23,8 +23,8 @@ public struct DeveloperServicesListAppIDsRequest: DeveloperServicesPlatformReque
|
||||
return ["teamId": teamID.rawValue]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.appIds))
|
||||
public func parse(_ response: Response) -> [DeveloperServicesAppID] {
|
||||
response.appIds
|
||||
}
|
||||
|
||||
public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesUpdateAppIDRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
let appId: DeveloperServicesAppID
|
||||
}
|
||||
public typealias Value = DeveloperServicesAppID
|
||||
@@ -39,8 +39,8 @@ public struct DeveloperServicesUpdateAppIDRequest: DeveloperServicesPlatformRequ
|
||||
return parameters
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.appId))
|
||||
public func parse(_ response: Response) -> DeveloperServicesAppID {
|
||||
response.appId
|
||||
}
|
||||
|
||||
public init(
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
import Foundation
|
||||
import ProtoCodable
|
||||
|
||||
public protocol DeveloperServicesFeature: ProtoCodable {
|
||||
public protocol DeveloperServicesFeature: ProtoCodable, Sendable {
|
||||
static var identifier: String { get }
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesCSRResponse: Decodable {
|
||||
public struct ID: RawRepresentable, Decodable {
|
||||
public struct DeveloperServicesCSRResponse: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesCertificate: Decodable {
|
||||
public struct ID: RawRepresentable, Decodable {
|
||||
public struct DeveloperServicesCertificate: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
public let id: ID
|
||||
|
||||
public struct SerialNumber: RawRepresentable, Decodable {
|
||||
public struct SerialNumber: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public enum Kind: String, Decodable, CaseIterable {
|
||||
public enum Kind: String, Decodable, CaseIterable, Sendable {
|
||||
case development = "DEVELOPMENT"
|
||||
case distribution = "DISTRIBUTION"
|
||||
case iOSDevelopment = "IOS_DEVELOPMENT"
|
||||
@@ -44,7 +44,7 @@ public struct DeveloperServicesCertificate: Decodable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Attributes: Decodable {
|
||||
public struct Attributes: Decodable, Sendable {
|
||||
public let serialNumber: SerialNumber
|
||||
public let name: String
|
||||
public let kind: Kind
|
||||
|
||||
+2
-2
@@ -29,10 +29,10 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
|
||||
}
|
||||
|
||||
public let context: SigningContext
|
||||
public let confirmRevocation: ([DeveloperServicesCertificate]) async -> Bool
|
||||
public let confirmRevocation: @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
public init(
|
||||
context: SigningContext,
|
||||
confirmRevocation: @escaping ([DeveloperServicesCertificate]) async -> Bool
|
||||
confirmRevocation: @escaping @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
) {
|
||||
self.context = context
|
||||
self.confirmRevocation = confirmRevocation
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesListCertificatesRequest: DeveloperServicesRequest {
|
||||
public struct DeveloperServicesListCertificatesRequest: DeveloperServicesRequest, Sendable {
|
||||
|
||||
public typealias Response = [DeveloperServicesCertificate]
|
||||
public typealias Value = Response
|
||||
|
||||
+4
-4
@@ -8,9 +8,9 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public class DeveloperServicesSubmitCSRRequest: DeveloperServicesPlatformRequest {
|
||||
public final class DeveloperServicesSubmitCSRRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let certRequest: DeveloperServicesCSRResponse
|
||||
}
|
||||
public typealias Value = DeveloperServicesCSRResponse
|
||||
@@ -31,8 +31,8 @@ public class DeveloperServicesSubmitCSRRequest: DeveloperServicesPlatformRequest
|
||||
]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.certRequest))
|
||||
public func parse(_ response: Response) -> DeveloperServicesCSRResponse {
|
||||
response.certRequest
|
||||
}
|
||||
|
||||
public init(
|
||||
|
||||
+4
-4
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesViewDeveloperRequest: DeveloperServicesRequest {
|
||||
|
||||
public struct Developer: Decodable {
|
||||
public struct Developer: Decodable, Sendable {
|
||||
public let email: String
|
||||
|
||||
public let firstName: String
|
||||
@@ -22,7 +22,7 @@ public struct DeveloperServicesViewDeveloperRequest: DeveloperServicesRequest {
|
||||
public let developerStatus: String
|
||||
}
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
let developer: Developer
|
||||
}
|
||||
public typealias Value = Developer
|
||||
@@ -30,8 +30,8 @@ public struct DeveloperServicesViewDeveloperRequest: DeveloperServicesRequest {
|
||||
public var action: String { return "viewDeveloper" }
|
||||
public var parameters: [String: Any] { return [:] }
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.developer))
|
||||
public func parse(_ response: Response) -> Developer {
|
||||
response.developer
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import Superutils
|
||||
|
||||
public protocol DeveloperServicesAPIVersion {
|
||||
public protocol DeveloperServicesAPIVersion: Sendable {
|
||||
func url(forAction action: String) -> URL?
|
||||
var contentType: String { get }
|
||||
var accept: String { get }
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class DeveloperServicesClient {
|
||||
public final class DeveloperServicesClient: Sendable {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case noData
|
||||
@@ -111,9 +111,7 @@ public final class DeveloperServicesClient {
|
||||
|
||||
let decoded: R.Response = try request.apiVersion.decode(response: data)
|
||||
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
request.parse(decoded) { continuation.resume(with: $0) }
|
||||
}
|
||||
return try await request.parse(decoded)
|
||||
}
|
||||
|
||||
public func send<R: DeveloperServicesRequest>(_ request: R) async throws -> R.Value {
|
||||
@@ -121,16 +119,4 @@ public final class DeveloperServicesClient {
|
||||
return try await self.send(request, anisetteData: anisetteData)
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use async overload")
|
||||
public func send<R: DeveloperServicesRequest>(
|
||||
_ request: R,
|
||||
completion: @escaping (Result<R.Value, Swift.Error>) -> Void
|
||||
) {
|
||||
Task {
|
||||
completion(await Result {
|
||||
try await send(request)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesLoginToken: Codable {
|
||||
public struct DeveloperServicesLoginToken: Codable, Sendable {
|
||||
public let adsid: String
|
||||
public let token: String
|
||||
public let expiry: Date
|
||||
@@ -20,7 +20,7 @@ public struct DeveloperServicesLoginToken: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeveloperServicesLoginManager {
|
||||
public struct DeveloperServicesLoginManager: Sendable {
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case missingLoginToken
|
||||
@@ -71,22 +71,4 @@ public struct DeveloperServicesLoginManager {
|
||||
return try await self.logIn(withLoginData: loginData)
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use async overload")
|
||||
public func logIn(
|
||||
withUsername username: String,
|
||||
password: String,
|
||||
twoFactorDelegate: TwoFactorAuthDelegate,
|
||||
completion: @escaping (Result<DeveloperServicesLoginToken, Swift.Error>) -> Void
|
||||
) {
|
||||
Task {
|
||||
completion(await Result {
|
||||
try await logIn(
|
||||
withUsername: username,
|
||||
password: password,
|
||||
twoFactorDelegate: twoFactorDelegate
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol DeveloperServicesOperation {
|
||||
public protocol DeveloperServicesOperation: Sendable {
|
||||
associatedtype Response
|
||||
|
||||
var context: SigningContext { get }
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum DeveloperServicesPlatform: Decodable, Hashable {
|
||||
public enum DeveloperServicesPlatform: Decodable, Hashable, Sendable {
|
||||
private static let known: ([String: DeveloperServicesPlatform], [DeveloperServicesPlatform: String]) = {
|
||||
var first: [String: DeveloperServicesPlatform] = [:]
|
||||
var second: [DeveloperServicesPlatform: String] = [:]
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct ProvisioningInfo {
|
||||
public struct ProvisioningInfo: Sendable {
|
||||
public let newBundleID: String
|
||||
public let entitlements: Entitlements
|
||||
public let mobileprovision: Mobileprovision
|
||||
@@ -23,13 +23,13 @@ public struct DeveloperServicesProvisioningOperation: DeveloperServicesOperation
|
||||
|
||||
public let context: SigningContext
|
||||
public let app: URL
|
||||
public let confirmRevocation: ([DeveloperServicesCertificate]) async -> Bool
|
||||
public let progress: (Double) -> Void
|
||||
public let confirmRevocation: @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
public let progress: @Sendable (Double) -> Void
|
||||
public init(
|
||||
context: SigningContext,
|
||||
app: URL,
|
||||
confirmRevocation: @escaping ([DeveloperServicesCertificate]) async -> Bool,
|
||||
progress: @escaping (Double) -> Void
|
||||
confirmRevocation: @escaping @Sendable ([DeveloperServicesCertificate]) async -> Bool,
|
||||
progress: @escaping @Sendable (Double) -> Void
|
||||
) {
|
||||
self.context = context
|
||||
self.app = app
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct EmptyResponse: Decodable {}
|
||||
public struct EmptyResponse: Decodable, Sendable {}
|
||||
|
||||
public protocol DeveloperServicesRequest {
|
||||
public protocol DeveloperServicesRequest: Sendable {
|
||||
|
||||
associatedtype Response: Decodable
|
||||
associatedtype Value
|
||||
associatedtype Response: Decodable, Sendable
|
||||
associatedtype Value: Sendable
|
||||
|
||||
var apiVersion: DeveloperServicesAPIVersion { get }
|
||||
|
||||
@@ -23,7 +23,7 @@ public protocol DeveloperServicesRequest {
|
||||
|
||||
func configure(urlRequest: inout HTTPRequest)
|
||||
|
||||
func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void)
|
||||
func parse(_ response: Response) async throws -> Value
|
||||
}
|
||||
|
||||
public extension DeveloperServicesRequest {
|
||||
@@ -33,7 +33,7 @@ public extension DeveloperServicesRequest {
|
||||
}
|
||||
|
||||
public extension DeveloperServicesRequest where Response == Value {
|
||||
func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response))
|
||||
func parse(_ response: Response) -> Response {
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesAddDeviceRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
let device: DeveloperServicesDevice
|
||||
}
|
||||
public typealias Value = DeveloperServicesDevice
|
||||
@@ -29,8 +29,8 @@ public struct DeveloperServicesAddDeviceRequest: DeveloperServicesPlatformReques
|
||||
]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.device))
|
||||
public func parse(_ response: Response) -> DeveloperServicesDevice {
|
||||
response.device
|
||||
}
|
||||
|
||||
public init(
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesDevice: Decodable {
|
||||
public struct ID: RawRepresentable, Decodable {
|
||||
public struct DeveloperServicesDevice: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesListDevicesRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let devices: [DeveloperServicesDevice]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesDevice]
|
||||
@@ -27,8 +27,8 @@ public struct DeveloperServicesListDevicesRequest: DeveloperServicesPlatformRequ
|
||||
]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.devices))
|
||||
public func parse(_ response: Response) -> Value {
|
||||
response.devices
|
||||
}
|
||||
|
||||
public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesDeleteProfileRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {}
|
||||
public struct Response: Decodable, Sendable {}
|
||||
public typealias Value = Response
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesGetProfileRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let provisioningProfile: DeveloperServicesProfile
|
||||
}
|
||||
public typealias Value = DeveloperServicesProfile
|
||||
@@ -24,8 +24,8 @@ public struct DeveloperServicesGetProfileRequest: DeveloperServicesPlatformReque
|
||||
return ["teamId": teamID.rawValue, "appIdId": appIDID.rawValue]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.provisioningProfile))
|
||||
public func parse(_ response: Response) -> DeveloperServicesProfile {
|
||||
response.provisioningProfile
|
||||
}
|
||||
|
||||
public init(
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesListProfilesRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let provisioningProfiles: [DeveloperServicesProfile]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesProfile]
|
||||
@@ -23,8 +23,8 @@ public struct DeveloperServicesListProfilesRequest: DeveloperServicesPlatformReq
|
||||
return ["teamId": teamID.rawValue]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {
|
||||
completion(.success(response.provisioningProfiles))
|
||||
public func parse(_ response: Response) -> [DeveloperServicesProfile] {
|
||||
response.provisioningProfiles
|
||||
}
|
||||
|
||||
public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesProfile: Decodable {
|
||||
public struct ID: RawRepresentable, Decodable {
|
||||
public struct DeveloperServicesProfile: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
public struct DeveloperServicesListTeamsRequest: DeveloperServicesRequest {
|
||||
|
||||
public struct Response: Decodable {
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let teams: [DeveloperServicesTeam]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesTeam]
|
||||
@@ -18,10 +18,8 @@ public struct DeveloperServicesListTeamsRequest: DeveloperServicesRequest {
|
||||
public var action: String { return "listTeams" }
|
||||
public var parameters: [String: Any] { return [:] }
|
||||
|
||||
public func parse(
|
||||
_ response: Response, completion: @escaping (Result<[DeveloperServicesTeam], Error>) -> Void
|
||||
) {
|
||||
completion(.success(response.teams))
|
||||
public func parse(_ response: Response) -> [DeveloperServicesTeam] {
|
||||
response.teams
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesTeam: Decodable {
|
||||
public struct ID: RawRepresentable, Decodable {
|
||||
public struct DeveloperServicesTeam: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public struct DeveloperServicesTeam: Decodable {
|
||||
public let status: String
|
||||
public let name: String
|
||||
|
||||
public struct Membership: Decodable {
|
||||
public struct Membership: Decodable, Sendable {
|
||||
public let name: String
|
||||
public let platform: DeveloperServicesPlatform
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import Foundation
|
||||
import Crypto
|
||||
import ConcurrencyExtras
|
||||
|
||||
public protocol RawADIProvider {
|
||||
public protocol RawADIProvider: Sendable {
|
||||
func clientInfo() async throws -> String
|
||||
|
||||
func startProvisioning(
|
||||
@@ -25,7 +26,7 @@ extension RawADIProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public protocol RawADIProvisioningSession {
|
||||
public protocol RawADIProvisioningSession: Sendable {
|
||||
func endProvisioning(
|
||||
routingInfo: UInt64,
|
||||
ptm: Data,
|
||||
@@ -52,7 +53,7 @@ public final class ADIDataProvider: AnisetteDataProvider {
|
||||
private let localUserUID: UUID
|
||||
private let localUserID: String
|
||||
|
||||
private var _clientInfo: String?
|
||||
private let _clientInfo = LockIsolated<String?>(nil)
|
||||
|
||||
public init(
|
||||
rawProvider: RawADIProvider,
|
||||
@@ -127,9 +128,9 @@ public final class ADIDataProvider: AnisetteDataProvider {
|
||||
}()
|
||||
|
||||
private func clientInfo() async throws -> String {
|
||||
if let _clientInfo { return _clientInfo }
|
||||
if let clientInfo = _clientInfo.value { return clientInfo }
|
||||
let clientInfo = try await rawProvider.clientInfo()
|
||||
self._clientInfo = clientInfo
|
||||
_clientInfo.setValue(clientInfo)
|
||||
return clientInfo
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol AnisetteDataProvider {
|
||||
public protocol AnisetteDataProvider: Sendable {
|
||||
// This is a suggestion and not a requirement.
|
||||
func resetProvisioning() async
|
||||
func provisioningData() -> ProvisioningData?
|
||||
@@ -16,7 +16,7 @@ public protocol AnisetteDataProvider {
|
||||
func fetchAnisetteData() async throws -> AnisetteData
|
||||
}
|
||||
|
||||
public struct ProvisioningData: Hashable, Codable {
|
||||
public struct ProvisioningData: Hashable, Codable, Sendable {
|
||||
public var localUserUID: UUID
|
||||
public var routingInfo: UInt64
|
||||
public var adiPb: Data
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeviceInfo: Codable {
|
||||
public struct DeviceInfo: Codable, Sendable {
|
||||
|
||||
/// `X-Xcode-Version`
|
||||
static let xcodeVersionKey = "X-Xcode-Version"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import Foundation
|
||||
import CSupersette
|
||||
|
||||
public struct SupersetteADIProvider: RawADIProvider {
|
||||
public actor SupersetteADIProvider: RawADIProvider {
|
||||
@MainActor private static var loadTask: Task<Void, Error>?
|
||||
|
||||
public let directory: URL
|
||||
@@ -27,14 +27,14 @@ public struct SupersetteADIProvider: RawADIProvider {
|
||||
let applemusic = tmp.appending(path: "applemusic.apk")
|
||||
if !applemusic.exists {
|
||||
print("[Downloading libraries] ...", terminator: "")
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
let url = URL(string: "https://apps.mzstatic.com/content/android-apple-music-apk/applemusic.apk")!
|
||||
defer { print("") }
|
||||
let data = try await httpClient.makeRequest(HTTPRequest(url: url)) { progress in
|
||||
guard let progress else { return }
|
||||
let progString = "\(Int(progress * 100))%".padding(toLength: 4, leading: true)
|
||||
print("\r[Downloading libraries] \(progString)", terminator: "")
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
}.body!
|
||||
try data.write(to: applemusic)
|
||||
}
|
||||
@@ -48,6 +48,7 @@ public struct SupersetteADIProvider: RawADIProvider {
|
||||
#endif
|
||||
let archDir = "lib/\(arch)"
|
||||
|
||||
// TODO: Use ZIPFoundation
|
||||
let proc = Process()
|
||||
proc.executableURL = URL(filePath: "/usr/bin/unzip")
|
||||
proc.arguments = [
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class GrandSlamClient {
|
||||
final class GrandSlamClient: Sendable {
|
||||
|
||||
private let encoder = PropertyListEncoder()
|
||||
|
||||
@@ -52,9 +52,4 @@ class GrandSlamClient {
|
||||
return try R.Decoder.decode(data: resp.body ?? .init())
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use async overload")
|
||||
func send<R: GrandSlamRequest>(_ request: R, completion: @escaping (Result<R.Decoder.Value, Swift.Error>) -> Void) {
|
||||
Task { completion(await Result { try await send(request) }) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ struct GrandSlamEndpoints: Decodable {
|
||||
let midFinishProvisioning: String
|
||||
}
|
||||
|
||||
enum GrandSlamEndpoint {
|
||||
case lookup(KeyPath<GrandSlamEndpoints, String>)
|
||||
enum GrandSlamEndpoint: Sendable {
|
||||
case lookup(KeyPath<GrandSlamEndpoints, String> & Sendable)
|
||||
case url(URL)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class GrandSlamLookupManager {
|
||||
actor GrandSlamLookupManager {
|
||||
|
||||
private static let lookupURL = URL(string: "https://gsa.apple.com/grandslam/GsService2/lookup")!
|
||||
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol TwoFactorAuthDelegate: AnyObject {
|
||||
public protocol TwoFactorAuthDelegate: AnyObject, Sendable {
|
||||
func fetchCode() async -> String?
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ protocol GrandSlamDataDecoder {
|
||||
static func decode(data: Data) throws -> Value
|
||||
}
|
||||
|
||||
protocol GrandSlamRequest {
|
||||
protocol GrandSlamRequest: Sendable {
|
||||
associatedtype Decoder: GrandSlamDataDecoder
|
||||
|
||||
static var endpoint: GrandSlamEndpoint { get }
|
||||
|
||||
@@ -16,7 +16,7 @@ import WebSocketKit
|
||||
|
||||
extension HTTPClient: HTTPClientProtocol {
|
||||
@discardableResult
|
||||
public func makeRequest(_ request: HTTPRequest, onProgress: (Double?) -> Void) async throws -> HTTPResponse {
|
||||
public func makeRequest(_ request: HTTPRequest, onProgress: sending @isolated(any) (Double?) -> Void) async throws -> HTTPResponse {
|
||||
// print("Requesting \(request.url)")
|
||||
var httpRequest = HTTPClientRequest(url: request.url.absoluteString)
|
||||
httpRequest.method = request.method.map(HTTPMethod.init(rawValue:)) ?? .GET
|
||||
@@ -30,13 +30,13 @@ extension HTTPClient: HTTPClientProtocol {
|
||||
let response = try await execute(httpRequest, deadline: .distantFuture)
|
||||
let expectedBytes = response.headers.first(name: "content-length").flatMap(Int.init).map(Double.init)
|
||||
if expectedBytes == nil {
|
||||
onProgress(nil)
|
||||
await onProgress(nil)
|
||||
}
|
||||
var body = Data()
|
||||
for try await chunk in response.body {
|
||||
body += chunk.readableBytesView
|
||||
if let expectedBytes {
|
||||
onProgress(min(Double(body.count) / expectedBytes, 1))
|
||||
await onProgress(min(Double(body.count) / expectedBytes, 1))
|
||||
}
|
||||
}
|
||||
return HTTPResponse(
|
||||
@@ -73,7 +73,7 @@ extension HTTPClient: HTTPClientProtocol {
|
||||
private final class WebSocketSessionWrapper: WebSocketSession {
|
||||
let webSocket: WebSocket
|
||||
let stream: AsyncStream<WebSocketMessage>
|
||||
private let finishStream: () -> Void
|
||||
private let finishStream: @Sendable () -> Void
|
||||
|
||||
init(webSocket: WebSocket) {
|
||||
self.webSocket = webSocket
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct HTTPRequest {
|
||||
public enum Body {
|
||||
public struct HTTPRequest: Sendable {
|
||||
public enum Body: Sendable {
|
||||
case buffer(Data)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public struct HTTPRequest {
|
||||
}
|
||||
}
|
||||
|
||||
public struct HTTPResponse {
|
||||
public struct HTTPResponse: Sendable {
|
||||
public var url: URL
|
||||
public var status: Int
|
||||
public var headers: [String: String]
|
||||
@@ -49,8 +49,11 @@ public struct HTTPResponse {
|
||||
}
|
||||
}
|
||||
|
||||
public protocol HTTPClientProtocol {
|
||||
func makeRequest(_ request: HTTPRequest, onProgress: (Double?) -> Void) async throws -> HTTPResponse
|
||||
public protocol HTTPClientProtocol: Sendable {
|
||||
func makeRequest(
|
||||
_ request: HTTPRequest,
|
||||
onProgress: sending @isolated(any) (Double?) -> Void
|
||||
) async throws -> HTTPResponse
|
||||
func makeWebSocket(url: URL) async throws -> WebSocketSession
|
||||
}
|
||||
|
||||
@@ -60,18 +63,18 @@ extension HTTPClientProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public protocol WebSocketSession {
|
||||
public protocol WebSocketSession: Sendable {
|
||||
func receive() async throws -> WebSocketMessage
|
||||
func send(_ message: WebSocketMessage) async throws
|
||||
func close()
|
||||
}
|
||||
|
||||
public enum WebSocketMessage {
|
||||
public enum WebSocketMessage: Sendable {
|
||||
case text(String)
|
||||
case data(Data)
|
||||
}
|
||||
|
||||
public protocol HTTPClientFactory {
|
||||
public protocol HTTPClientFactory: Sendable {
|
||||
func shutdown() // client is invalidated after this
|
||||
func makeClient() -> HTTPClientProtocol
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#if !os(Linux)
|
||||
import Foundation
|
||||
import ConcurrencyExtras
|
||||
|
||||
public struct UnknownHTTPError: Error {}
|
||||
|
||||
@@ -21,14 +22,16 @@ final class URLHTTPClientFactory: HTTPClientFactory {
|
||||
|
||||
private final class Client: HTTPClientProtocol {
|
||||
final class ClientDelegate: NSObject, URLSessionWebSocketDelegate {
|
||||
var webSocketCallbacks: [URLSessionWebSocketTask: (URLSessionWebSocketTask.CloseCode?) -> Void] = [:]
|
||||
let webSocketCallbacks = LockIsolated<[
|
||||
URLSessionWebSocketTask: @Sendable (URLSessionWebSocketTask.CloseCode?) -> Void
|
||||
]>([:])
|
||||
|
||||
func urlSession(
|
||||
_ session: URLSession,
|
||||
webSocketTask: URLSessionWebSocketTask,
|
||||
didOpenWithProtocol protocol: String?
|
||||
) {
|
||||
webSocketCallbacks.removeValue(forKey: webSocketTask)?(nil)
|
||||
webSocketCallbacks.withValue { $0.removeValue(forKey: webSocketTask) }?(nil)
|
||||
}
|
||||
|
||||
func urlSession(
|
||||
@@ -37,7 +40,7 @@ private final class Client: HTTPClientProtocol {
|
||||
didCloseWith closeCode: URLSessionWebSocketTask.CloseCode,
|
||||
reason: Data?
|
||||
) {
|
||||
webSocketCallbacks.removeValue(forKey: webSocketTask)?(closeCode)
|
||||
webSocketCallbacks.withValue { $0.removeValue(forKey: webSocketTask) }?(closeCode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +56,7 @@ private final class Client: HTTPClientProtocol {
|
||||
|
||||
public func makeRequest(
|
||||
_ request: HTTPRequest,
|
||||
onProgress: @isolated(any) (Double?) -> Void
|
||||
onProgress: sending @isolated(any) (Double?) -> Void
|
||||
) async throws -> HTTPResponse {
|
||||
final class ProgressDelegate: NSObject, URLSessionDataDelegate {
|
||||
private let progressContinuation: AsyncStream<Double>.Continuation
|
||||
@@ -130,9 +133,11 @@ private final class Client: HTTPClientProtocol {
|
||||
public func makeWebSocket(url: URL) async throws -> any WebSocketSession {
|
||||
let task = session.webSocketTask(with: url)
|
||||
let (event, eventContinuation) = AsyncStream<URLSessionWebSocketTask.CloseCode?>.makeStream()
|
||||
clientDelegate.webSocketCallbacks[task] = {
|
||||
eventContinuation.yield($0)
|
||||
eventContinuation.finish()
|
||||
clientDelegate.webSocketCallbacks.withValue {
|
||||
$0[task] = {
|
||||
eventContinuation.yield($0)
|
||||
eventContinuation.finish()
|
||||
}
|
||||
}
|
||||
let code = await event.first { _ in true } ?? nil
|
||||
if let code { throw Errors.webSocketClosed(code) }
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import SwiftyMobileDevice
|
||||
|
||||
public final class AppInstaller {
|
||||
public actor AppInstaller {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case userCancelled
|
||||
@@ -33,7 +33,7 @@ public final class AppInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Stage {
|
||||
public enum Stage: Sendable {
|
||||
case connecting(Double)
|
||||
case uploading(Double)
|
||||
case installing(String, Double?)
|
||||
@@ -80,14 +80,6 @@ public final class AppInstaller {
|
||||
label: "com.kabiroberai.Supersign.install-queue"
|
||||
)
|
||||
|
||||
private var needsCancellation = false
|
||||
// throws `Error.userCancelled` if the user cancelled this operation
|
||||
private func cancelPoint() throws {
|
||||
if needsCancellation {
|
||||
throw Error.userCancelled
|
||||
}
|
||||
}
|
||||
|
||||
public let ipa: URL
|
||||
public let udid: String
|
||||
public let connectionPreferences: Connection.Preferences
|
||||
@@ -102,58 +94,40 @@ public final class AppInstaller {
|
||||
}
|
||||
|
||||
// synchronous
|
||||
private func installSync(progress: @escaping (Stage) -> Void) throws {
|
||||
defer { needsCancellation = false }
|
||||
try cancelPoint()
|
||||
|
||||
let connection = try Connection.connection(
|
||||
public func install(progress: @escaping @Sendable (Stage) -> Void) async throws {
|
||||
let connection = try await Connection.connection(
|
||||
forUDID: udid,
|
||||
preferences: connectionPreferences
|
||||
) {
|
||||
progress(.connecting($0 * 4/6))
|
||||
}
|
||||
|
||||
try cancelPoint()
|
||||
try Task.checkCancellation()
|
||||
|
||||
let uploader = try IPAUploader(connection: connection)
|
||||
let uploader = try await IPAUploader(connection: connection)
|
||||
progress(.connecting(5/6))
|
||||
|
||||
try cancelPoint()
|
||||
try Task.checkCancellation()
|
||||
|
||||
// we need to start the installer quickly because sometimes it fails if we do it after
|
||||
// uploading the ipa to the device
|
||||
let installer = try IPAInstaller(connection: connection)
|
||||
let installer = try await IPAInstaller(connection: connection)
|
||||
progress(.connecting(6/6))
|
||||
|
||||
try cancelPoint()
|
||||
try Task.checkCancellation()
|
||||
|
||||
let uploaded = try uploader.upload(app: ipa) { currentProgress in
|
||||
let uploaded = try await uploader.upload(app: ipa) { currentProgress in
|
||||
progress(.uploading(currentProgress))
|
||||
}
|
||||
defer { uploaded.delete() }
|
||||
|
||||
try cancelPoint()
|
||||
try Task.checkCancellation()
|
||||
|
||||
try installer.install(uploaded: uploaded) { currentProgress in
|
||||
try await installer.install(uploaded: uploaded) { currentProgress in
|
||||
progress(.installing(currentProgress.details, currentProgress.progress))
|
||||
}
|
||||
|
||||
_ = connection
|
||||
}
|
||||
|
||||
public func install(
|
||||
progress: @escaping (Stage) -> Void,
|
||||
completion: @escaping (Result<(), Swift.Error>) -> Void
|
||||
) {
|
||||
installQueue.async {
|
||||
completion(Result {
|
||||
try self.installSync(progress: progress)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public func cancel() {
|
||||
needsCancellation = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,17 +9,18 @@
|
||||
import Foundation
|
||||
import SwiftyMobileDevice
|
||||
|
||||
private class WeakBox<T: AnyObject> {
|
||||
private struct Weak<T: AnyObject> {
|
||||
weak var value: T?
|
||||
init(_ value: T) { self.value = value }
|
||||
}
|
||||
extension Weak: Sendable where T: Sendable {}
|
||||
|
||||
// there is guaranteed to be at most one Connection instance per (udid, preferences)
|
||||
// at any moment, thanks to Connection.connection(...). Consequently
|
||||
// there is at most one device per (udid, preferences) at any moment too.
|
||||
public class Connection {
|
||||
// at any moment, thanks to the object pool. Consequently there is at most one device
|
||||
// per (udid, preferences) at any moment too.
|
||||
public actor Connection {
|
||||
|
||||
public enum LookupHandler: Hashable {
|
||||
public enum LookupHandler: Hashable, Sendable {
|
||||
case system(LookupMode)
|
||||
case custom(any ConnectionLookupHandler)
|
||||
|
||||
@@ -46,7 +47,7 @@ public class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Preferences: Hashable {
|
||||
public struct Preferences: Hashable, Sendable {
|
||||
public var lookupHandler: LookupHandler
|
||||
|
||||
public init(lookupMode: LookupMode) {
|
||||
@@ -68,9 +69,7 @@ public class Connection {
|
||||
}
|
||||
|
||||
private static let label = "supersign"
|
||||
|
||||
private static var connections: [ConnectionDescriptor: WeakBox<Connection>] = [:]
|
||||
private static let connectionsQueue = DispatchQueue(label: "connections-queue")
|
||||
private static let pool = WeakPool<ConnectionDescriptor, Connection, Error>()
|
||||
|
||||
private var handle: AnyObject?
|
||||
private let heartbeatHandler: HeartbeatHandler
|
||||
@@ -83,7 +82,7 @@ public class Connection {
|
||||
udid: String,
|
||||
preferences: Preferences,
|
||||
progress: (Double) -> Void
|
||||
) throws {
|
||||
) async throws {
|
||||
progress(0/4)
|
||||
|
||||
self.preferences = preferences
|
||||
@@ -111,22 +110,14 @@ public class Connection {
|
||||
public static func connection(
|
||||
forUDID udid: String,
|
||||
preferences: Preferences,
|
||||
progress: (Double) -> Void
|
||||
) throws -> Connection {
|
||||
let descriptor = ConnectionDescriptor(udid: udid, preferences: preferences)
|
||||
return try connectionsQueue.sync {
|
||||
progress(0)
|
||||
if let conn = connections[descriptor]?.value {
|
||||
progress(1)
|
||||
return conn
|
||||
}
|
||||
let conn = try Connection(
|
||||
udid: udid,
|
||||
preferences: preferences,
|
||||
progress: progress
|
||||
)
|
||||
connections[descriptor] = WeakBox(conn)
|
||||
return conn
|
||||
progress: @escaping @Sendable (Double) -> Void
|
||||
) async throws -> Connection {
|
||||
progress(0)
|
||||
defer { progress(1) }
|
||||
return try await Self.pool.value(
|
||||
key: ConnectionDescriptor(udid: udid, preferences: preferences)
|
||||
) {
|
||||
try await Connection(udid: udid, preferences: preferences, progress: progress)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +135,44 @@ public class Connection {
|
||||
|
||||
}
|
||||
|
||||
public protocol ConnectionLookupHandler: Hashable {
|
||||
private actor WeakPool<Key: Hashable, Value: AnyObject & Sendable, Failure: Error> {
|
||||
init() {}
|
||||
|
||||
private var pendingValues: [Key: Task<Result<Value, Failure>, Never>] = [:]
|
||||
private var existingValues: [Key: Weak<Value>] = [:]
|
||||
|
||||
func value(
|
||||
key: Key,
|
||||
create: @escaping @Sendable () async throws(Failure) -> Value
|
||||
) async throws(Failure) -> Value {
|
||||
if let pending = pendingValues[key] {
|
||||
return try await pending.value.get()
|
||||
}
|
||||
|
||||
if let existing = existingValues[key] {
|
||||
if let existingValue = existing.value {
|
||||
return existingValue
|
||||
} else {
|
||||
existingValues[key] = nil
|
||||
}
|
||||
}
|
||||
|
||||
let task = Task { () -> Result<Value, Failure> in
|
||||
do throws(Failure) {
|
||||
let connection = try await create()
|
||||
existingValues[key] = Weak(connection)
|
||||
pendingValues[key] = nil
|
||||
return .success(connection)
|
||||
} catch {
|
||||
return .failure(error)
|
||||
}
|
||||
}
|
||||
pendingValues[key] = task
|
||||
|
||||
return try await task.value.get()
|
||||
}
|
||||
}
|
||||
|
||||
public protocol ConnectionLookupHandler: Hashable, Sendable {
|
||||
func createHandle() throws -> AnyObject
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
import Foundation
|
||||
import SwiftyMobileDevice
|
||||
|
||||
public final class Debugger {
|
||||
public actor Debugger {
|
||||
|
||||
private let client: DebugserverClient
|
||||
public init(connection: Connection) throws {
|
||||
client = try connection.startClient()
|
||||
public init(connection: Connection) async throws {
|
||||
client = try await connection.startClient()
|
||||
try client.send(command: "QSetMaxPacketSize:", arguments: ["1024"])
|
||||
}
|
||||
|
||||
@@ -23,21 +23,13 @@ public final class Debugger {
|
||||
|
||||
// if the receiver is released before the completion handler is called, the
|
||||
// method will fail with `Debugger.Error.userCancelled`
|
||||
public func attach(toProcess process: String, completion: @escaping (Result<(), Swift.Error>) -> Void) {
|
||||
let queue = DispatchQueue(label: "debugger-attach-queue")
|
||||
queue.async { [weak self] in
|
||||
completion(Result {
|
||||
var retainedSelf: Debugger?
|
||||
var resp: Data
|
||||
repeat {
|
||||
retainedSelf = nil
|
||||
guard let self = self else { throw Error.userCancelled }
|
||||
retainedSelf = self
|
||||
resp = try self.client.send(command: "vAttachWait;", arguments: [process])
|
||||
} while resp.isEmpty
|
||||
try retainedSelf!.client.send(command: "D", arguments: [])
|
||||
})
|
||||
}
|
||||
public func attach(toProcess process: String) async throws {
|
||||
var resp: Data
|
||||
repeat {
|
||||
try Task.checkCancellation()
|
||||
resp = try self.client.send(command: "vAttachWait;", arguments: [process])
|
||||
} while resp.isEmpty
|
||||
try self.client.send(command: "D", arguments: [])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
import Foundation
|
||||
import SwiftyMobileDevice
|
||||
import ConcurrencyExtras
|
||||
|
||||
public final class HeartbeatHandler {
|
||||
public final class HeartbeatHandler: Sendable {
|
||||
private struct Error: Swift.Error {}
|
||||
|
||||
private struct ReceivedPacket: Decodable {
|
||||
@@ -49,8 +50,7 @@ public final class HeartbeatHandler {
|
||||
private let heartbeatQueue = DispatchQueue(
|
||||
label: "com.kabiroberai.Supersign.heartbeat-queue"
|
||||
)
|
||||
private let stopLock = NSLock()
|
||||
private var isStopped = false
|
||||
private let isStopped = LockIsolated(false)
|
||||
|
||||
private let device: Device
|
||||
private let client: LockdownClient
|
||||
@@ -99,9 +99,7 @@ public final class HeartbeatHandler {
|
||||
guard let self = self else { break }
|
||||
|
||||
do {
|
||||
self.stopLock.lock()
|
||||
defer { self.stopLock.unlock() }
|
||||
guard !self.isStopped else { break }
|
||||
guard !self.isStopped.value else { break }
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -121,8 +119,6 @@ public final class HeartbeatHandler {
|
||||
}
|
||||
|
||||
public func stop() {
|
||||
stopLock.lock()
|
||||
defer { stopLock.unlock() }
|
||||
isStopped = true
|
||||
self.isStopped.setValue(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,30 +9,21 @@
|
||||
import Foundation
|
||||
import SwiftyMobileDevice
|
||||
|
||||
public final class IPAInstaller {
|
||||
public final class IPAInstaller: Sendable {
|
||||
|
||||
private let client: InstallationProxyClient
|
||||
public init(connection: Connection) throws {
|
||||
self.client = try connection.startClient()
|
||||
public init(connection: Connection) async throws {
|
||||
self.client = try await connection.startClient()
|
||||
}
|
||||
|
||||
public func install(
|
||||
uploaded: IPAUploader.UploadedIPA,
|
||||
progress: @escaping (InstallationProxyClient.RequestProgress) -> Void
|
||||
) throws {
|
||||
var result: Result<(), Error>?
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
client.install(
|
||||
progress: @escaping @Sendable (InstallationProxyClient.RequestProgress) -> Void
|
||||
) async throws {
|
||||
try await client.install(
|
||||
package: uploaded.location,
|
||||
progress: progress,
|
||||
completion: { res in
|
||||
defer { semaphore.signal() }
|
||||
result = res
|
||||
}
|
||||
progress: progress
|
||||
)
|
||||
semaphore.wait()
|
||||
|
||||
try result!.get()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import SwiftyMobileDevice
|
||||
|
||||
public final class IPAUploader {
|
||||
public final class IPAUploader: Sendable {
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case unexpectedSymlink(at: URL)
|
||||
@@ -18,7 +18,7 @@ public final class IPAUploader {
|
||||
private static let packagePath = URL(fileURLWithPath: "PublicStaging")
|
||||
private static let bufferSize = 1 << 20 // 1 MB
|
||||
|
||||
public class UploadedIPA {
|
||||
public final class UploadedIPA: Sendable {
|
||||
public let uploader: IPAUploader
|
||||
let location: URL
|
||||
fileprivate init(uploader: IPAUploader, location: URL) {
|
||||
@@ -26,21 +26,19 @@ public final class IPAUploader {
|
||||
self.location = location
|
||||
}
|
||||
|
||||
public private(set) var isDeleted: Bool = false
|
||||
|
||||
deinit { delete() }
|
||||
|
||||
public func delete() {
|
||||
guard !isDeleted else { return }
|
||||
try? uploader.client.removeItemAndContents(at: location)
|
||||
}
|
||||
}
|
||||
|
||||
private let client: AFCClient
|
||||
public init(connection: Connection) throws {
|
||||
self.client = try connection.startClient()
|
||||
public init(connection: Connection) async throws {
|
||||
self.client = try await connection.startClient()
|
||||
}
|
||||
|
||||
private func upload(_ src: URL, to dest: URL, progress: (Double) -> Void) throws {
|
||||
private func upload(_ src: URL, to dest: URL, progress: (Double) -> Void) async throws {
|
||||
let srcData = try Data(contentsOf: src)
|
||||
let size = srcData.count
|
||||
let sizeDouble = Double(size)
|
||||
@@ -50,6 +48,10 @@ public final class IPAUploader {
|
||||
|
||||
var totalWritten = 0
|
||||
while totalWritten != size {
|
||||
if totalWritten != 0 {
|
||||
await Task.yield()
|
||||
try Task.checkCancellation()
|
||||
}
|
||||
let buf = srcData.dropFirst(totalWritten).prefix(bufferSize)
|
||||
let bufSize = buf.count
|
||||
var bufWritten = 0
|
||||
@@ -63,7 +65,7 @@ public final class IPAUploader {
|
||||
}
|
||||
}
|
||||
|
||||
public func upload(app: URL, progress: (Double) -> Void) throws -> UploadedIPA {
|
||||
public func upload(app: URL, progress: (Double) -> Void) async throws -> UploadedIPA {
|
||||
if try !client.fileExists(at: Self.packagePath) {
|
||||
try client.createDirectory(at: Self.packagePath)
|
||||
}
|
||||
@@ -73,7 +75,7 @@ public final class IPAUploader {
|
||||
try client.removeItemAndContents(at: dest)
|
||||
}
|
||||
|
||||
try upload(app, to: dest, progress: progress)
|
||||
try await upload(app, to: dest, progress: progress)
|
||||
|
||||
return UploadedIPA(uploader: self, location: dest)
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ public final class ProfileManager {
|
||||
return minor >= 3
|
||||
}()
|
||||
|
||||
public init(connection: Connection) throws {
|
||||
self.client = try connection.startClient()
|
||||
public init(connection: Connection) async throws {
|
||||
self.client = try await connection.startClient()
|
||||
self.version = try connection.client.value(ofType: String.self, forDomain: nil, key: "ProductVersion")
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,13 @@ extension LockdownClient {
|
||||
|
||||
#if !os(iOS)
|
||||
|
||||
public protocol IntegratedInstallerDelegate: AnyObject {
|
||||
public protocol IntegratedInstallerDelegate: AnyObject, Sendable {
|
||||
|
||||
func fetchCode() async -> String?
|
||||
func fetchTeam(fromTeams teams: [DeveloperServicesTeam], completion: @escaping (DeveloperServicesTeam?) -> Void)
|
||||
func fetchTeam(fromTeams teams: [DeveloperServicesTeam]) async -> DeveloperServicesTeam?
|
||||
|
||||
func setPresentedMessage(_ message: IntegratedInstaller.Message?)
|
||||
func installerDidUpdate(toStage stage: String, progress: Double?)
|
||||
func installerDidComplete(withResult result: Result<String, Error>)
|
||||
|
||||
// defaults to always returning true
|
||||
func confirmRevocation(of certificates: [DeveloperServicesCertificate]) async -> Bool
|
||||
@@ -32,14 +32,11 @@ public protocol IntegratedInstallerDelegate: AnyObject {
|
||||
/// - Parameter directory: The directory into which `ipa` should be decompressed.
|
||||
/// - Parameter progress: A closure to which the callee can provide progress updates.
|
||||
/// - Parameter currentProgress: The current progress, or `nil` to indicate it is indeterminate.
|
||||
/// - Parameter completion: A completion handler to call once decompression is finished.
|
||||
/// - Parameter success: Whether or not extraction was successful.
|
||||
func decompress(
|
||||
ipa: URL,
|
||||
in directory: URL,
|
||||
progress: @escaping (_ currentProgress: Double?) -> Void,
|
||||
completion: @escaping (_ success: Bool) -> Void
|
||||
)
|
||||
progress: @escaping @Sendable (_ currentProgress: Double?) -> Void
|
||||
) async throws
|
||||
|
||||
// `compress` is required because the only way to upload symlinks via afc is by
|
||||
// putting them in a zip archive (afc_make_symlink was disabled due to security or
|
||||
@@ -50,14 +47,10 @@ public protocol IntegratedInstallerDelegate: AnyObject {
|
||||
/// - Parameter payloadDir: The `Payload` directory which is to be compressed.
|
||||
/// - Parameter progress: A closure to which the callee can provide progress updates.
|
||||
/// - Parameter currentProgress: The current progress, or `nil` to indicate it is indeterminate.
|
||||
/// - Parameter completion: A completion handler to call with the compressed file's URL.
|
||||
/// - Parameter result: A result with the URL of the compressed file. The caller is responsible
|
||||
/// for cleaning this up once installation is complete.
|
||||
func compress(
|
||||
payloadDir: URL,
|
||||
progress: @escaping (_ currentProgress: Double?) -> Void,
|
||||
completion: @escaping (_ result: Result<URL, Error>) -> Void
|
||||
)
|
||||
progress: @escaping @Sendable (_ currentProgress: Double?) -> Void
|
||||
) async throws -> URL
|
||||
|
||||
}
|
||||
|
||||
@@ -67,13 +60,12 @@ extension IntegratedInstallerDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public final class IntegratedInstaller {
|
||||
public actor IntegratedInstaller {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case alreadyInstalling
|
||||
case deviceInfoFetchFailed
|
||||
case noTeamFound
|
||||
case userCancelled
|
||||
case appExtractionFailed
|
||||
case appCorrupted
|
||||
case appPackagingFailed
|
||||
@@ -89,7 +81,7 @@ public final class IntegratedInstaller {
|
||||
case unlockDevice
|
||||
}
|
||||
|
||||
public enum Credentials {
|
||||
public enum Credentials: Sendable {
|
||||
case password(String)
|
||||
case token(DeveloperServicesLoginToken)
|
||||
}
|
||||
@@ -106,56 +98,51 @@ public final class IntegratedInstaller {
|
||||
|
||||
private let tempDir = FileManager.default.temporaryDirectoryShim
|
||||
.appendingPathComponent("com.kabiroberai.Supercharge-Installer.Staging")
|
||||
private let installQueue =
|
||||
DispatchQueue(label: "com.kabiroberai.Supercharge-Installer.install-queue", qos: .userInitiated, attributes: [])
|
||||
|
||||
private enum ExecutionState {
|
||||
case running
|
||||
case complete
|
||||
}
|
||||
|
||||
private var executionStateLock = NSLock()
|
||||
private var executionState: ExecutionState = .running
|
||||
|
||||
private func shouldContinue() -> Bool {
|
||||
executionStateLock.lock()
|
||||
defer { executionStateLock.unlock() }
|
||||
switch executionState {
|
||||
case .running:
|
||||
return true
|
||||
case .complete:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private func completion(_ result: Result<String, Swift.Error>) {
|
||||
executionStateLock.lock()
|
||||
defer { executionStateLock.unlock() }
|
||||
guard executionState != .complete else { return }
|
||||
try? FileManager.default.removeItem(at: tempDir)
|
||||
executionState = .complete
|
||||
delegate?.installerDidComplete(withResult: result)
|
||||
delegate = nil
|
||||
}
|
||||
|
||||
public func cancel() {
|
||||
completion(.failure(Error.userCancelled))
|
||||
}
|
||||
|
||||
private var stage: String?
|
||||
private func updateStage(to stage: String, initialProgress: Double? = 0, ignoreCancellation: Bool = false) -> Bool {
|
||||
guard ignoreCancellation || shouldContinue(), self.stage != stage else { return false }
|
||||
|
||||
private func updateStage(
|
||||
to stage: String,
|
||||
initialProgress: Double? = 0
|
||||
) async throws {
|
||||
await Task.yield()
|
||||
try Task.checkCancellation()
|
||||
updateStageIgnoringCancellation(to: stage, initialProgress: initialProgress)
|
||||
}
|
||||
|
||||
private func updateStage(
|
||||
to stage: String,
|
||||
initialProgress: Double? = 0
|
||||
) throws {
|
||||
try Task.checkCancellation()
|
||||
updateStageIgnoringCancellation(to: stage, initialProgress: initialProgress)
|
||||
}
|
||||
|
||||
private func updateStageIgnoringCancellation(
|
||||
to stage: String,
|
||||
initialProgress: Double? = 0
|
||||
) {
|
||||
guard self.stage != stage else { return }
|
||||
self.stage = stage
|
||||
delegate?.installerDidUpdate(toStage: stage, progress: initialProgress)
|
||||
return true
|
||||
}
|
||||
private func updateProgress(to progress: Double?, ignoreCancellation: Bool = false) -> Bool {
|
||||
guard ignoreCancellation || shouldContinue() else { return false }
|
||||
|
||||
private func updateProgress(to progress: Double?) async throws {
|
||||
await Task.yield()
|
||||
try Task.checkCancellation()
|
||||
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")
|
||||
}
|
||||
delegate?.installerDidUpdate(toStage: stage, progress: progress)
|
||||
return true
|
||||
}
|
||||
|
||||
public init(
|
||||
@@ -176,7 +163,10 @@ public final class IntegratedInstaller {
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
private func performWithRecovery<T>(repeatAfter: TimeInterval = 0.1, block: () throws -> T) throws -> T {
|
||||
private func performWithRecovery<T>(
|
||||
repeatAfter: TimeInterval = 0.1,
|
||||
block: () async throws -> sending T
|
||||
) async throws -> sending T {
|
||||
var currMessage: Message?
|
||||
|
||||
defer {
|
||||
@@ -186,10 +176,9 @@ public final class IntegratedInstaller {
|
||||
}
|
||||
|
||||
while true {
|
||||
guard shouldContinue() else { throw Error.userCancelled }
|
||||
let nextMessage: Message
|
||||
do {
|
||||
return try block()
|
||||
return try await block()
|
||||
} catch let error as LockdownClient.Error where error == .pairingDialogResponsePending {
|
||||
nextMessage = .pairDevice
|
||||
} catch let error as LockdownClient.Error where error == .passwordProtected {
|
||||
@@ -199,24 +188,22 @@ public final class IntegratedInstaller {
|
||||
delegate?.setPresentedMessage(nextMessage)
|
||||
currMessage = nextMessage
|
||||
}
|
||||
if repeatAfter > 0 {
|
||||
Thread.sleep(forTimeInterval: repeatAfter)
|
||||
}
|
||||
try await Task.sleep(nanoseconds: UInt64(repeatAfter * 1_000_000_000))
|
||||
}
|
||||
}
|
||||
|
||||
// returns nil for pairingKeys if !configureDevice
|
||||
// returns nil overall if cancelled
|
||||
private func prepareDevice() throws -> (deviceName: String, pairingKeys: Data?)? {
|
||||
private func prepareDevice() async throws -> (deviceName: String, pairingKeys: Data?) {
|
||||
// TODO: Maybe use `Connection` here instead of creating the lockdown
|
||||
// client manually?
|
||||
|
||||
let device = try Device(udid: udid, lookupMode: lookupMode)
|
||||
|
||||
guard updateProgress(to: 1/3) else { return nil }
|
||||
try await updateProgress(to: 1/3)
|
||||
|
||||
// we can't reuse any previously created client because we need to perform a handshake this time
|
||||
let lockdownClient = try performWithRecovery {
|
||||
let lockdownClient = try await performWithRecovery {
|
||||
try LockdownClient(
|
||||
device: device,
|
||||
label: LockdownClient.installerLabel,
|
||||
@@ -227,14 +214,14 @@ public final class IntegratedInstaller {
|
||||
let deviceName = try lockdownClient.deviceName()
|
||||
|
||||
if !configureDevice {
|
||||
guard updateProgress(to: 1) else { return nil }
|
||||
try await updateProgress(to: 1)
|
||||
return (deviceName, nil)
|
||||
}
|
||||
|
||||
try lockdownClient.setValue(udid, forDomain: "com.apple.mobile.wireless_lockdown", key: "WirelessBuddyID")
|
||||
try lockdownClient.setValue(true, forDomain: "com.apple.mobile.wireless_lockdown", key: "EnableWifiConnections")
|
||||
|
||||
guard updateProgress(to: 2/3) else { return nil }
|
||||
try await updateProgress(to: 2/3)
|
||||
|
||||
// now create a new pair record based off the existing one, but replacing the
|
||||
// SystemBUID and HostID. This is necessary because if two machines with the
|
||||
@@ -273,7 +260,7 @@ public final class IntegratedInstaller {
|
||||
hostID: hostID,
|
||||
systemBUID: newSystemBUID
|
||||
)
|
||||
try performWithRecovery {
|
||||
try await performWithRecovery {
|
||||
try lockdownClient.pair(withRecord: record)
|
||||
}
|
||||
|
||||
@@ -281,7 +268,7 @@ public final class IntegratedInstaller {
|
||||
fromPropertyList: plist, format: plistFormat, options: 0
|
||||
)
|
||||
|
||||
guard updateProgress(to: 1) else { return nil }
|
||||
try await updateProgress(to: 1)
|
||||
|
||||
return (deviceName, data)
|
||||
}
|
||||
@@ -293,19 +280,19 @@ public final class IntegratedInstaller {
|
||||
team: DeveloperServicesTeam,
|
||||
ipa: URL,
|
||||
bundleID: String
|
||||
) {
|
||||
guard shouldContinue() else { return }
|
||||
executionStateLock.lock()
|
||||
defer { executionStateLock.unlock() }
|
||||
) async throws -> String {
|
||||
try Task.checkCancellation()
|
||||
let appInstaller = AppInstaller(ipa: ipa, udid: udid, connectionPreferences: .init(lookupMode: lookupMode))
|
||||
self.appInstaller = appInstaller
|
||||
appInstaller.install(
|
||||
try await appInstaller.install(
|
||||
progress: { stage in
|
||||
_ = self.updateStage(to: stage.displayName, ignoreCancellation: true)
|
||||
_ = self.updateProgress(to: stage.displayProgress, ignoreCancellation: true)
|
||||
},
|
||||
completion: { self.completion($0.map { bundleID }) }
|
||||
Task {
|
||||
await self.updateStageIgnoringCancellation(to: stage.displayName)
|
||||
await self.updateProgressIgnoringCancellation(to: stage.displayProgress)
|
||||
}
|
||||
}
|
||||
)
|
||||
return bundleID
|
||||
}
|
||||
|
||||
private func packageAndInstall(
|
||||
@@ -315,30 +302,28 @@ public final class IntegratedInstaller {
|
||||
team: DeveloperServicesTeam,
|
||||
appDir: URL,
|
||||
bundleID: String
|
||||
) {
|
||||
guard self.updateStage(to: "Packaging", initialProgress: nil)
|
||||
else { return }
|
||||
) async throws -> String {
|
||||
try await self.updateStage(to: "Packaging", initialProgress: nil)
|
||||
|
||||
delegate?.compress(
|
||||
let ipa = try await delegate?.compress(
|
||||
payloadDir: appDir.deletingLastPathComponent(),
|
||||
progress: { progress in
|
||||
_ = self.updateProgress(to: progress, ignoreCancellation: true)
|
||||
},
|
||||
completion: { result in
|
||||
guard self.updateProgress(to: 1) else { return self.completion(.failure(Error.userCancelled)) }
|
||||
guard let ipa = result.get(withErrorHandler: self.completion) else { return }
|
||||
self.installQueue.async {
|
||||
self.install(
|
||||
deviceInfo: deviceInfo,
|
||||
token: token,
|
||||
client: client,
|
||||
team: team,
|
||||
ipa: ipa,
|
||||
bundleID: bundleID
|
||||
)
|
||||
Task {
|
||||
await self.updateProgressIgnoringCancellation(to: progress)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
try await self.updateProgress(to: 1)
|
||||
|
||||
return try await self.install(
|
||||
deviceInfo: deviceInfo,
|
||||
token: token,
|
||||
client: client,
|
||||
team: team,
|
||||
ipa: ipa!,
|
||||
bundleID: bundleID
|
||||
)
|
||||
}
|
||||
|
||||
private func install(
|
||||
@@ -348,46 +333,36 @@ public final class IntegratedInstaller {
|
||||
client: DeveloperServicesClient,
|
||||
team: DeveloperServicesTeam,
|
||||
appDir: URL
|
||||
) {
|
||||
guard self.updateStage(to: "Preparing device") else { return }
|
||||
) async throws -> String {
|
||||
try await self.updateStage(to: "Preparing device")
|
||||
|
||||
let deviceName: String
|
||||
let pairingKeys: Data?
|
||||
let (deviceName, pairingKeys) = try await prepareDevice()
|
||||
|
||||
do {
|
||||
guard let prepareResult = try prepareDevice()
|
||||
else { return } // nil: user cancelled
|
||||
(deviceName, pairingKeys) = prepareResult
|
||||
} catch {
|
||||
return completion(.failure(error))
|
||||
}
|
||||
let context = try SigningContext(
|
||||
udid: udid,
|
||||
deviceName: deviceName,
|
||||
teamID: team.id,
|
||||
client: client,
|
||||
signingInfoManager: KeyValueSigningInfoManager(storage: storage),
|
||||
platform: .iOS
|
||||
)
|
||||
|
||||
let context: SigningContext
|
||||
do {
|
||||
context = try SigningContext(
|
||||
udid: udid,
|
||||
deviceName: deviceName,
|
||||
teamID: team.id,
|
||||
client: client,
|
||||
signingInfoManager: KeyValueSigningInfoManager(storage: storage),
|
||||
platform: .iOS
|
||||
)
|
||||
} catch {
|
||||
return completion(.failure(error))
|
||||
}
|
||||
let signer = Signer(context: context) { certs in
|
||||
guard let delegate = self.delegate else { return false }
|
||||
return await delegate.confirmRevocation(of: certs)
|
||||
await self.delegate?.confirmRevocation(of: certs) ?? false
|
||||
}
|
||||
signer.sign(
|
||||
let bundleID = try await signer.sign(
|
||||
app: appDir,
|
||||
status: { status in
|
||||
_ = self.updateStage(to: status, ignoreCancellation: true)
|
||||
status: { @Sendable status in
|
||||
Task {
|
||||
await self.updateStageIgnoringCancellation(to: status)
|
||||
}
|
||||
},
|
||||
progress: { progress in
|
||||
_ = self.updateProgress(to: progress, ignoreCancellation: true)
|
||||
Task {
|
||||
_ = await self.updateProgressIgnoringCancellation(to: progress)
|
||||
}
|
||||
},
|
||||
didProvision: {
|
||||
didProvision: { @Sendable in
|
||||
if let pairingKeys = pairingKeys {
|
||||
let info = try context.signingInfoManager.info(forTeamID: context.teamID)
|
||||
try Superconfig(
|
||||
@@ -401,19 +376,16 @@ public final class IntegratedInstaller {
|
||||
token: token
|
||||
).save(inAppDir: appDir)
|
||||
}
|
||||
},
|
||||
completion: { result in
|
||||
guard let bundleID = result.get(withErrorHandler: self.completion) else { return }
|
||||
self.packageAndInstall(
|
||||
deviceInfo: deviceInfo,
|
||||
token: token,
|
||||
client: client,
|
||||
team: team,
|
||||
appDir: appDir,
|
||||
bundleID: bundleID
|
||||
)
|
||||
}
|
||||
)
|
||||
return try await self.packageAndInstall(
|
||||
deviceInfo: deviceInfo,
|
||||
token: token,
|
||||
client: client,
|
||||
team: team,
|
||||
appDir: appDir,
|
||||
bundleID: bundleID
|
||||
)
|
||||
}
|
||||
|
||||
private func install(
|
||||
@@ -422,126 +394,105 @@ public final class IntegratedInstaller {
|
||||
token: DeveloperServicesLoginToken,
|
||||
anisetteProvider: AnisetteDataProvider,
|
||||
appDir: URL
|
||||
) {
|
||||
) async throws -> String {
|
||||
let client = DeveloperServicesClient(
|
||||
loginToken: token,
|
||||
deviceInfo: deviceInfo,
|
||||
anisetteProvider: anisetteProvider
|
||||
)
|
||||
client.send(DeveloperServicesListTeamsRequest()) { result in
|
||||
guard let teams = result.get(withErrorHandler: self.completion) else { return }
|
||||
guard self.updateProgress(to: 1) else { return }
|
||||
switch teams.count {
|
||||
case 0:
|
||||
return self.completion(.failure(Error.noTeamFound))
|
||||
case 1:
|
||||
self.install(deviceInfo: deviceInfo, provisioningData: provisioningData, token: token, client: client, team: teams[0], appDir: appDir)
|
||||
default:
|
||||
self.delegate?.fetchTeam(fromTeams: teams) { team in
|
||||
self.installQueue.async {
|
||||
guard let team = team else { return self.completion(.failure(Error.userCancelled)) }
|
||||
self.install(deviceInfo: deviceInfo, provisioningData: provisioningData, token: token, client: client, team: team, appDir: appDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
let teams = try await client.send(DeveloperServicesListTeamsRequest())
|
||||
try await self.updateProgress(to: 1)
|
||||
let team: DeveloperServicesTeam
|
||||
switch teams.count {
|
||||
case 0:
|
||||
throw Error.noTeamFound
|
||||
case 1:
|
||||
team = teams[0]
|
||||
default:
|
||||
guard let selectedTeam = await self.delegate?.fetchTeam(fromTeams: teams)
|
||||
else { throw CancellationError() }
|
||||
team = selectedTeam
|
||||
}
|
||||
return try await self.install(
|
||||
deviceInfo: deviceInfo,
|
||||
provisioningData: provisioningData,
|
||||
token: token,
|
||||
client: client,
|
||||
team: team,
|
||||
appDir: appDir
|
||||
)
|
||||
}
|
||||
|
||||
private func install(decompressionDidSucceed: Bool) {
|
||||
private func installAfterDecompression() async throws -> String {
|
||||
let payload = self.tempDir.appendingPathComponent("Payload")
|
||||
guard decompressionDidSucceed,
|
||||
let appDir = payload.implicitContents.first(where: { $0.pathExtension == "app" })
|
||||
else { return self.completion(.failure(Error.appExtractionFailed)) }
|
||||
guard let appDir = payload.implicitContents.first(where: { $0.pathExtension == "app" })
|
||||
else { throw Error.appExtractionFailed }
|
||||
|
||||
guard let deviceInfo = DeviceInfo.current() else {
|
||||
return completion(.failure(Error.deviceInfoFetchFailed))
|
||||
throw Error.deviceInfoFetchFailed
|
||||
}
|
||||
|
||||
guard updateStage(to: "Logging in") else { return }
|
||||
try await updateStage(to: "Logging in")
|
||||
|
||||
do {
|
||||
let anisetteProvider = try ADIDataProvider.adiProvider(deviceInfo: deviceInfo, storage: storage)
|
||||
switch credentials {
|
||||
case .password(let password):
|
||||
try DeveloperServicesLoginManager(
|
||||
deviceInfo: deviceInfo,
|
||||
anisetteProvider: anisetteProvider
|
||||
).logIn(
|
||||
withUsername: self.appleID,
|
||||
password: password,
|
||||
twoFactorDelegate: self
|
||||
) { result in
|
||||
guard let token = result.get(withErrorHandler: self.completion) else { return }
|
||||
guard self.updateProgress(to: 1/2) else { return }
|
||||
self.install(
|
||||
deviceInfo: deviceInfo,
|
||||
provisioningData: anisetteProvider.provisioningData(),
|
||||
token: token,
|
||||
anisetteProvider: anisetteProvider,
|
||||
appDir: appDir
|
||||
)
|
||||
}
|
||||
case .token(let token):
|
||||
self.install(
|
||||
deviceInfo: deviceInfo,
|
||||
provisioningData: anisetteProvider.provisioningData(),
|
||||
token: token,
|
||||
anisetteProvider: anisetteProvider,
|
||||
appDir: appDir
|
||||
)
|
||||
}
|
||||
} catch {
|
||||
return completion(.failure(error))
|
||||
let anisetteProvider = try ADIDataProvider.adiProvider(deviceInfo: deviceInfo, storage: storage)
|
||||
let token: DeveloperServicesLoginToken
|
||||
switch credentials {
|
||||
case .password(let password):
|
||||
let newToken = try await DeveloperServicesLoginManager(
|
||||
deviceInfo: deviceInfo,
|
||||
anisetteProvider: anisetteProvider
|
||||
).logIn(
|
||||
withUsername: self.appleID,
|
||||
password: password,
|
||||
twoFactorDelegate: self
|
||||
)
|
||||
try await self.updateProgress(to: 1/2)
|
||||
token = newToken
|
||||
case .token(let existingToken):
|
||||
token = existingToken
|
||||
}
|
||||
return try await self.install(
|
||||
deviceInfo: deviceInfo,
|
||||
provisioningData: anisetteProvider.provisioningData(),
|
||||
token: token,
|
||||
anisetteProvider: anisetteProvider,
|
||||
appDir: appDir
|
||||
)
|
||||
}
|
||||
|
||||
private func installOnQueue(app: URL) {
|
||||
guard self.updateStage(to: "Unpacking app", initialProgress: nil) else { return }
|
||||
@discardableResult
|
||||
public func install(app: URL) async throws -> String {
|
||||
try await self.updateStage(to: "Unpacking app", initialProgress: nil)
|
||||
|
||||
if FileManager.default.fileExists(atPath: tempDir.path) {
|
||||
try? FileManager.default.removeItem(at: tempDir)
|
||||
}
|
||||
|
||||
do {
|
||||
try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true)
|
||||
} catch {
|
||||
return completion(.failure(error))
|
||||
}
|
||||
try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true)
|
||||
defer { try? FileManager.default.removeItem(at: tempDir) }
|
||||
|
||||
switch app.pathExtension {
|
||||
case "ipa":
|
||||
delegate?.decompress(
|
||||
try await delegate?.decompress(
|
||||
ipa: app,
|
||||
in: tempDir,
|
||||
progress: { progress in
|
||||
_ = self.updateProgress(to: progress, ignoreCancellation: true)
|
||||
},
|
||||
completion: { success in
|
||||
guard self.updateProgress(to: 1) else { return self.completion(.failure(Error.userCancelled)) }
|
||||
self.installQueue.async {
|
||||
self.install(decompressionDidSucceed: success)
|
||||
Task {
|
||||
await self.updateProgressIgnoringCancellation(to: progress)
|
||||
}
|
||||
}
|
||||
)
|
||||
try await self.updateProgress(to: 1)
|
||||
return try await self.installAfterDecompression()
|
||||
case "app":
|
||||
let payload = tempDir.appendingPathComponent("Payload")
|
||||
let dest = payload.appendingPathComponent(app.lastPathComponent)
|
||||
do {
|
||||
try FileManager.default.createDirectory(at: payload, withIntermediateDirectories: false)
|
||||
try FileManager.default.copyItem(at: app, to: dest)
|
||||
} catch {
|
||||
return completion(.failure(error))
|
||||
}
|
||||
guard self.updateProgress(to: 1) else { return self.completion(.failure(Error.userCancelled)) }
|
||||
self.install(decompressionDidSucceed: true)
|
||||
try FileManager.default.createDirectory(at: payload, withIntermediateDirectories: false)
|
||||
try FileManager.default.copyItem(at: app, to: dest)
|
||||
try await self.updateProgress(to: 1)
|
||||
return try await self.installAfterDecompression()
|
||||
default:
|
||||
return completion(.failure(Error.appExtractionFailed))
|
||||
}
|
||||
}
|
||||
|
||||
public func install(app: URL) {
|
||||
installQueue.async {
|
||||
self.installOnQueue(app: app)
|
||||
throw Error.appExtractionFailed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import X509
|
||||
import SwiftASN1
|
||||
|
||||
/// A certificate in DER format
|
||||
public struct Certificate: Codable {
|
||||
public struct Certificate: Codable, Sendable {
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case invalidCertificate
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import ProtoCodable
|
||||
|
||||
public protocol Entitlement: ProtoCodable {
|
||||
public protocol Entitlement: ProtoCodable, Sendable {
|
||||
static var identifier: String { get }
|
||||
static var isFree: Bool { get }
|
||||
/// whether this entitlement should be included in developer services API requests
|
||||
|
||||
@@ -10,13 +10,13 @@ import Foundation
|
||||
import ProtoCodable
|
||||
import Superutils
|
||||
|
||||
public struct EntitlementContainer: ProtoCodableContainer {
|
||||
public struct EntitlementContainer: ProtoCodableContainer, Sendable {
|
||||
public var value: Entitlement
|
||||
public init(value: Entitlement) { self.value = value }
|
||||
}
|
||||
|
||||
// allows access to a parsable entitlements list while not losing unparsed entitlements when it's modified
|
||||
public struct Entitlements {
|
||||
public struct Entitlements: Sendable {
|
||||
|
||||
private static let decoder = PropertyListDecoder()
|
||||
private static let encoder = PropertyListEncoder()
|
||||
|
||||
@@ -11,7 +11,7 @@ import Crypto
|
||||
import X509
|
||||
import _CryptoExtras
|
||||
|
||||
public struct PrivateKey: Codable {
|
||||
public struct PrivateKey: Codable, Sendable {
|
||||
// pem encoded
|
||||
public let data: Data
|
||||
|
||||
@@ -20,7 +20,7 @@ public struct PrivateKey: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct CSR {
|
||||
public struct CSR: Sendable {
|
||||
public let pemString: String
|
||||
|
||||
public init(pemString: String) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import CSupersign
|
||||
|
||||
public final class Mobileprovision: Decodable {
|
||||
public final class Mobileprovision: Decodable, @unchecked Sendable {
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case invalidProfile
|
||||
|
||||
@@ -40,10 +40,10 @@ public struct Signer {
|
||||
}
|
||||
|
||||
public let context: SigningContext
|
||||
public let confirmRevocation: ([DeveloperServicesCertificate]) async -> Bool
|
||||
public let confirmRevocation: @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
public init(
|
||||
context: SigningContext,
|
||||
confirmRevocation: @escaping ([DeveloperServicesCertificate]) async -> Bool
|
||||
confirmRevocation: @escaping @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
) {
|
||||
self.context = context
|
||||
self.confirmRevocation = confirmRevocation
|
||||
@@ -52,7 +52,7 @@ public struct Signer {
|
||||
public func sign(
|
||||
app: URL,
|
||||
status: @escaping (String) -> Void,
|
||||
progress: @escaping (Double?) -> Void,
|
||||
progress: @escaping @Sendable (Double?) -> Void,
|
||||
didProvision: @escaping () throws -> Void = {}
|
||||
) async throws -> String {
|
||||
status(NSLocalizedString("signer.provisioning", value: "Provisioning", comment: ""))
|
||||
@@ -103,18 +103,4 @@ public struct Signer {
|
||||
return mainInfo.newBundleID
|
||||
}
|
||||
|
||||
public func sign(
|
||||
app: URL,
|
||||
status: @escaping (String) -> Void,
|
||||
progress: @escaping (Double?) -> Void,
|
||||
didProvision: @escaping () throws -> Void = {},
|
||||
completion: @escaping (Result<String, Swift.Error>) -> Void
|
||||
) {
|
||||
Task {
|
||||
completion(await Result { try await sign(
|
||||
app: app, status: status, progress: progress, didProvision: didProvision)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
import Foundation
|
||||
import CSupersign
|
||||
import SignerSupport
|
||||
import ConcurrencyExtras
|
||||
|
||||
/// a wrapper around signer_t
|
||||
public struct SignerImpl {
|
||||
public actor SignerImpl {
|
||||
|
||||
private static let signingQueue = DispatchQueue(
|
||||
label: "com.kabiroberai.Supercharge.signing-queue",
|
||||
@@ -48,18 +49,18 @@ public struct SignerImpl {
|
||||
String(cString: signer.pointee.name)
|
||||
}
|
||||
|
||||
private init(signer: UnsafePointer<signer_t>) {
|
||||
self.signer = signer
|
||||
private init(signer: UncheckedSendable<UnsafePointer<signer_t>>) {
|
||||
self.signer = signer.value
|
||||
}
|
||||
|
||||
public static func all() -> AnyCollection<SignerImpl> {
|
||||
public static func all() -> some Collection<SignerImpl> {
|
||||
var list = get_signers()
|
||||
var arr: [SignerImpl] = []
|
||||
while let curr = list {
|
||||
arr.append(SignerImpl(signer: curr))
|
||||
arr.append(SignerImpl(signer: UncheckedSendable(curr)))
|
||||
list = curr.pointee.next
|
||||
}
|
||||
return AnyCollection(arr)
|
||||
return arr
|
||||
}
|
||||
|
||||
public static func first() throws -> SignerImpl {
|
||||
@@ -96,11 +97,18 @@ public struct SignerImpl {
|
||||
$0.data.deallocate()
|
||||
}
|
||||
}
|
||||
let sendableProgress = UncheckedSendable(progress)
|
||||
let sendableEntsArray = UncheckedSendable(entsArray)
|
||||
try certificate.data().withUnsafeBytes { cert in
|
||||
let sendableCert = UncheckedSendable(cert)
|
||||
try privateKey.data.withUnsafeBytes { priv in
|
||||
var exception: UnsafeMutablePointer<Int8>?
|
||||
defer { exception.map { free($0) } }
|
||||
|
||||
let progress = sendableProgress.value
|
||||
let cert = sendableCert.value
|
||||
let entsArray = sendableEntsArray.value
|
||||
|
||||
guard let certBase = cert.baseAddress,
|
||||
let privBase = priv.baseAddress
|
||||
else { throw Error.signer(nil) }
|
||||
@@ -137,22 +145,13 @@ public struct SignerImpl {
|
||||
entitlementMapping: [URL: Entitlements],
|
||||
progress: @escaping (Double?) -> Void
|
||||
) async throws {
|
||||
try await withCheckedThrowingContinuation { cont in
|
||||
Self.signingQueue.async {
|
||||
do {
|
||||
try self._sign(
|
||||
app: app,
|
||||
certificate: certificate,
|
||||
privateKey: privateKey,
|
||||
entitlementMapping: entitlementMapping,
|
||||
progress: progress
|
||||
)
|
||||
cont.resume()
|
||||
} catch {
|
||||
cont.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
try self._sign(
|
||||
app: app,
|
||||
certificate: certificate,
|
||||
privateKey: privateKey,
|
||||
entitlementMapping: entitlementMapping,
|
||||
progress: progress
|
||||
)
|
||||
}
|
||||
|
||||
public func analyze(executable: URL) throws -> Data {
|
||||
@@ -160,8 +159,10 @@ public struct SignerImpl {
|
||||
guard let path = path else { throw Error.badFilePath }
|
||||
var exception: UnsafeMutablePointer<Int8>?
|
||||
defer { exception.map { free($0) } }
|
||||
return try Data { signer.pointee.analyze(path, &$0, &exception) }
|
||||
.orThrow(Error.signer(exception.map { String(cString: $0) }))
|
||||
var count = 0
|
||||
guard let bytes = signer.pointee.analyze(path, &count, &exception)
|
||||
else { throw Error.signer(exception.map { String(cString: $0) })}
|
||||
return Data(bytesNoCopy: bytes, count: count, deallocator: .free)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct SigningContext {
|
||||
public struct SigningContext: Sendable {
|
||||
|
||||
public let udid: String
|
||||
public let deviceName: String
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CSupersign
|
||||
|
||||
package var stdoutSafe: UnsafeMutablePointer<FILE> {
|
||||
get_stdout()
|
||||
}
|
||||
|
||||
extension Data {
|
||||
init?(deallocator: Deallocator = .free, acceptor: (inout Int) -> UnsafeMutableRawPointer?) {
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ConcurrencyExtras
|
||||
|
||||
public enum KeyValueStorageError: Error {
|
||||
case stringConversionFailure
|
||||
}
|
||||
|
||||
public protocol KeyValueStorage {
|
||||
public protocol KeyValueStorage: Sendable {
|
||||
func data(forKey key: String) throws -> Data?
|
||||
func setData(_ data: Data?, forKey key: String) throws
|
||||
// default implementations provided
|
||||
@@ -43,9 +44,9 @@ extension KeyValueStorage {
|
||||
}
|
||||
}
|
||||
|
||||
public class MemoryKeyValueStorage: KeyValueStorage {
|
||||
public final class MemoryKeyValueStorage: KeyValueStorage {
|
||||
|
||||
private var dict: [String: Data] = [:]
|
||||
private let dict = LockIsolated<[String: Data]>([:])
|
||||
public init() {}
|
||||
|
||||
public func data(forKey key: String) throws -> Data? {
|
||||
@@ -53,7 +54,7 @@ public class MemoryKeyValueStorage: KeyValueStorage {
|
||||
}
|
||||
|
||||
public func setData(_ data: Data?, forKey key: String) throws {
|
||||
dict[key] = data
|
||||
dict.withValue { $0[key] = data }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,38 +20,3 @@ public struct ErrorList<E: Error>: LocalizedError {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RequestGrouper<T, E: Error> {
|
||||
|
||||
private let waitQueue = DispatchQueue(
|
||||
label: "com.kabiroberai.Supersign.request-wait-queue",
|
||||
attributes: .concurrent
|
||||
)
|
||||
private let group = DispatchGroup()
|
||||
|
||||
private var values: [T] = []
|
||||
private var errors: [E] = []
|
||||
|
||||
func add(request: (_ completion: @escaping (Result<T, E>) -> Void) -> Void) {
|
||||
group.enter()
|
||||
request { result in
|
||||
defer { self.group.leave() }
|
||||
switch result {
|
||||
case .failure(let error): self.errors.append(error)
|
||||
case .success(let value): self.values.append(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func onComplete(_ completion: @escaping (Result<[T], Error>) -> Void) {
|
||||
waitQueue.async {
|
||||
self.group.wait()
|
||||
switch self.errors.count {
|
||||
case 0: completion(.success(self.values))
|
||||
case 1: completion(.failure(self.errors[0]))
|
||||
default: completion(.failure(ErrorList(self.errors)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ConcurrencyExtras
|
||||
|
||||
public struct SigningInfo: Codable {
|
||||
public struct SigningInfo: Codable, Sendable {
|
||||
public let privateKey: PrivateKey
|
||||
public let certificate: Certificate
|
||||
}
|
||||
|
||||
public protocol SigningInfoManager {
|
||||
public protocol SigningInfoManager: Sendable {
|
||||
func info(forTeamID teamID: DeveloperServicesTeam.ID) throws -> SigningInfo?
|
||||
func setInfo(_ info: SigningInfo?, forTeamID teamID: DeveloperServicesTeam.ID) throws
|
||||
}
|
||||
@@ -29,8 +30,8 @@ extension SigningInfoManager {
|
||||
}
|
||||
}
|
||||
|
||||
public class MemoryBackedSigningInfoManager: SigningInfoManager {
|
||||
private var infos: [String: SigningInfo] = [:]
|
||||
public final class MemoryBackedSigningInfoManager: SigningInfoManager {
|
||||
private let infos = LockIsolated<[String: SigningInfo]>([:])
|
||||
|
||||
public init() {}
|
||||
|
||||
@@ -39,7 +40,9 @@ public class MemoryBackedSigningInfoManager: SigningInfoManager {
|
||||
}
|
||||
|
||||
public func setInfo(_ info: SigningInfo?, forTeamID teamID: DeveloperServicesTeam.ID) throws {
|
||||
infos[teamID.rawValue] = info
|
||||
infos.withValue {
|
||||
$0[teamID.rawValue] = info
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
|
||||
enum Console {
|
||||
// nil = EOF
|
||||
@@ -6,7 +7,7 @@ enum Console {
|
||||
if !message.isEmpty {
|
||||
print(message, terminator: "")
|
||||
}
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
return readLine()
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ private extension AuthToken {
|
||||
storage: SupersignCLI.config.storage
|
||||
)
|
||||
if resetProvisioning {
|
||||
await provider.resetProvisioning()
|
||||
provider.resetProvisioning()
|
||||
}
|
||||
let authDelegate = SupersignCLIAuthDelegate()
|
||||
let manager = try DeveloperServicesLoginManager(
|
||||
@@ -120,7 +120,7 @@ struct DSTeamsListCommand: AsyncParsableCommand {
|
||||
}
|
||||
|
||||
struct DSAnisetteCommand: AsyncParsableCommand {
|
||||
private class Provider: RawADIProvider, RawADIProvisioningSession {
|
||||
private final class Provider: RawADIProvider, RawADIProvisioningSession {
|
||||
func startProvisioning(spim: Data, userID: UUID) -> (RawADIProvisioningSession, Data) {
|
||||
print("spim: \(spim.base64EncodedString())")
|
||||
return (self, Data(base64Encoded: Console.prompt("cpim: ")!)!)
|
||||
|
||||
@@ -2,7 +2,7 @@ import Foundation
|
||||
import Supersign
|
||||
import ArgumentParser
|
||||
|
||||
extension ConnectionManager.SearchMode: @retroactive EnumerableFlag {
|
||||
extension ConnectionManager.SearchMode: EnumerableFlag {
|
||||
// public static func name(for value: ConnectionManager.SearchMode) -> NameSpecification {
|
||||
// [.short, .long]
|
||||
// }
|
||||
|
||||
@@ -3,7 +3,7 @@ import Supersign
|
||||
import SwiftyMobileDevice
|
||||
import ArgumentParser
|
||||
|
||||
struct InstallCommand: ParsableCommand {
|
||||
struct InstallCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "install",
|
||||
abstract: "Install an ipa file to your device"
|
||||
@@ -20,7 +20,7 @@ struct InstallCommand: ParsableCommand {
|
||||
help: "The path to a custom app/ipa to install"
|
||||
) var path: String
|
||||
|
||||
func run() throws {
|
||||
func run() async throws {
|
||||
let token = try account.flatMap(AuthToken.init(string:)) ?? AuthToken.saved()
|
||||
|
||||
let username = token.appleID
|
||||
@@ -28,10 +28,7 @@ struct InstallCommand: ParsableCommand {
|
||||
|
||||
print("Installing to device: \(client.deviceName) (udid: \(client.udid))")
|
||||
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
let installDelegate = SupersignCLIDelegate(preferredTeam: team.map(DeveloperServicesTeam.ID.init)) {
|
||||
semaphore.signal()
|
||||
}
|
||||
let installDelegate = SupersignCLIDelegate(preferredTeam: team.map(DeveloperServicesTeam.ID.init))
|
||||
let installer = IntegratedInstaller(
|
||||
udid: client.udid,
|
||||
lookupMode: .only(client.connectionType),
|
||||
@@ -41,8 +38,13 @@ struct InstallCommand: ParsableCommand {
|
||||
storage: SupersignCLI.config.storage,
|
||||
delegate: installDelegate
|
||||
)
|
||||
installer.install(app: URL(fileURLWithPath: path))
|
||||
semaphore.wait()
|
||||
_ = installer
|
||||
|
||||
do {
|
||||
try await installer.install(app: URL(fileURLWithPath: path))
|
||||
print("\nSuccessfully installed!")
|
||||
} catch {
|
||||
print("\nFailed :(")
|
||||
print("Error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import Foundation
|
||||
import Supersign
|
||||
import ArgumentParser
|
||||
|
||||
struct InstallSuperchargeCommand: ParsableCommand {
|
||||
struct InstallSuperchargeCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "install",
|
||||
abstract: "Install Supercharge"
|
||||
@@ -11,7 +11,7 @@ struct InstallSuperchargeCommand: ParsableCommand {
|
||||
@Option(name: .shortAndLong) var udid: String?
|
||||
@Option(name: .shortAndLong) var account: String?
|
||||
|
||||
func run() throws {
|
||||
func run() async throws {
|
||||
guard let app = SupersignCLI.config.superchargeApp else {
|
||||
throw Console.Error("This copy of Supersign is not configured to install Supercharge.")
|
||||
}
|
||||
@@ -58,9 +58,7 @@ struct InstallSuperchargeCommand: ParsableCommand {
|
||||
|
||||
print("Installing to device: \(client.deviceName) (udid: \(client.udid))")
|
||||
|
||||
let installDelegate = SupersignCLIDelegate(preferredTeam: nil) {
|
||||
semaphore.signal()
|
||||
}
|
||||
let installDelegate = SupersignCLIDelegate(preferredTeam: nil)
|
||||
let installer = IntegratedInstaller(
|
||||
udid: client.udid,
|
||||
lookupMode: .only(.usb),
|
||||
@@ -70,9 +68,22 @@ struct InstallSuperchargeCommand: ParsableCommand {
|
||||
storage: SupersignCLI.config.storage,
|
||||
delegate: installDelegate
|
||||
)
|
||||
installer.install(app: app)
|
||||
semaphore.wait()
|
||||
_ = installer
|
||||
|
||||
do {
|
||||
let bundleID = try await installer.install(app: app)
|
||||
print("\nSuccessfully installed!")
|
||||
if let file = ProcessInfo.processInfo.environment["SUPERSIGN_METADATA_FILE"] {
|
||||
do {
|
||||
try Data("\(bundleID)\n".utf8).write(to: URL(fileURLWithPath: file))
|
||||
} catch {
|
||||
print("warning: Failed to write metadata to SUPERSIGN_METADATA_FILE: \(error)")
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("\nFailed :(")
|
||||
print("Error: \(error)")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,30 +11,29 @@ final class SupersignCLIAuthDelegate: TwoFactorAuthDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
final class SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDelegate {
|
||||
actor SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDelegate {
|
||||
public enum Error: Swift.Error {
|
||||
case decompressionFailed
|
||||
case compressionFailed
|
||||
}
|
||||
|
||||
let preferredTeam: DeveloperServicesTeam.ID?
|
||||
let completion: () -> Void
|
||||
init(preferredTeam: DeveloperServicesTeam.ID?, completion: @escaping () -> Void) {
|
||||
init(preferredTeam: DeveloperServicesTeam.ID?) {
|
||||
self.preferredTeam = preferredTeam
|
||||
self.completion = completion
|
||||
}
|
||||
|
||||
func fetchCode() async -> String? {
|
||||
await _fetchCode()
|
||||
}
|
||||
|
||||
func fetchTeam(fromTeams teams: [DeveloperServicesTeam], completion: @escaping (DeveloperServicesTeam?) -> Void) {
|
||||
func fetchTeam(fromTeams teams: [DeveloperServicesTeam]) async -> DeveloperServicesTeam? {
|
||||
if let preferredTeam = preferredTeam {
|
||||
// Fails if a team with the requested ID isn't found.
|
||||
// This is intentional to avoid interactivity.
|
||||
return completion(teams.first(where: { $0.id == preferredTeam }))
|
||||
return teams.first(where: { $0.id == preferredTeam })
|
||||
}
|
||||
|
||||
let selected = Console.choose(
|
||||
return Console.choose(
|
||||
from: teams,
|
||||
onNoElement: { fatalError("No development teams available") },
|
||||
multiPrompt: "\nSelect a team",
|
||||
@@ -42,10 +41,9 @@ final class SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDele
|
||||
"\($0.name) (\($0.id.rawValue))"
|
||||
}
|
||||
)
|
||||
completion(selected)
|
||||
}
|
||||
|
||||
func setPresentedMessage(_ message: IntegratedInstaller.Message?) {
|
||||
nonisolated func setPresentedMessage(_ message: IntegratedInstaller.Message?) {
|
||||
let text: String
|
||||
switch message {
|
||||
case .pairDevice:
|
||||
@@ -56,13 +54,13 @@ final class SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDele
|
||||
text = "Continuing..."
|
||||
}
|
||||
print("\n\(text)", terminator: "")
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
}
|
||||
|
||||
var prevStage: String?
|
||||
var prevProgress: String?
|
||||
|
||||
func installerDidUpdate(toStage stage: String, progress: Double?) {
|
||||
private func _installerDidUpdate(toStage stage: String, progress: Double?) {
|
||||
let progString: String?
|
||||
if let progress = progress {
|
||||
let progInt = Int(progress * 100)
|
||||
@@ -85,39 +83,24 @@ final class SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDele
|
||||
if stage != prevStage {
|
||||
if let progString = progString {
|
||||
print("\n[\(stage)] \(progString)", terminator: "")
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
} else {
|
||||
print("\n[\(stage)] ...", terminator: "")
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
}
|
||||
} else if progString != prevProgress {
|
||||
if let progString = progString {
|
||||
print("\r[\(stage)] \(progString)", terminator: "")
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
} else {
|
||||
print("\r[\(stage)]", terminator: "")
|
||||
fflush(stdout)
|
||||
fflush(stdoutSafe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func installerDidComplete(withResult result: Result<String, Swift.Error>) {
|
||||
print("\n")
|
||||
switch result {
|
||||
case .success(let bundleID):
|
||||
print("Successfully installed!")
|
||||
if let file = ProcessInfo.processInfo.environment["SUPERSIGN_METADATA_FILE"] {
|
||||
do {
|
||||
try Data("\(bundleID)\n".utf8).write(to: URL(fileURLWithPath: file))
|
||||
} catch {
|
||||
print("warning: Failed to write metadata to SUPERSIGN_METADATA_FILE: \(error)")
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
print("Failed :(")
|
||||
print("Error: \(error)")
|
||||
}
|
||||
completion()
|
||||
nonisolated func installerDidUpdate(toStage stage: String, progress: Double?) {
|
||||
Task { await _installerDidUpdate(toStage: stage, progress: progress) }
|
||||
}
|
||||
|
||||
private static let expiryFormatter: DateFormatter = {
|
||||
@@ -142,26 +125,23 @@ final class SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDele
|
||||
func decompress(
|
||||
ipa: URL,
|
||||
in directory: URL,
|
||||
progress: @escaping (Double?) -> Void,
|
||||
completion: @escaping (_ success: Bool) -> Void
|
||||
) {
|
||||
progress: @escaping (Double?) -> Void
|
||||
) async throws {
|
||||
progress(nil)
|
||||
|
||||
let unzip = Process()
|
||||
unzip.launchPath = "/usr/bin/unzip"
|
||||
unzip.arguments = ["-q", ipa.path, "-d", directory.path]
|
||||
unzip.launch()
|
||||
unzip.waitUntilExit()
|
||||
guard unzip.terminationStatus == 0 else { return completion(false) }
|
||||
|
||||
completion(true)
|
||||
try await unzip.launchAndWait()
|
||||
guard unzip.terminationStatus == 0 else {
|
||||
throw Error.decompressionFailed
|
||||
}
|
||||
}
|
||||
|
||||
func compress(
|
||||
payloadDir: URL,
|
||||
progress: @escaping (Double?) -> Void,
|
||||
completion: @escaping (Result<URL, Swift.Error>) -> Void
|
||||
) {
|
||||
progress: @escaping (Double?) -> Void
|
||||
) async throws -> URL {
|
||||
progress(nil)
|
||||
|
||||
let dest = payloadDir.deletingLastPathComponent().appendingPathComponent("app.ipa")
|
||||
@@ -170,10 +150,26 @@ final class SupersignCLIDelegate: IntegratedInstallerDelegate, TwoFactorAuthDele
|
||||
zip.launchPath = "/usr/bin/zip"
|
||||
zip.currentDirectoryPath = payloadDir.deletingLastPathComponent().path
|
||||
zip.arguments = ["-yqru0", dest.path, "Payload"]
|
||||
zip.launch()
|
||||
zip.waitUntilExit()
|
||||
guard zip.terminationStatus == 0 else { return completion(.failure(Error.compressionFailed)) }
|
||||
try await zip.launchAndWait()
|
||||
guard zip.terminationStatus == 0 else { throw Error.compressionFailed }
|
||||
|
||||
completion(.success(dest))
|
||||
return dest
|
||||
}
|
||||
}
|
||||
|
||||
extension Process {
|
||||
fileprivate func launchAndWait() async throws {
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
terminationHandler = { _ in
|
||||
continuation.resume()
|
||||
}
|
||||
do {
|
||||
try self.run()
|
||||
} catch {
|
||||
continuation.resume(throwing: error)
|
||||
return
|
||||
}
|
||||
Task.detached { self.waitUntilExit() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import Supersign
|
||||
import ArgumentParser
|
||||
|
||||
public enum SupersignCLI {
|
||||
public struct Configuration {
|
||||
public struct Configuration: Sendable {
|
||||
public let superchargeApp: URL?
|
||||
public let storage: KeyValueStorage
|
||||
|
||||
@@ -16,7 +16,7 @@ public enum SupersignCLI {
|
||||
}
|
||||
}
|
||||
|
||||
private static var _config: Configuration!
|
||||
private static nonisolated(unsafe) var _config: Configuration!
|
||||
static var config: Configuration { _config }
|
||||
|
||||
public static func run(configuration: Configuration, arguments: [String]? = nil) async throws {
|
||||
|
||||
@@ -3,7 +3,7 @@ import Supersign
|
||||
import SwiftyMobileDevice
|
||||
import ArgumentParser
|
||||
|
||||
struct UninstallCommand: ParsableCommand {
|
||||
struct UninstallCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "uninstall",
|
||||
abstract: "Uninstall an installed app"
|
||||
@@ -15,25 +15,17 @@ struct UninstallCommand: ParsableCommand {
|
||||
help: "The app to uninstall"
|
||||
) var bundleID: String
|
||||
|
||||
func run() throws {
|
||||
func run() async throws {
|
||||
let installProxy = try InstallationProxyClient(device: connection.device, label: "supersign-inst")
|
||||
let sem = DispatchSemaphore(value: 0)
|
||||
var error: Error?
|
||||
installProxy.uninstall(
|
||||
bundleID: bundleID,
|
||||
progress: { _ in },
|
||||
completion: { result in
|
||||
if case let .failure(err) = result {
|
||||
error = err
|
||||
}
|
||||
sem.signal()
|
||||
}
|
||||
)
|
||||
sem.wait()
|
||||
if let error = error {
|
||||
do {
|
||||
try await installProxy.uninstall(
|
||||
bundleID: bundleID,
|
||||
progress: { _ in }
|
||||
)
|
||||
} catch {
|
||||
print("Failed: \(error)")
|
||||
} else {
|
||||
print("Success!")
|
||||
return
|
||||
}
|
||||
print("Success!")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user