Repository navigation
Conversation
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.
darwin: create CoreBluetooth managers in Enable, not at package init
DefaultAdapteron darwin creates itsCBCentralManagerandCBPeripheralManagerin a package-level initialiser, so any program thatimports
tinygo.org/x/bluetoothstarts CoreBluetooth beforemainruns,whether or not it ever calls
Enable().Creating a manager triggers macOS's Bluetooth privacy check, which for a
command-line program applies to the terminal app that launched it. On macOS
27.2, run from a terminal without Bluetooth permission, the process is killed
with SIGABRT a moment after it starts. There's no Go panic or stack trace, and
the program can't detect or handle it. (On macOS 26.6 the same program gets a
permission prompt instead, and keeps running if access is denied.) We hit this
with a large program that uses BLE in one optional feature: it crashed on
startup on a developer's Mac even though that feature was turned off. It didn't
crash under lldb, where a different process is responsible for it.
This PR moves creating the managers into
Enable(), so only programs thatactually use Bluetooth start CoreBluetooth.
Reset()now clears the managersinstead of creating new ones; its doc already says that the following
Enable()creates fresh managers.This matches the other backends, whose
DefaultAdapterholds only Go stateand leaves all platform setup to
Enable(): D-Bus on Linux,RoInitializeonWindows, the SoftDevice on nRF, and so on.
Behaviour changes:
Enable()no longer touchCoreBluetooth.
Enable()behave as before. The managers are created justbefore the delegate is set, and the existing comment about setting the
delegate before checking the state still applies.
Adaptermethods beforeEnable()was already documented asunsupported. Those methods now message a nil manager, which Objective-C
treats as a no-op.
Tested:
go vet .on darwin and linux.Enable()nowstarts from a terminal without Bluetooth permission, where it used to abort.