Keep session alive across transient device disappearance#79
Closed
ImmortalDragonm wants to merge 1 commit into
Closed
Keep session alive across transient device disappearance#79ImmortalDragonm wants to merge 1 commit into
ImmortalDragonm wants to merge 1 commit into
Conversation
After importing an .entlayout, the export actions (and other layout-gated UI) could go dead: clicking Export did nothing and opened no file dialog. The menu items are enabled only while a keyboard is connected (self.layout.is_some()), so the layout had been cleared out from under them. A large import writes a burst of HID transactions (keymap for every layer and key, encoders, the macro buffer, combos). Under that load the board briefly re-enumerates on USB. The very next device scan sees an empty list and immediately tore the whole session down (layout = None, selected device = None) via clear_connected_keyboard_state, and on Linux the follow-up scan could then hit the udev-rules guard and refuse to auto-reconnect, leaving export permanently greyed out until a manual re-select. Debounce the disappearance: require the selected device to stay absent for three consecutive scans (~3s) before clearing state. While within the window the device list, selection and layout are preserved untouched, so export and other actions keep working. When the device reappears after a transient absence the previously opened HID handle is stale, so force a reconnect to reopen it even when a layout is still present. A genuine unplug still surfaces as "No device detected" after the short debounce window. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S2vEWd6sxhZLCa4PULq5Ti
Contributor
Author
|
Closing: this was based on a wrong hypothesis. Reproducing the reported "menu dead after import" on real hardware showed the device does not disappear/re-enumerate during import (layout stays connected the whole time) — the actual cause is synchronous native file dialogs blocking the UI thread, fixed in #80. This debounce addresses a transient-disappearance scenario that was never actually observed, and it delays the genuine-unplug notice by ~3s, so it's not worth merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
After importing an
.entlayout, the layout-image /.entlayoutExport actions could go completely dead — clicking Export did nothing and no file dialog appeared.Root cause
The export menu items (and other layout-gated UI) are enabled only while a keyboard is connected —
self.layout.is_some(). So a dead Export button means the layout had been cleared out from under it.A large import writes a burst of HID transactions (keymap for every layer × key, encoders, the macro buffer, combos). Under that load the board briefly re-enumerates on USB. The very next device scan sees an empty list and immediately tears the whole session down (
clear_connected_keyboard_state→layout = None,selected_device = None). On Linux the follow-up scan can then hit the udev-rules guard and refuse to auto-reconnect, leaving Export greyed out until the user manually re-selects the device.Fix
Debounce the disappearance in
apply_device_scan_result:A genuine unplug still surfaces as "No device detected" after the short debounce window.
Testing
cargo build,cargo test(59 passed).🤖 Generated with Claude Code