@@ -36,6 +36,10 @@ def run_on_mount(app: AppProtocol) -> None:
3636 app ._startup_stamp ("settings_loaded" )
3737
3838 app ._expanded_paths = set (settings .get ("expanded_nodes" , []))
39+ if settings .get ("debug_events_enabled" ):
40+ setter = getattr (app , "_set_debug_events_enabled" , None )
41+ if callable (setter ):
42+ setter (True )
3943 if "process_worker" in settings :
4044 app .services .runtime .process_worker = bool (settings .get ("process_worker" ))
4145 if "process_worker_warm_on_idle" in settings :
@@ -83,6 +87,9 @@ def run_on_mount(app: AppProtocol) -> None:
8387 app .object_tree .cursor_line = 0
8488 app ._update_section_labels ()
8589 maybe_restore_connection_screen (app )
90+ # Auto-connect to pending connection after driver install (if not already connecting)
91+ if app ._startup_connect_config is None :
92+ maybe_auto_connect_pending (app )
8693 app ._startup_stamp ("restore_checked" )
8794 if app ._debug_mode :
8895 app .call_after_refresh (app ._record_launch_ms )
@@ -224,6 +231,83 @@ def _get_restart_cache_path() -> Path:
224231 return Path (tempfile .gettempdir ()) / "sqlit-driver-install-restore.json"
225232
226233
234+ def maybe_auto_connect_pending (app : AppProtocol ) -> bool :
235+ """Auto-connect to a pending connection after driver install restart.
236+
237+ Returns True if a connection was initiated, False otherwise.
238+ """
239+ from sqlit .shared .core .debug_events import emit_debug_event
240+
241+ from sqlit .domains .connections .ui .restart_cache import (
242+ clear_restart_cache ,
243+ get_restart_cache_path ,
244+ )
245+
246+ cache_path = get_restart_cache_path ()
247+ emit_debug_event (
248+ "startup.pending_connection_check" ,
249+ cache_path = str (cache_path ),
250+ exists = cache_path .exists (),
251+ )
252+ if not cache_path .exists ():
253+ return False
254+
255+ emit_debug_event (
256+ "startup.pending_connection_found" ,
257+ contents = cache_path .read_text (),
258+ )
259+
260+ try :
261+ payload = json .loads (cache_path .read_text (encoding = "utf-8" ))
262+ except Exception as e :
263+ emit_debug_event ("startup.pending_connection_parse_error" , error = str (e ))
264+ clear_restart_cache ()
265+ return False
266+
267+ # Always clear cache after reading
268+ clear_restart_cache ()
269+
270+ # Check for version 2 pending_connection type
271+ if not isinstance (payload , dict ):
272+ emit_debug_event ("startup.pending_connection_invalid" , reason = "not a dict" )
273+ return False
274+ if payload .get ("version" ) != 2 :
275+ emit_debug_event ("startup.pending_connection_invalid" , reason = "wrong version" , version = payload .get ("version" ))
276+ return False
277+ if payload .get ("type" ) != "pending_connection" :
278+ emit_debug_event ("startup.pending_connection_invalid" , reason = "wrong type" , type = payload .get ("type" ))
279+ return False
280+
281+ connection_name = payload .get ("connection_name" )
282+ if not connection_name :
283+ emit_debug_event ("startup.pending_connection_invalid" , reason = "no connection_name" )
284+ return False
285+
286+ emit_debug_event (
287+ "startup.pending_connection_lookup" ,
288+ connection_name = connection_name ,
289+ available_connections = [getattr (c , "name" , None ) for c in app .connections ],
290+ )
291+
292+ # Find the connection by name
293+ config = next (
294+ (c for c in app .connections if getattr (c , "name" , None ) == connection_name ),
295+ None ,
296+ )
297+ if config is None :
298+ emit_debug_event ("startup.pending_connection_not_found" , connection_name = connection_name )
299+ return False
300+
301+ emit_debug_event ("startup.pending_connection_connecting" , connection_name = connection_name )
302+
303+ # Auto-connect after refresh (same pattern as startup_connect_config)
304+ def _connect_pending () -> None :
305+ app .connect_to_server (config )
306+
307+ app .call_after_refresh (_connect_pending )
308+ return True
309+
310+
227311def maybe_restore_connection_screen (app : AppProtocol ) -> None :
228312 """Restore an in-progress connection form after a driver-install restart."""
229313 cache_path = _get_restart_cache_path ()
@@ -239,14 +323,16 @@ def maybe_restore_connection_screen(app: AppProtocol) -> None:
239323 pass
240324 return
241325
326+ # Only handle version 1 (connection form restore), leave version 2 for maybe_auto_connect_pending
327+ if not isinstance (payload , dict ) or payload .get ("version" ) != 1 :
328+ return
329+
330+ # Clear cache only for version 1
242331 try :
243332 cache_path .unlink (missing_ok = True )
244333 except Exception :
245334 pass
246335
247- if not isinstance (payload , dict ) or payload .get ("version" ) != 1 :
248- return
249-
250336 values = payload .get ("values" )
251337 if not isinstance (values , dict ):
252338 return
0 commit comments