Skip to content

Commit ba7aad9

Browse files
Merge pull request #64 from andreasgriffin/simplifications3
Simplify methods
2 parents e285410 + 8dc4d60 commit ba7aad9

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

bitcoin_usb/usb_gui.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,32 +158,27 @@ def _discover_bluetooth_devices(self) -> list[dict[str, Any]]:
158158
return discover_jade_ble_devices(scan_timeout=6.0)
159159

160160
@staticmethod
161-
def _is_jade_ble_device(selected_device: dict[str, Any]) -> bool:
162-
return (
163-
str(selected_device.get("type", "")).lower() == "jade"
164-
and str(selected_device.get("transport", "")).lower() == "bluetooth"
165-
)
166-
167-
@staticmethod
168-
def _is_usb_device(selected_device: dict[str, Any]) -> bool:
169-
transport = str(selected_device.get("transport", "usb")).lower()
170-
return transport != "bluetooth"
161+
def _is_bluetooth_device(selected_device: dict[str, Any]) -> bool:
162+
return str(selected_device.get("transport", "")).lower() == "bluetooth"
171163

172164
@staticmethod
173165
def _should_run_in_worker(selected_device: dict[str, Any]) -> bool:
174-
if USBGui._is_jade_ble_device(selected_device):
166+
if USBGui._is_bluetooth_device(selected_device):
167+
# BLE must run in a worker thread (otherwise it does not work on Windows).
175168
return True
176169
if platform.system() == "Darwin":
170+
# macOS USB is kept on the caller/main thread to avoid crashes.
177171
return False
178-
return USBGui._is_usb_device(selected_device)
172+
# Linux/Windows USB runs in a worker thread.
173+
return True
179174

180175
def _with_device(self, selected_device: dict[str, Any], operation: Callable[[USBDevice], T]) -> T | None:
181176
"""
182177
Run one hardware-wallet operation with the required threading model.
183178
184179
- macOS USB: keep calls on the caller/main thread to avoid crashes.
185180
- Linux/Windows USB: run calls in a worker thread.
186-
- Jade BLE: run calls in a worker thread for stable bleak behavior.
181+
- BLE: run calls in a worker thread, otherwise it doesnt work in Windows
187182
"""
188183

189184
def _run_operation() -> T:

0 commit comments

Comments
 (0)