feat: auto-reconnect peripherals that drop while held on this Mac#36
Merged
Merged
Conversation
Apple's Magic peripherals sometimes fail to reconnect after the Bluetooth radio sleeps (e.g. a lid-close) and stay stuck until they're physically powered off and on — a macOS-side bug we can't fix, but can recover from. A persistent watcher now retries a peripheral that drops while it should be on this Mac until it's back in range (or a 1h window expires), so the user no longer has to manually reconnect after flipping the device off and on. - Armed on a genuine disconnect (handlePeripheralDisconnected) and, on wake, for everything this Mac was connected to right before sleep (connectedBeforeSleep) -- not just the peripherals we actively handed off -- so a device that dropped on a peerless lid-close is covered too. Deliberate releases (handoff, "Remove from PC", sleep) are flagged so they never arm it. - Each probe is a cheap RSSI read; only once the device is visible again does it consult the peer with a read-only HOLDS_ONE query and reclaim it unless the peer is actively using it. It never tells the peer to disconnect, so an in-use peripheral on the other Mac is never stolen. - Watcher retries pair silently; the "Pairing Timed Out" notification stays reserved for interactive connects. - Gated by a default-on "Reconnect peripherals if they drop" toggle in Settings -> Other.
|
🎉 This PR is included in version 2.11.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This was referenced Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Apple's Magic peripherals sometimes fail to reconnect after the Bluetooth radio sleeps (a lid-close, say) and stay stuck until they're physically powered off and on — a macOS-side bug we can't fix, but can recover from. Today the only reconnect attempt is a single shot on wake, so if the device is still stuck at that moment nothing brings it back and the user has to reconnect by hand after power-cycling it.
This adds a persistent auto-reconnect watcher: a peripheral that drops while it should be on this Mac is retried until it's back in range (or a 1 h window expires), so reconnection just happens once the device reappears.
How it works
handlePeripheralDisconnected) and, on wake, for everything this Mac was connected to right before sleep (connectedBeforeSleep) — not just the peripherals we actively handed off — so a device that dropped on a lid-close with no peer to take it is covered too. Deliberate releases (handoff, "Remove from PC", sleep) are flagged so they never arm it.HOLDS_ONEquery confirms the peer isn't using it (peer "yes" → leave it; "no" or unreachable → take it). It never tells the peer to disconnect, so an in-use peripheral on the other Mac is never stolen.isConnected()check means a device macOS reconnected on its own is dropped from the watchlist rather than needlessly re-paired.Safety
Two independent gates keep it from grabbing a peripheral the other Mac is actively using: the RSSI visibility gate (a peripheral connected to the peer isn't advertising → invisible to us → never attempted), and the 5 s wake delay plus
HOLDS_ONE's own 5 s connect window, which absorb Wi-Fi reassociation lag on wake.Testing
Builds clean (
CODE_SIGNING_ALLOWED=NO);swift formatapplied. No test target in this project. The sleep/wake/power-cycle recovery and the RSSI "is it back?" timing want a real two-Mac + Magic-device check — IOBluetooth sleep behavior can't be exercised locally.