Skip to content

Commit

Permalink
make sure requestedUUID gets reset so listen for devices doesn't get …
Browse files Browse the repository at this point in the history
…blcoked
  • Loading branch information
simonmcl committed Oct 21, 2024
1 parent d5840c7 commit 08b109a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/KukaiCoreSwift/Services/LedgerService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ public class LedgerService: NSObject, CBPeripheralDelegate, CBCentralManagerDele
if let device = self.connectedDevice {
self.centralManager?.cancelPeripheralConnection(device)
}

requestedUUID = nil
}

/**
Expand Down Expand Up @@ -425,6 +427,7 @@ public class LedgerService: NSObject, CBPeripheralDelegate, CBCentralManagerDele
public func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
Logger.ledger.info("Failed to connect to \(peripheral.name ?? ""), \(peripheral.identifier.uuidString)")
self.connectedDevice = nil
self.requestedUUID = nil
self.deviceConnectedPublisher.send(false)
}

Expand All @@ -433,6 +436,7 @@ public class LedgerService: NSObject, CBPeripheralDelegate, CBCentralManagerDele
guard let services = peripheral.services else {
Logger.ledger.info("Unable to locate services for: \(peripheral.name ?? ""), \(peripheral.identifier.uuidString). Error: \(error)")
self.connectedDevice = nil
self.requestedUUID = nil
self.deviceConnectedPublisher.send(false)
return
}
Expand All @@ -448,12 +452,14 @@ public class LedgerService: NSObject, CBPeripheralDelegate, CBCentralManagerDele
public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: (any Error)?) {
Logger.ledger.info("Disconnected: \(peripheral.name ?? ""), \(peripheral.identifier.uuidString). Error: \(error)")
self.connectedDevice = nil
self.requestedUUID = nil
self.deviceConnectedPublisher.send(false)
}

public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, timestamp: CFAbsoluteTime, isReconnecting: Bool, error: (any Error)?) {
Logger.ledger.info("Disconnected: \(peripheral.name ?? ""), \(peripheral.identifier.uuidString). Error: \(error)")
self.connectedDevice = nil
self.requestedUUID = nil
self.deviceConnectedPublisher.send(false)
}

Expand All @@ -462,6 +468,7 @@ public class LedgerService: NSObject, CBPeripheralDelegate, CBCentralManagerDele
guard let characteristics = service.characteristics else {
Logger.ledger.info("Unable to locate characteristics for: \(peripheral.name ?? ""), \(peripheral.identifier.uuidString). Error: \(error)")
self.connectedDevice = nil
self.requestedUUID = nil
self.deviceConnectedPublisher.send(false)
return
}
Expand Down

0 comments on commit 08b109a

Please sign in to comment.