1
0

qt hww show_settings_dialog: don't scan devices in GUI thread

Just makes sense in general.
Also, previously, the GUI would freeze if right after startup the user
clicked the hww status bar icon (especially with multiple hww connected).
This commit is contained in:
SomberNight
2020-04-01 18:42:06 +02:00
parent 276631fab7
commit e6d43b60fa
8 changed files with 40 additions and 13 deletions

View File

@@ -36,6 +36,7 @@ from electrum.storage import get_derivation_used_for_hw_device_encryption
from electrum.keystore import Xpub, Hardware_KeyStore
if TYPE_CHECKING:
import threading
from electrum.wallet import Abstract_Wallet
from electrum.base_wizard import BaseWizard
@@ -210,6 +211,11 @@ class HardwareHandlerBase:
if hasattr(self.win, 'wallet'):
return self.win.wallet
def get_gui_thread(self) -> Optional['threading.Thread']:
if self.win is not None:
if hasattr(self.win, 'gui_thread'):
return self.win.gui_thread
def update_status(self, paired: bool) -> None:
pass

View File

@@ -67,6 +67,7 @@ class QtHandlerBase(HardwareHandlerBase, QObject, Logger):
def __init__(self, win: Union[ElectrumWindow, InstallWizard], device: str):
QObject.__init__(self)
Logger.__init__(self)
assert win.gui_thread == threading.current_thread(), 'must be called from GUI thread'
self.clear_signal.connect(self.clear_dialog)
self.error_signal.connect(self.error_dialog)
self.message_signal.connect(self.message_dialog)
@@ -254,6 +255,7 @@ class QtPluginBase(object):
keystore: 'Hardware_KeyStore') -> Optional[str]:
'''This dialog box should be usable even if the user has
forgotten their PIN or it is in bootloader mode.'''
assert window.gui_thread != threading.current_thread(), 'must not be called from GUI thread'
device_id = self.device_manager().xpub_id(keystore.xpub)
if not device_id:
try:
@@ -264,7 +266,10 @@ class QtPluginBase(object):
return device_id
def show_settings_dialog(self, window: ElectrumWindow, keystore: 'Hardware_KeyStore') -> None:
device_id = self.choose_device(window, keystore)
# default implementation (if no dialog): just try to connect to device
def connect():
device_id = self.choose_device(window, keystore)
keystore.thread.add(connect)
def add_show_address_on_hw_device_button_for_receive_addr(self, wallet: 'Abstract_Wallet',
keystore: 'Hardware_KeyStore',

View File

@@ -208,9 +208,13 @@ class QtPlugin(QtPluginBase):
menu.addAction(_("Show on {}").format(device_name), show_address)
def show_settings_dialog(self, window, keystore):
device_id = self.choose_device(window, keystore)
if device_id:
SettingsDialog(window, self, keystore, device_id).exec_()
def connect():
device_id = self.choose_device(window, keystore)
return device_id
def show_dialog(device_id):
if device_id:
SettingsDialog(window, self, keystore, device_id).exec_()
keystore.thread.add(connect, on_success=show_dialog)
def request_trezor_init_settings(self, wizard, method, device):
vbox = QVBoxLayout()

View File

@@ -84,9 +84,13 @@ class QtPlugin(QtPluginBase):
menu.addAction(_("Show on {}").format(device_name), show_address)
def show_settings_dialog(self, window, keystore):
device_id = self.choose_device(window, keystore)
if device_id:
SettingsDialog(window, self, keystore, device_id).exec_()
def connect():
device_id = self.choose_device(window, keystore)
return device_id
def show_dialog(device_id):
if device_id:
SettingsDialog(window, self, keystore, device_id).exec_()
keystore.thread.add(connect, on_success=show_dialog)
def request_safe_t_init_settings(self, wizard, method, device):
vbox = QVBoxLayout()

View File

@@ -182,9 +182,13 @@ class QtPlugin(QtPluginBase):
menu.addAction(_("Show on {}").format(device_name), show_address)
def show_settings_dialog(self, window, keystore):
device_id = self.choose_device(window, keystore)
if device_id:
SettingsDialog(window, self, keystore, device_id).exec_()
def connect():
device_id = self.choose_device(window, keystore)
return device_id
def show_dialog(device_id):
if device_id:
SettingsDialog(window, self, keystore, device_id).exec_()
keystore.thread.add(connect, on_success=show_dialog)
def request_trezor_init_settings(self, wizard, method, device_id):
vbox = QVBoxLayout()