diff --git a/go.mod b/go.mod index 4e2dafc..6f09ed1 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( go.bug.st/serial v1.6.4 golang.org/x/term v0.43.0 google.golang.org/protobuf v1.36.11 - tinygo.org/x/bluetooth v0.15.0 + tinygo.org/x/bluetooth v0.15.1-0.20260516164426-9314216eb8e6 ) require ( diff --git a/go.sum b/go.sum index ff1dc6f..9e2af9d 100644 --- a/go.sum +++ b/go.sum @@ -1175,3 +1175,5 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= tinygo.org/x/bluetooth v0.15.0 h1:hLn8+iZFXvVxBzPIdZfvc6TD8JP32ixF22lCEWHAbIo= tinygo.org/x/bluetooth v0.15.0/go.mod h1:meayNB+9rC1igTUNmNU7KftlSEzrFHe37rBSQZjHN8Y= +tinygo.org/x/bluetooth v0.15.1-0.20260516164426-9314216eb8e6 h1:oRX+XsAJ0HOQa57yUelRxllVZyLoggYjdO6Z/VfvKjo= +tinygo.org/x/bluetooth v0.15.1-0.20260516164426-9314216eb8e6/go.mod h1:meayNB+9rC1igTUNmNU7KftlSEzrFHe37rBSQZjHN8Y= diff --git a/internal/meshx/transport/ble.go b/internal/meshx/transport/ble.go index 5739785..8448899 100644 --- a/internal/meshx/transport/ble.go +++ b/internal/meshx/transport/ble.go @@ -31,32 +31,6 @@ import ( "tinygo.org/x/bluetooth" ) -// adapter.Enable() on tinygo-bluetooth v0.15.0 is non-idempotent on -// macOS — a second call from the same process returns "already calling -// Enable function" and aborts. The pump's reconnect loop redials on -// every transport drop, so without this guard every retry would fail -// for the wrong reason. Enable once per process, cache the result — -// but only on success. A failed Enable (timeout, TCC permission not -// yet granted) must be retryable so the daemon doesn't stay bricked -// until restart. -var ( - bleEnableMu sync.Mutex - bleEnableSuccess bool -) - -func enableBLEAdapterOnce(adapter *bluetooth.Adapter) error { - bleEnableMu.Lock() - defer bleEnableMu.Unlock() - if bleEnableSuccess { - return nil - } - if err := adapter.Enable(); err != nil { - return err - } - bleEnableSuccess = true - return nil -} - // scannedAddrs caches the bluetooth.Address (which carries the // CBPeripheral pointer on macOS) of every UUID we've successfully // scanned in this process. The cache lets in-process redials skip @@ -155,7 +129,7 @@ const bleReadBuf = 512 // real error before it can panic downstream. func DialBLE(addr string) (Client, error) { adapter := bluetooth.DefaultAdapter - if err := enableBLEAdapterOnce(adapter); err != nil { + if err := adapter.Enable(); err != nil { return nil, fmt.Errorf("enable bluetooth adapter: %w — is Bluetooth on?", err) } diff --git a/internal/meshx/transport/ble_scan.go b/internal/meshx/transport/ble_scan.go index 370b06a..44b0f4f 100644 --- a/internal/meshx/transport/ble_scan.go +++ b/internal/meshx/transport/ble_scan.go @@ -52,7 +52,7 @@ type BLESighting struct { // deduplicated set. func ScanBLE(timeout time.Duration) ([]BLESighting, error) { adapter := bluetooth.DefaultAdapter - if err := enableBLEAdapterOnce(adapter); err != nil { + if err := adapter.Enable(); err != nil { return nil, fmt.Errorf("enable bluetooth adapter: %w", err) }