Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Magic Switch/Model/Store/BluetoothPeripheralStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,18 @@ final class BluetoothPeripheralStore: NSObject, ObservableObject, BluetoothPerip
return
}

// Already connected — e.g. macOS reconnected this bonded peripheral on
// its own while the auto-reconnect watcher's HOLDS_ONE probe was in
// flight, so by the time we got here there's nothing left to pair.
// Starting an `IOBluetoothDevicePair` on an already-connected device
// never fires `devicePairingFinished`, stranding the UI at `.connecting`
// ("(Pairing…)"). Adopt the live connection instead.
if btDevice.isConnected() {
self.setConnectionState(.connected, for: peripheral.id)
self.registerForDisconnect(device: btDevice, address: peripheral.id)
return
}

if btDevice.rssi() == Constants.invalidRSSI {
print("\(peripheral.name) is out of range or not responding")
self.setConnectionState(.disconnected, for: peripheral.id)
Expand Down