Fix connect dialog: button order and cancel-during-connection cleanup
Swap Connect/Cancel button order so Connect is the default (leftmost). Guard background thread against cancelled state so a cancelled connect does not leave the app in live mode. Cancel during connection now disconnects the session cleanly in a cleanup thread. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+21
-3
@@ -64,12 +64,12 @@ class ConnectDialog:
|
||||
btn_frame = ttk.Frame(frame)
|
||||
btn_frame.grid(row=row, column=0, columnspan=3, sticky="e", pady=(8, 0))
|
||||
|
||||
self._btn_connect = ttk.Button(btn_frame, text="Connect", command=self._do_connect)
|
||||
self._btn_connect.pack(side=tk.RIGHT, padx=(8, 0))
|
||||
|
||||
self._btn_cancel = ttk.Button(btn_frame, text="Cancel", command=self._do_cancel)
|
||||
self._btn_cancel.pack(side=tk.RIGHT)
|
||||
|
||||
self._btn_connect = ttk.Button(btn_frame, text="Connect", command=self._do_connect)
|
||||
self._btn_connect.pack(side=tk.RIGHT, padx=(0, 8))
|
||||
|
||||
self._host_entry.focus_set()
|
||||
self._dlg.bind("<Return>", lambda e: self._do_connect())
|
||||
self._dlg.bind("<Escape>", lambda e: self._do_cancel())
|
||||
@@ -110,8 +110,12 @@ class ConnectDialog:
|
||||
def _connect_worker(self, host, port, user, password):
|
||||
try:
|
||||
result = self._callback(host, port, user, password)
|
||||
if self._cancelled:
|
||||
return
|
||||
self._result = ("ok", result, host, port, user)
|
||||
except Exception as e:
|
||||
if self._cancelled:
|
||||
return
|
||||
self._result = ("error", str(e), host, port, user)
|
||||
|
||||
def _poll_connect(self):
|
||||
@@ -133,6 +137,20 @@ class ConnectDialog:
|
||||
|
||||
def _do_cancel(self):
|
||||
self._cancelled = True
|
||||
if self._thread is not None and self._thread.is_alive():
|
||||
# Connection attempt in progress — clean up after it finishes
|
||||
import app_state as _as
|
||||
def _cleanup():
|
||||
self._thread.join(timeout=5)
|
||||
if _as.device_session is not None and _as.live_mode:
|
||||
try:
|
||||
_as.device_session.disconnect()
|
||||
except Exception:
|
||||
pass
|
||||
_as.live_mode = False
|
||||
_as.device_session = None
|
||||
_as.connection_status = "offline"
|
||||
threading.Thread(target=_cleanup, daemon=True).start()
|
||||
self._dlg.destroy()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user