@@ -758,23 +758,19 @@ export class Bluetooth extends BluetoothCommon {
758758
759759 // needed for consecutive calls to isBluetoothEnabled. Until readyToAskForEnabled, everyone waits!
760760 readyToAskForEnabled = false ;
761- public isBluetoothEnabled ( ) : Promise < boolean > {
762- const methodName = 'isBluetoothEnabled' ;
763- return Promise . resolve ( )
764- . then ( ( ) => {
765- if ( ! this . readyToAskForEnabled ) {
766- // the centralManager return wrong state just after initialization
767- // so create it and wait a bit
768- // eslint-disable-next-line no-unused-expressions
769- this . centralManager ;
770- if ( Trace . isEnabled ( ) ) {
771- CLog ( CLogTypes . info , methodName , 'waiting a bit' ) ;
772- }
773- return new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) . then ( ( ) => ( this . readyToAskForEnabled = true ) ) ;
774- }
775- return null ;
776- } )
777- . then ( ( ) => this . _isEnabled ( ) ) ;
761+ public async isBluetoothEnabled ( ) {
762+ if ( ! this . readyToAskForEnabled ) {
763+ // the centralManager return wrong state just after initialization
764+ // so create it and wait a bit
765+ // eslint-disable-next-line no-unused-expressions
766+ this . centralManager ;
767+ if ( Trace . isEnabled ( ) ) {
768+ CLog ( CLogTypes . info , 'isBluetoothEnabled' , 'waiting a bit' ) ;
769+ }
770+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
771+ this . readyToAskForEnabled = true ;
772+ }
773+ return this . _isEnabled ( ) ;
778774 }
779775 scanningReferTimer : {
780776 timer ?: NodeJS . Timeout ;
@@ -1582,7 +1578,7 @@ export class Bluetooth extends BluetoothCommon {
15821578 }
15831579
15841580 private _isEnabled ( ) {
1585- return this . state === CBManagerState . PoweredOn ;
1581+ return this . _state === CBManagerState . PoweredOn ;
15861582 }
15871583
15881584 private _findService ( UUID : CBUUID , peripheral : CBPeripheral ) {
0 commit comments