@@ -5,7 +5,6 @@ import { buildCompleteIdentifier } from '../bluetooth-extension';
55import { IDisposable } from '@lumino/disposable' ;
66import { Dialog , showDialog } from '@jupyterlab/apputils' ;
77
8-
98/**
109 * A class used to update the list of connected device and the related signals used to rerender the connected devices section.
1110 */
@@ -101,29 +100,24 @@ export class BluetoothManager implements IBluetoothManager {
101100 const isWebBluetoothSupported : boolean = navigator . bluetooth ? true : false ;
102101 if ( isWebBluetoothSupported === false ) {
103102 showDialog ( {
104- title : ( 'Error' ) ,
105- body : (
106- 'Web Bluetooth is not supported on your browser. It works on Chrome and Edge (Firefox and Explorer are not supported). \n Please also check that the Web Bluetooth flag is properly set to enabled in the Chrome flags (chrome://flags/).'
107- ) ,
108- buttons : [
109- Dialog . okButton ( { label : ( 'Close' ) } )
110- ]
103+ title : 'Error' ,
104+ body : 'Web Bluetooth is not supported on your browser. It works on Chrome and Edge (Firefox and Explorer are not supported). \n Please also check that the Web Bluetooth flag is properly set to enabled in the Chrome flags (chrome://flags/).' ,
105+ buttons : [ Dialog . okButton ( { label : 'Close' } ) ]
111106 } ) ;
112107 }
113- return isWebBluetoothSupported
108+ return isWebBluetoothSupported ;
114109 }
115110
116111 async requestDevice (
117112 registryItem : IDeviceRegistryItem
118113 ) : Promise < BluetoothDevice | undefined > {
119- const isWebBluetoothSupported = await this . checkWebBluetoothSupport ( )
114+ const isWebBluetoothSupported = await this . checkWebBluetoothSupport ( ) ;
120115 if ( isWebBluetoothSupported ) {
121116 const native = await navigator . bluetooth . requestDevice (
122117 registryItem . options
123118 ) ;
124119 return native ;
125- }
126- else {
120+ } else {
127121 return ;
128122 }
129123 }
@@ -146,15 +140,18 @@ export namespace BluetoothManager {
146140 public connected : Signal < this, boolean > ;
147141 public disconnected : Signal < this, boolean > ;
148142 public isDisposed : boolean ;
149- public contextCommands :Array < string > ;
143+ public contextCommands : Array < string > ;
150144
151145 constructor ( native : BluetoothDevice ) {
152146 this . connected = new Signal < this, boolean > ( this ) ;
153147 this . disconnected = new Signal < this, boolean > ( this ) ;
154148 this . isConnected = false ;
155149 this . isDisposed = false ;
156150 this . native = native ;
157- this . contextCommands = [ 'bluetooth-manager:disconnect-device' , 'bluetooth-manager:add-lego-movehub-control-panel' ]
151+ this . contextCommands = [
152+ 'bluetooth-manager:disconnect-device' ,
153+ 'bluetooth-manager:add-lego-movehub-control-panel'
154+ ] ;
158155 }
159156
160157 async connectAndGetAllServices ( ) : Promise <
@@ -164,40 +161,45 @@ export namespace BluetoothManager {
164161 this . isConnected = false ;
165162 this . disconnected . emit ( true ) ;
166163 } ) ;
167- const server = this . native . gatt
164+ const server = this . native . gatt ;
168165 if ( server ) {
169166 const timeout = 5000 ;
170167 const connectWithTimeout = new Promise < void > ( ( resolve , reject ) => {
171- const timeoutId = setTimeout ( ( ) => {
172- reject (
173- new Error ( 'Connection to GATT server timed out' ) ) ;
168+ const timeoutId = setTimeout ( ( ) => {
169+ reject ( new Error ( 'Connection to GATT server timed out' ) ) ;
174170 server . disconnect ( ) ;
175171 this . dispose ( ) ;
176172 } , timeout ) ;
177173
178- server . connect ( ) . then ( async ( ) => {
179- clearTimeout ( timeoutId ) ;
180- resolve ( ) ;
181- this . isConnected = true ;
182- this . connected . emit ( true ) ;
183- } )
184- . catch ( ( error ) => {
174+ server
175+ . connect ( )
176+ . then ( async ( ) => {
177+ clearTimeout ( timeoutId ) ;
178+ resolve ( ) ;
179+ this . isConnected = true ;
180+ this . connected . emit ( true ) ;
181+ } )
182+ . catch ( error => {
185183 server . disconnect ( ) ;
186184 reject ( error ) ;
187185 } ) ;
188186 } ) ;
189- await connectWithTimeout
187+ await connectWithTimeout ;
190188 if ( server . connected === true ) {
191189 const services = await server . getPrimaryServices ( ) ;
192190 if ( ! services || services . length === 0 ) {
193- throw new Error ( 'Server exists but no service found on the device.' ) ;
194- } else { return services ; }
195- }
196- else {
197- throw new Error ( 'There is no connection to server. No attempt to get a service.' )
191+ throw new Error (
192+ 'Server exists but no service found on the device.'
193+ ) ;
194+ } else {
195+ return services ;
196+ }
197+ } else {
198+ throw new Error (
199+ 'There is no connection to server. No attempt to get a service.'
200+ ) ;
198201 }
199- }
200- else {
202+ } else {
201203 throw new Error ( 'Server is not defined.' ) ;
202204 }
203205 }
@@ -256,7 +258,7 @@ export namespace BluetoothManager {
256258 if ( service ) {
257259 return service . getCharacteristics ( ) ;
258260 } else {
259- throw new Error ( 'The requested service is not available.' )
261+ throw new Error ( 'The requested service is not available.' ) ;
260262 }
261263 }
262264
@@ -267,7 +269,6 @@ export namespace BluetoothManager {
267269 const service = await this . getService ( serviceUUID ) ;
268270 if ( service ) {
269271 return service . getCharacteristic ( characteristicUUID ) ;
270-
271272 } else {
272273 throw new Error ( 'The requested service is not available.' ) ;
273274 }
0 commit comments