fix(gui): window z-order + lifecycle (B1-B10) (#2)
* fix(gui): correct window z-order and lifecycle bugs (B1-B10)
Sintomi risolti:
- S1: le finestre del plugin sparivano dietro Electrum
- S2: alcuni meccanismi funzionavano solo dopo chiusura+pulizia di Electrum
La logica di business resta BYTE-IDENTICA (nessuna modifica a bal/core/*):
cambiano solo parent, modalità, ciclo di vita, cleanup e presentazione.
Nuovo modulo bal/gui/qt/window_utils.py con helper centralizzati:
- top_level_of, bring_to_front, stop_thread, show_modal, show_on_top
Fix per bug:
- B1: self.parent -> self._bal_parent (dialogs/lists/widgets); parent = top_level_of(parent)
- B2/B9: .show() -> show_on_top()/show_modal()/bring_to_front()
- B3: init a caldo _setup_window() replica load_wallet (niente 'restart Electrum')
- B4: chiave finestra stabile _window_key() = id(window)
- B5: on_close riscritto (no except:pass, log per-step, reset stato)
- B6: BalBlockingWaitingDialog ripristina processEvents()
- B7/B8: closeEvent/hideEvent -> stop_thread() (stop+wait) + super()
- B10: uso di window.tools_menu (no ricerca per titolo localizzato '&Tools')
Test: smoke + gui_fixes (regressione B1-B10) + external_zip tutti verdi.
Doc aggiornata: DIAGNOSI_GUI.md marca B1-B10 come FIXED.
* fix(gui): do not kill task thread on dialog close (download list regression)
The B7/B8 change added stop_thread() to BalDialog.closeEvent/hideEvent.
But Electrum's TaskThread.on_done runs cb_done (often self.accept, which
closes the waiting dialog) BEFORE cb_result (on_success, which updates the
will-executor list). Stopping/joining the thread inside closeEvent therefore
tore the thread down before on_success ran, silently dropping the downloaded
will-executor list ('Download List' appeared to do nothing).
Restore the original safe behavior: the base BalDialog no longer stops the
thread on close/hide (matching the original plugin, which deliberately left
this commented out). Long-lived dialogs that own a thread still stop it
explicitly in their own handlers.
Adds a regression test asserting BalDialog.closeEvent/hideEvent never call
stop_thread.
* fix(gui): restore modal exec for waiting dialog + surface download failures
Two changes to fix 'Download List' doing nothing:
1) BalWaitingDialog.exe() now keeps the original application-modal exec()
(only adding raise/activate for visibility). The earlier switch to
window-modal could interfere with how the TaskThread result (on_success,
which populates the will-executor list) is delivered via a queued signal
while the modal loop is spinning.
2) BalWindow.download_list now logs how many entries were received and, when
the result is empty (the core download_list swallows errors and returns {}),
shows a warning to the user instead of failing silently. This makes any
future network/parse failure visible in the Electrum log and to the user.
Business logic in bal/core/* is unchanged.
* fix(gui): show the real download error reason in the warning popup
When 'Download List' fails, the core download_list returns {} and the cause
was only visible in the Electrum log (which is hard to capture). The GUI now
re-issues the same raw request when the result is empty and shows the actual
exception/reason in the warning popup (e.g. SSL error, timeout, empty server
response). Pure GUI-side diagnostics; bal/core/* logic unchanged.
* fix(gui): download will-executor list synchronously like the original
ROOT CAUSE: the original plugin's 'Download List' button called
Willexecutors.download_list() DIRECTLY on the GUI thread
(qt.py: WillExecutorWidget.download_list). The refactor instead routed the
button through BalWaitingDialog + TaskThread. Electrum's
Network.send_http_on_proxy behaves differently depending on the calling
thread, and on the user's setup the TaskThread path timed out ('No response
from the server'), while the original direct call worked fine.
FIX: WillExecutorWidget.download_list now performs the same direct,
synchronous download as the original, updates and saves the list, and shows a
warning only on genuine failure. The wizard download path (which the original
also ran via TaskThread) is left unchanged.
Compared against upstream original source (kaibot/bal-electrum-plugin):
send_request, handle_response, download_list core logic are byte-identical;
only the GUI call site is restored to the original behaviour.
* diag(gui): detailed download diagnostics + hardcoded-URL fallback
The will-executor download still times out on the user's setup even with the
direct (original-style) GUI-thread call, and the URL/request are byte-identical
to the working original. To pinpoint the real cause, the Download List button
now:
- logs whether a Network instance is present;
- tries the configured WELIST_SERVER URL AND falls back to the original
hardcoded https://welist.bitcoin-after.life/ endpoint (so a stale/bad config
value can't break it);
- shows the EXACT URL(s) tried and the precise exception per attempt in the
warning popup instead of a generic timeout message.
bal/core networking remains unchanged.
* diag(gui): add direct-HTTPS control probe to download diagnostics
When the Electrum-network download fails, also run a plain urllib HTTPS GET
(bypassing Electrum's Network/proxy layer) and show its result in the popup.
This distinguishes a real connectivity/DNS/firewall problem from an
Electrum-network-state problem, so we can finally pinpoint why the request
times out only in this build.
* fix(gui): unify wizard + button download on one synchronous path with diagnostics
The 'No response from the server (timeout?)' popup was coming from the WIZARD
download path in window.py (BalWaitingDialog + TaskThread), which was never
switched to the original direct call - only the list button had been.
Both paths now share BalWindow.fetch_will_executors_list(): a direct,
synchronous GUI-thread download (like the original), trying the configured
server then the hardcoded fallback, with full diagnostics (exact URL/error per
attempt + a direct-HTTPS control probe) shown in the failure popup.
This both fixes the wizard timeout and guarantees the same diagnostic popup
('Details (via Electrum network)' + 'Direct connection test') regardless of
which UI entry point is used.
* fix(gui): clean up will-executor download (waiting dialog + simple message)
Root cause of the 'download not working' reports was environmental (the user's
network/ISP was resetting the connection to the IPv6/IPv4 host; a VPN fixes
it), NOT a plugin bug. Final cleanup of the diagnostic code:
- download_list (button + wizard) again uses BalWaitingDialog + TaskThread so
the GUI is not frozen and shows a 'Downloading will-executors list...' dialog.
- Keep the configured + hardcoded-fallback server URLs and detailed per-attempt
diagnostics, but write them to the Electrum log only.
- On failure the user now sees a simple English message explaining it is most
likely a connection/firewall issue (a VPN often helps), instead of a technical
timeout/exception dump.
- Removed the urllib control probe from the user-facing popup.
bal/core networking unchanged.
---------
Co-authored-by: GenSpark AI Developer <ai@genspark.dev>
This commit is contained in:
committed by
steal
parent
4711f7de62
commit
c8a9cbfc0a
@@ -145,7 +145,9 @@ class BalWindow:
|
||||
|
||||
def show_willexecutor_dialog(self):
|
||||
self.willexecutor_dialog = WillExecutorDialog(self)
|
||||
self.willexecutor_dialog.show()
|
||||
# Keep it in front of Electrum (window-modal) instead of letting it
|
||||
# fall behind the main window.
|
||||
show_on_top(self.willexecutor_dialog)
|
||||
|
||||
def create_heirs_tab(self):
|
||||
if not self.heirs:
|
||||
@@ -563,7 +565,8 @@ class BalWindow:
|
||||
_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)
|
||||
)
|
||||
else:
|
||||
d.show()
|
||||
# Electrum's own TxDialog: keep it in front of the main window.
|
||||
show_on_top(d, modal_to_window=False)
|
||||
return d
|
||||
|
||||
def show_transaction(self, tx=None, txid=None, parent=None):
|
||||
@@ -662,19 +665,48 @@ class BalWindow:
|
||||
return password
|
||||
|
||||
def on_close(self):
|
||||
# Wallet is closing: run the closing "build will" task and tear down
|
||||
# the plugin's tabs/menu. Each step is isolated so that one failure
|
||||
# does not leave the GUI half-initialised (which previously forced the
|
||||
# user to restart Electrum). Errors are logged instead of silently
|
||||
# swallowed.
|
||||
if self.disable_plugin:
|
||||
return
|
||||
|
||||
# 1) Business logic: build/save the will on close (unchanged behaviour).
|
||||
try:
|
||||
if not self.disable_plugin:
|
||||
close_window = BalBuildWillDialog(self)
|
||||
close_window.build_will_task()
|
||||
self.save_willitems()
|
||||
self.heirs_tab.close()
|
||||
self.will_tab.close()
|
||||
self.tools_menu.removeAction(self.tools_menu.willexecutors_action)
|
||||
self.window.toggle_tab(self.heirs_tab)
|
||||
self.window.toggle_tab(self.will_tab)
|
||||
self.window.tabs.update()
|
||||
except Exception:
|
||||
pass
|
||||
close_window = BalBuildWillDialog(self)
|
||||
close_window.build_will_task()
|
||||
self.save_willitems()
|
||||
except Exception as e:
|
||||
_logger.error(f"on_close: build/save will failed: {e}")
|
||||
|
||||
# 2) GUI teardown - each action guarded independently.
|
||||
def _safe(desc, fn):
|
||||
try:
|
||||
fn()
|
||||
except Exception as e:
|
||||
_logger.error(f"on_close: {desc} failed: {e}")
|
||||
|
||||
_safe("close heirs tab", lambda: self.heirs_tab.close())
|
||||
_safe("close will tab", lambda: self.will_tab.close())
|
||||
_safe(
|
||||
"remove willexecutors menu action",
|
||||
lambda: self.tools_menu.removeAction(
|
||||
self.tools_menu.willexecutors_action
|
||||
),
|
||||
)
|
||||
_safe("toggle heirs tab off", lambda: self.window.toggle_tab(self.heirs_tab))
|
||||
_safe("toggle will tab off", lambda: self.window.toggle_tab(self.will_tab))
|
||||
_safe("refresh tabs", lambda: self.window.tabs.update())
|
||||
|
||||
# 3) Reset in-memory state so re-enabling/re-opening starts clean.
|
||||
self.willitems = {}
|
||||
self.will = {}
|
||||
self.heirs = {}
|
||||
self.willexecutors = {}
|
||||
self.disable_plugin = True
|
||||
self.ok = False
|
||||
|
||||
def ask_password_and_sign_transactions(self, callback=None):
|
||||
def on_success(txs):
|
||||
@@ -863,20 +895,82 @@ class BalWindow:
|
||||
_logger.error(f"impossible to update will_executor_list_widget {e}")
|
||||
self.will_executors.update()
|
||||
|
||||
def fetch_will_executors_list(self, old_willexecutors):
|
||||
"""Download the will-executor list (runs inside the TaskThread worker).
|
||||
|
||||
Tries the configured server first, then the original hardcoded endpoint,
|
||||
so a stale/bad config value cannot break the download. Detailed
|
||||
per-attempt diagnostics are written to the Electrum log only; the user
|
||||
sees a simple message. No business logic in ``bal.core`` is changed.
|
||||
|
||||
Returns the downloaded dict (empty ``{}`` on failure).
|
||||
"""
|
||||
chainname = BalPlugin.chainname
|
||||
configured = self.bal_plugin.WELIST_SERVER.get()
|
||||
candidates = []
|
||||
for base in (configured, "https://welist.bitcoin-after.life/"):
|
||||
if not base:
|
||||
continue
|
||||
base = base if base.endswith("/") else base + "/"
|
||||
url = f"{base}data/{chainname}?page=0&limit=100"
|
||||
if url not in candidates:
|
||||
candidates.append(url)
|
||||
|
||||
result = {}
|
||||
net = Network.get_instance()
|
||||
_logger.info(f"fetch_will_executors_list: network present = {net is not None}")
|
||||
for url in candidates:
|
||||
_logger.info(f"fetch_will_executors_list: trying {url}")
|
||||
try:
|
||||
resp = Willexecutors.send_request("get", url, timeout=20)
|
||||
_logger.info(
|
||||
f"fetch_will_executors_list: resp type={type(resp).__name__} "
|
||||
f"len={len(resp) if hasattr(resp, '__len__') else 'n/a'}"
|
||||
)
|
||||
if resp:
|
||||
result = resp
|
||||
for w in result:
|
||||
if w not in ("status", "url"):
|
||||
Willexecutors.initialize_willexecutor(
|
||||
result[w], w, None,
|
||||
old_willexecutors.get(w, None),
|
||||
)
|
||||
break
|
||||
_logger.warning(f"fetch_will_executors_list: {url} -> empty response")
|
||||
except Exception as e:
|
||||
_logger.error(
|
||||
f"fetch_will_executors_list: {url} -> {type(e).__name__}: {e}"
|
||||
)
|
||||
return result
|
||||
|
||||
# Simple, user-facing message shown when the download fails for any reason
|
||||
# (the technical cause is in the Electrum log).
|
||||
DOWNLOAD_FAILED_MESSAGE = (
|
||||
"Could not download the will-executors list.\n\n"
|
||||
"This is usually caused by your internet connection or a firewall, "
|
||||
"not by the plugin. Please check your connection (a VPN often helps) "
|
||||
"and try again."
|
||||
)
|
||||
|
||||
def download_list(self, willexecutors, fn_on_success, fn_on_failure=None):
|
||||
|
||||
def on_success(result):
|
||||
self.willexecutors.update(result)
|
||||
fn_on_success(result)
|
||||
|
||||
def on_failure(exec_info):
|
||||
fn_on_failure(exec_info)
|
||||
|
||||
if fn_on_failure is None:
|
||||
fn_on_failure = log_error
|
||||
welist_server = self.bal_plugin.WELIST_SERVER.get()
|
||||
task = partial(Willexecutors.download_list, willexecutors, welist_server)
|
||||
msg = _(f"Downloading willexecutors list from {welist_server}")
|
||||
|
||||
def task():
|
||||
return self.fetch_will_executors_list(willexecutors)
|
||||
|
||||
def on_success(result):
|
||||
if result:
|
||||
self.willexecutors.update(result)
|
||||
fn_on_success(result)
|
||||
else:
|
||||
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
||||
|
||||
def on_failure(exc_info):
|
||||
_logger.error(f"download_list failed: {exc_info}")
|
||||
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
||||
|
||||
msg = _("Downloading will-executors list...")
|
||||
self.waiting_dialog = BalWaitingDialog(
|
||||
self, msg, task, on_success, on_failure, exe=False
|
||||
)
|
||||
@@ -933,7 +1027,9 @@ class BalWindow:
|
||||
|
||||
def preview_modal_dialog(self):
|
||||
self.dw = WillDetailDialog(self)
|
||||
self.dw.show()
|
||||
# This dialog is meant to be modal (per its name); show it on top so it
|
||||
# cannot disappear behind the Electrum window.
|
||||
show_on_top(self.dw)
|
||||
|
||||
def update_all(self):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user