@@ -420,7 +420,7 @@ class ReplJS{
420420 }
421421
422422
423- bleDisconnect ( ) {
423+ async bleDisconnect ( ) {
424424 if ( REPL . DEBUG_CONSOLE_ON ) console . log ( "BLE Disconnected" ) ;
425425 REPL . BLE_DISCONNECT_TIME = Date . now ( ) ;
426426 REPL . WRITEBLE = undefined ;
@@ -434,6 +434,8 @@ class ReplJS{
434434 REPL . RUN_BUSY = false ;
435435 REPL . STOP = false ;
436436 REPL . BUSY = false ;
437+ //bug must wait for a bit before trying to reconnect. Known Web Bluetooth bug.
438+ await new Promise ( r => setTimeout ( r , 300 ) ) ;
437439 REPL . bleReconnect ( ) ;
438440 }
439441
@@ -453,14 +455,14 @@ class ReplJS{
453455 const server = await this . connectWithTimeout ( this . BLE_DEVICE , 10000 ) ; //wait for 10seconds to see if it reconnects
454456 //await new Promise(r => setTimeout(r, 300));
455457
456- let attempts = 7 ;
458+ let attempts = 10 ;
457459 for ( let i = 0 ; i < attempts ; i ++ ) {
458460 try {
459461 this . btService = await server . getPrimaryService ( this . UART_SERVICE_UUID ) ;
460462 break ;
461463 } catch ( e ) {
462464 if ( / N o S e r v i c e s f o u n d / . test ( e . message ) && i < attempts - 1 ) {
463- await new Promise ( r => setTimeout ( r , 300 ) ) ;
465+ await new Promise ( r => setTimeout ( r , 400 ) ) ;
464466 } else {
465467 throw e ;
466468 }
@@ -1834,6 +1836,8 @@ class ReplJS{
18341836
18351837 this . BLE_DEVICE = undefined ; //just in case we were connected before.
18361838
1839+ let UserCancled = false ;
1840+
18371841 var elapseTime = ( Date . now ( ) - this . BLE_DISCONNECT_TIME ) / 1000 ;
18381842 if ( elapseTime > 60 ) {
18391843 await window . alertMessage ( "Error while detecting bluetooth devices. \nPlease refresh the browser and try again." )
@@ -1851,9 +1855,16 @@ class ReplJS{
18511855 this . BLE_DEVICE = device ;
18521856 } )
18531857 . catch ( error => {
1858+ if ( error . code == 8 ) {
1859+ UserCancled = true ;
1860+ return ;
1861+ }
18541862 window . alertMessage ( "*Error connecting to XRP. Please refresh this page and try again" ) ;
18551863 console . log ( 'Error: ' + error ) ;
18561864 } ) ;
1865+
1866+ if ( UserCancled ) return ;
1867+
18571868 document . getElementById ( "IdWaiting_TitleText" ) . innerText = 'Connecting to XRP...' ;
18581869 UIkit . modal ( document . getElementById ( "IDWaitingParent" ) ) . show ( ) ;
18591870
0 commit comments