diff --git a/plugins/keepkey/keepkey.py b/plugins/keepkey/keepkey.py index 5b1515947..bf52a8680 100644 --- a/plugins/keepkey/keepkey.py +++ b/plugins/keepkey/keepkey.py @@ -181,19 +181,26 @@ class KeepKeyPlugin(HW_PluginBase): t = threading.Thread(target=self._initialize_device_safe, args=(settings, method, device_id, wizard, handler)) t.setDaemon(True) t.start() - wizard.loop.exec_() + exit_code = wizard.loop.exec_() + if exit_code != 0: + # this method (initialize_device) was called with the expectation + # of leaving the device in an initialized state when finishing. + # signal that this is not the case: + raise UserCancelled() wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f) def _initialize_device_safe(self, settings, method, device_id, wizard, handler): + exit_code = 0 try: self._initialize_device(settings, method, device_id, wizard, handler) except UserCancelled: - pass + exit_code = 1 except BaseException as e: traceback.print_exc(file=sys.stderr) handler.show_error(str(e)) + exit_code = 1 finally: - wizard.loop.exit(0) + wizard.loop.exit(exit_code) def _initialize_device(self, settings, method, device_id, wizard, handler): item, label, pin_protection, passphrase_protection = settings diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py index d5cd33d2b..575aba5c9 100644 --- a/plugins/trezor/trezor.py +++ b/plugins/trezor/trezor.py @@ -202,19 +202,26 @@ class TrezorPlugin(HW_PluginBase): t = threading.Thread(target=self._initialize_device_safe, args=(settings, method, device_id, wizard, handler)) t.setDaemon(True) t.start() - wizard.loop.exec_() + exit_code = wizard.loop.exec_() + if exit_code != 0: + # this method (initialize_device) was called with the expectation + # of leaving the device in an initialized state when finishing. + # signal that this is not the case: + raise UserCancelled() wizard.choice_dialog(title=_('Initialize Device'), message=msg, choices=choices, run_next=f) def _initialize_device_safe(self, settings, method, device_id, wizard, handler): + exit_code = 0 try: self._initialize_device(settings, method, device_id, wizard, handler) except UserCancelled: - pass + exit_code = 1 except BaseException as e: traceback.print_exc(file=sys.stderr) handler.show_error(str(e)) + exit_code = 1 finally: - wizard.loop.exit(0) + wizard.loop.exit(exit_code) def _initialize_device(self, settings, method, device_id, wizard, handler): item, label, pin_protection, passphrase_protection, recovery_type = settings