diff --git a/app_state.py b/app_state.py index a93debc..0d4d40b 100644 --- a/app_state.py +++ b/app_state.py @@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it. import configparser import os -VERSION = "0.0.0.080" +VERSION = "0.0.0.081" PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties") DEFAULT_GRID_SIZE = 10 DEFAULT_ADD_TIMESTAMP = True diff --git a/connect_dialog.py b/connect_dialog.py index 8bb4957..47813f6 100644 --- a/connect_dialog.py +++ b/connect_dialog.py @@ -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("", lambda e: self._do_connect()) self._dlg.bind("", 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()