Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 5 additions & 11 deletions Magic Switch/Model/Store/BluetoothPeripheralStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ final class BluetoothPeripheralStore: NSObject, ObservableObject, BluetoothPerip
return
}
let sentAt = Date()
let peerKeepsTrying = self.needsTypedCode(peripheral.id)
let typedCode = self.needsTypedCode(peripheral.id)
networkStore.executeConnectOne(address: peripheral.id, on: device) { [weak self] result in
guard let self = self else { return }
switch result {
Expand Down Expand Up @@ -1381,7 +1381,7 @@ final class BluetoothPeripheralStore: NSObject, ObservableObject, BluetoothPerip
// We did release it locally, so we're disconnected regardless of
// where it ended up; clear the "Sending…" row.
self.setConnectionState(.disconnected, for: peripheral.id)
if !peerKeepsTrying {
if err.peerReplied || !typedCode {
DispatchQueue.main.async {
self.reclaimUnheld(
[peripheral], from: device, sentAt: sentAt, peerReplied: err.peerReplied)
Expand Down Expand Up @@ -1454,12 +1454,12 @@ final class BluetoothPeripheralStore: NSObject, ObservableObject, BluetoothPerip
}

/// Bring back what `peer` doesn't hold after a full-set send that reached
/// it but didn't complete, except keyboards that need a typed code; see
/// `reclaimUnheld`.
/// it but didn't complete; see `reclaimUnheld`. Without its reply, keyboards
/// that need a typed code are left to its retries.
func rollBackFullSetRelease(from peer: NetworkDevice, sentAt: Date, peerReplied: Bool) {
finishFullSetRelease()
reclaimUnheld(
peripherals.filter { !needsTypedCode($0.id) }, from: peer, sentAt: sentAt,
peripherals.filter { peerReplied || !needsTypedCode($0.id) }, from: peer, sentAt: sentAt,
peerReplied: peerReplied)
}

Expand Down Expand Up @@ -1524,12 +1524,6 @@ final class BluetoothPeripheralStore: NSObject, ObservableObject, BluetoothPerip
refreshStaleBondOnFailedOpen: true,
completion: completion
)
let id = peripheral.id
let armIfTyped = { [weak self] in
guard let self = self, self.needsTypedCode(id) else { return }
self.armReconnectForTakeover(id)
}
if Thread.isMainThread { armIfTyped() } else { DispatchQueue.main.async(execute: armIfTyped) }
}

/// Connects `peripherals`; `completion` reports whether every one ended
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Older keyboards, such as Apple's Wireless Keyboard that runs on AA batteries, us
</p>

- If a switch doesn't finish, click the keyboard in the menu on the Mac you want it on. That Mac shows the window again when the keyboard asks for the code.
- If your other Mac can't take the keyboard, for example because it isn't in that Mac's list, the Mac you sent it from takes it back and shows the window.
- In a switch with other peripherals, the others connect first.
- When a Mac sleeps, it keeps such a keyboard paired unless your other Mac can take it right then, so closing a lid doesn't leave you typing the code on wake.
- If no window ever appears and the keyboard won't connect, set its type to **Keyboard** in the Peripherals tab.
Expand Down
Loading