wizard hww: scan devices fewer times and move away from GUI thread
This commit is contained in:
@@ -401,7 +401,7 @@ class DeviceMgr(ThreadJob):
|
||||
def create_client(self, device: 'Device', handler: Optional['HardwareHandlerBase'],
|
||||
plugin: 'HW_PluginBase') -> Optional['HardwareClientBase']:
|
||||
# Get from cache first
|
||||
client = self.client_lookup(device.id_)
|
||||
client = self._client_by_id(device.id_)
|
||||
if client:
|
||||
return client
|
||||
client = plugin.create_client(device, handler)
|
||||
@@ -437,7 +437,7 @@ class DeviceMgr(ThreadJob):
|
||||
self._close_client(id_)
|
||||
|
||||
def _close_client(self, id_):
|
||||
client = self.client_lookup(id_)
|
||||
client = self._client_by_id(id_)
|
||||
self.clients.pop(client, None)
|
||||
if client:
|
||||
client.close()
|
||||
@@ -446,19 +446,20 @@ class DeviceMgr(ThreadJob):
|
||||
with self.lock:
|
||||
self.xpub_ids[xpub] = id_
|
||||
|
||||
def client_lookup(self, id_) -> Optional['HardwareClientBase']:
|
||||
def _client_by_id(self, id_) -> Optional['HardwareClientBase']:
|
||||
with self.lock:
|
||||
for client, (path, client_id) in self.clients.items():
|
||||
if client_id == id_:
|
||||
return client
|
||||
return None
|
||||
|
||||
def client_by_id(self, id_) -> Optional['HardwareClientBase']:
|
||||
def client_by_id(self, id_, *, scan_now: bool = True) -> Optional['HardwareClientBase']:
|
||||
'''Returns a client for the device ID if one is registered. If
|
||||
a device is wiped or in bootloader mode pairing is impossible;
|
||||
in such cases we communicate by device ID and not wallet.'''
|
||||
self.scan_devices()
|
||||
return self.client_lookup(id_)
|
||||
if scan_now:
|
||||
self.scan_devices()
|
||||
return self._client_by_id(id_)
|
||||
|
||||
@with_scan_lock
|
||||
def client_for_keystore(self, plugin: 'HW_PluginBase', handler: Optional['HardwareHandlerBase'],
|
||||
@@ -495,7 +496,7 @@ class DeviceMgr(ThreadJob):
|
||||
def client_by_xpub(self, plugin: 'HW_PluginBase', xpub, handler: 'HardwareHandlerBase',
|
||||
devices: Sequence['Device']) -> Optional['HardwareClientBase']:
|
||||
_id = self.xpub_id(xpub)
|
||||
client = self.client_lookup(_id)
|
||||
client = self._client_by_id(_id)
|
||||
if client:
|
||||
# An unpaired client might have another wallet's handler
|
||||
# from a prior scan. Replace to fix dialog parenting.
|
||||
@@ -511,7 +512,7 @@ class DeviceMgr(ThreadJob):
|
||||
# The wallet has not been previously paired, so let the user
|
||||
# choose an unpaired device and compare its first address.
|
||||
xtype = bip32.xpub_type(xpub)
|
||||
client = self.client_lookup(info.device.id_)
|
||||
client = self._client_by_id(info.device.id_)
|
||||
if client and client.is_pairable():
|
||||
# See comment above for same code
|
||||
client.handler = handler
|
||||
|
||||
Reference in New Issue
Block a user