Skip to content

Commit 8fe1fb4

Browse files
authored
Merge pull request #10718 from sashazykov/hw-wallet-reuse-message-dialog
hw_wallet/qt: reuse message dialog to fix lag between device prompts
2 parents 11f2201 + f3af41d commit 8fe1fb4

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

electrum/hw_wallet/qt.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def __init__(self, win: Union['ElectrumWindow', 'QENewWalletWizard'], device: st
8484
self.win = win
8585
self.device = device
8686
self.dialog = None
87+
self._dialog_label = None
88+
self._dialog_on_cancel = None
8789
self.done = threading.Event()
8890

8991
def top_level_window(self):
@@ -174,12 +176,22 @@ def word_dialog(self, msg):
174176

175177
MESSAGE_DIALOG_TITLE = None # type: Optional[str]
176178
def message_dialog(self, msg, on_cancel=None):
179+
# If a dialog is already open, update its text instead of rebuilding it.
180+
# A device emits one button request per output, and rebuilding the
181+
# window-modal dialog each time is slow and visibly janky on macOS
182+
# (the modal "sheet" animates closed/open between outputs). See #10718.
183+
if self.dialog is not None and self._dialog_on_cancel == on_cancel:
184+
self._dialog_label.setText(msg)
185+
if not self.dialog.isVisible(): # e.g. was hidden by a user "cancel"
186+
self.dialog.show()
187+
return
177188
self.clear_dialog()
178189
title = self.MESSAGE_DIALOG_TITLE
179190
if title is None:
180191
title = _('Please check your {} device').format(self.device)
181192
self.dialog = dialog = WindowModalDialog(self.top_level_window(), title)
182-
label = QLabel(msg)
193+
self._dialog_on_cancel = on_cancel
194+
self._dialog_label = label = QLabel(msg)
183195
label.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
184196
vbox = QVBoxLayout(dialog)
185197
vbox.addWidget(label)
@@ -197,6 +209,8 @@ def clear_dialog(self):
197209
if self.dialog:
198210
self.dialog.accept()
199211
self.dialog = None
212+
self._dialog_label = None
213+
self._dialog_on_cancel = None
200214

201215
def win_query_choice(self, msg: str, choices: Sequence[ChoiceItem]):
202216
try:

0 commit comments

Comments
 (0)