File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,10 @@ class MicrobitRadioBridgeConnectionImpl
8383 const currentStatus = this . status ;
8484 if ( e . status !== ConnectionStatus . CONNECTED ) {
8585 this . setStatus ( e . status ) ;
86- this . serialSession ?. dispose ( ) ;
86+ if ( this . serialSessionOpen ) {
87+ // If the session is already closed we don't need to dispose.
88+ this . serialSession ?. dispose ( ) ;
89+ }
8790 } else {
8891 this . status = ConnectionStatus . DISCONNECTED ;
8992 if (
Original file line number Diff line number Diff line change @@ -564,6 +564,10 @@ class MicrobitWebUSBConnectionImpl
564564 protected eventActivated ( type : string ) : void {
565565 switch ( type as keyof SerialConnectionEventMap ) {
566566 case "serialdata" : {
567+ if ( this . addedListeners . serialdata ) {
568+ this . addedListeners . serialdata ++ ;
569+ break ;
570+ }
567571 // Prevent starting serial when flashing.
568572 if ( ! this . flashing ) {
569573 this . startSerialInternal ( ) ;
@@ -578,8 +582,10 @@ class MicrobitWebUSBConnectionImpl
578582 protected async eventDeactivated ( type : string ) {
579583 switch ( type as keyof SerialConnectionEventMap ) {
580584 case "serialdata" : {
581- this . stopSerialInternal ( ) ;
582585 this . addedListeners . serialdata -- ;
586+ if ( ! this . addedListeners . serialdata ) {
587+ this . stopSerialInternal ( ) ;
588+ }
583589 break ;
584590 }
585591 }
You can’t perform that action at this time.
0 commit comments