Bug fixes, performance improvements, and SwiftyMobileDevice API changes

This commit is contained in:
kabiroberai
2020-04-02 19:00:13 +05:30
committed by Kabir Oberai
Unverified
parent cb54463d29
commit 9cba2f0055
2 changed files with 33 additions and 14 deletions
+32 -12
View File
@@ -13,9 +13,35 @@ class HeartbeatHandler {
private struct Error: Swift.Error {}
private struct ReceivedPacket: Decodable {
enum Command: String, Decodable {
case marco = "Marco"
}
let command: Command
let interval: Int
private enum CodingKeys: String, CodingKey {
case command = "Command"
case interval = "Interval"
}
}
private struct SentPacket: Encodable {
enum Command: String, Encodable {
case polo = "Polo"
}
let command: Command
private enum CodingKeys: String, CodingKey {
case command = "Command"
}
}
private static let restartInterval: TimeInterval = 1
private static let requestCommand = "Marco"
private static let responseCommand = "Polo"
// private static let requestCommand = "Marco"
// private static let responseCommand = "Polo"
// each handler should have its own heartbeat queue
private let heartbeatQueue = DispatchQueue(
@@ -33,18 +59,12 @@ class HeartbeatHandler {
private func beat(client: HeartbeatClient, idx: Int) throws {
// allow a 30 second timeout for the first heartbeat
let plist = try client.receive(timeout: idx == 0 ? 30 : 5)
guard case let .dictionary(dict) = plist,
case let .string(command) = dict["Command"],
case let .integer(interval) = dict["Interval"],
command == Self.requestCommand
else { throw Error() }
let received = try client.receive(ReceivedPacket.self, timeout: idx == 0 ? 30 : 5)
guard received.command == .marco else { throw Error() }
try client.send(.dictionary([
"Command": .string(Self.responseCommand)
]))
try client.send(SentPacket(command: .polo))
sleep(.init(interval))
sleep(.init(received.interval))
}
private func start() {
+1 -2
View File
@@ -21,8 +21,7 @@ class IPAInstaller {
bundleID: String,
progress: @escaping (InstallationProxyClient.InstallProgress) -> Void
) throws {
let options = InstallationProxyClient.InstallOptions()
options["CFBundleIdentifier"] = bundleID
let options = InstallationProxyClient.Options(additionalOptions: ["CFBundleIdentifier": bundleID])
var error: Error?
let semaphore = DispatchSemaphore(value: 0)