Skip to content

Conversation

@takaokouji
Copy link

Summary

When the Mesh V2 extension enters an error state (e.g., due to heartbeat failure or expired group), the GUI's connection status icon (the dot in the toolbox) was not updating correctly. This is because Blocks.jsx in the GUI only refreshes the status buttons upon receiving PERIPHERAL_CONNECTED or PERIPHERAL_DISCONNECTED events.

This PR ensures that PERIPHERAL_DISCONNECTED is always emitted when transitioning to the error state, forcing the GUI to update its status icon to the 'error' state (typically shown as an exclamation mark).

Implementation Details

  • Modified gui/scratch-vm/src/extensions/scratch3_mesh_v2/index.js:
    • Updated setConnectionState('error') to always emit PERIPHERAL_DISCONNECTED.
    • Added emission of PERIPHERAL_CONNECTION_LOST_ERROR when the previous state was connected.
  • Updated unit tests:
    • Adjusted expectations in test/unit/extension_mesh_v2.js and test/unit/extension_mesh_v2_issue66.js to match the new event emission sequence.
    • Added PERIPHERAL_CONNECTION_LOST_ERROR to the mock runtime in tests.

Test Coverage

  • test/unit/extension_mesh_v2.js: Added test cases for state transitions and verified event emission.
  • test/unit/extension_mesh_v2_issue66.js: Verified that expired group scenarios correctly emit the expected events.

Fixes #82

Co-Authored-By: Gemini noreply@google.com

takaokouji and others added 3 commits January 4, 2026 18:30
- Ensure GUI refreshes status icon by emitting PERIPHERAL_DISCONNECTED in 'error' state
- Emit PERIPHERAL_CONNECTION_LOST_ERROR when transitioning from 'connected' to 'error'
- Update unit tests to match new event emission behavior
- Add PERIPHERAL_CONNECTION_LOST_ERROR to mock runtime in tests

Fixes #82

Co-Authored-By: Gemini <noreply@google.com>
…ctions

- Introduced isExplicitDisconnect flag to distinguish between user-initiated
  disconnection and connection loss
- Emit PERIPHERAL_CONNECTION_LOST_ERROR when transitioning from 'connected'
  to 'disconnected' or 'error' unexpectedly
- Ensure PERIPHERAL_DISCONNECTED is emitted to refresh GUI status
- Updated unit tests to verify behavior for both explicit and unexpected
  disconnections

Co-Authored-By: Gemini <noreply@google.com>
@takaokouji takaokouji merged commit 74b5d9e into develop Jan 4, 2026
1 check passed
@takaokouji takaokouji deleted the fix/issue-82-mesh-v2-error-status branch January 4, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mesh V2: Heartbeat renewal failed (Group not found) does not update connection status in GUI

2 participants