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
83
83
const currentStatus = this . status ;
84
84
if ( e . status !== ConnectionStatus . CONNECTED ) {
85
85
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
+ }
87
90
} else {
88
91
this . status = ConnectionStatus . DISCONNECTED ;
89
92
if (
Original file line number Diff line number Diff line change @@ -564,11 +564,10 @@ class MicrobitWebUSBConnectionImpl
564
564
protected eventActivated ( type : string ) : void {
565
565
switch ( type as keyof SerialConnectionEventMap ) {
566
566
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 ) {
569
569
this . startSerialInternal ( ) ;
570
570
}
571
- // Allows for reinstating serial after flashing.
572
571
this . addedListeners . serialdata ++ ;
573
572
break ;
574
573
}
@@ -578,8 +577,10 @@ class MicrobitWebUSBConnectionImpl
578
577
protected async eventDeactivated ( type : string ) {
579
578
switch ( type as keyof SerialConnectionEventMap ) {
580
579
case "serialdata" : {
581
- this . stopSerialInternal ( ) ;
582
580
this . addedListeners . serialdata -- ;
581
+ if ( ! this . addedListeners . serialdata ) {
582
+ this . stopSerialInternal ( ) ;
583
+ }
583
584
break ;
584
585
}
585
586
}
You can’t perform that action at this time.
0 commit comments