Attempt a workaround for the bad response issue #77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See microbit-foundation/python-editor-v3#89
Ultimately this needs a fix in DAPLink to clear the queue when the host reconnects but that won't have much impact on existing devices.
If this gets merged then we should also merge it into the apps branch and remove the PAUSED state that more explicitly models the workaround there.
Repro steps via the demo:
Now we have this fix, I think if apps want visibility based disconnection they should do it themselves. The beforeunload stuff is also perhaps unnecessary and unreliable.
Plan to integrate this / behaviour changes
Because the disconnect on tab visibility has been a long-standing workaround, I think we should move this fix to the apps branch and integrate it with the changes there that introduce a PAUSED state (these are breaking and targetting 1.0). These disconnects play an important role in letting folks use multiple micro:bit apps. MakeCode will disconnect from USB in a similar way (though I think not if it's seen serial data). But I'll discuss this with product folks too.
From a library point of view, transitioning to PAUSED can then be an optional feature supported uniformly across USB and Bluetooth. Then when we upgrade the Python Editor we can just not clear the serial console on transitions to PAUSED.