File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
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,11 +564,10 @@ class MicrobitWebUSBConnectionImpl
564564 protected eventActivated ( type : string ) : void {
565565 switch ( type as keyof SerialConnectionEventMap ) {
566566 case "serialdata" : {
567- // Prevent starting serial when flashing.
568- if ( ! this . flashing ) {
567+ // Prevent starting serial if already started and when flashing.
568+ if ( ! this . addedListeners . serialdata && ! this . flashing ) {
569569 this . startSerialInternal ( ) ;
570570 }
571- // Allows for reinstating serial after flashing.
572571 this . addedListeners . serialdata ++ ;
573572 break ;
574573 }
@@ -578,8 +577,10 @@ class MicrobitWebUSBConnectionImpl
578577 protected async eventDeactivated ( type : string ) {
579578 switch ( type as keyof SerialConnectionEventMap ) {
580579 case "serialdata" : {
581- this . stopSerialInternal ( ) ;
582580 this . addedListeners . serialdata -- ;
581+ if ( ! this . addedListeners . serialdata ) {
582+ this . stopSerialInternal ( ) ;
583+ }
583584 break ;
584585 }
585586 }
You can’t perform that action at this time.
0 commit comments