@@ -98,6 +98,7 @@ def __init__(
9898 self .exit_event = asyncio .Event ()
9999 self ._task : asyncio .Task | None = None
100100 self ._exit_poller = ExitPoller (self , exit_on_idle )
101+ self ._connected_event = asyncio .Event ()
101102
102103 @property
103104 def app_count (self ) -> int :
@@ -207,7 +208,7 @@ def exit_handler(signal_handler, stack_frame) -> None:
207208 self ._poller .start ()
208209
209210 if self .web_interface :
210- app = await run_web_interface ()
211+ app = await run_web_interface (self . _connected_event )
211212 try :
212213 self ._task = asyncio .create_task (self .connect ())
213214 finally :
@@ -241,6 +242,7 @@ async def _connect(self) -> None:
241242 retry = Retry ()
242243
243244 async for retry_count in retry :
245+ self ._connected_event .clear ()
244246 if self .exit_event .is_set ():
245247 break
246248 try :
@@ -325,19 +327,22 @@ async def run_messages() -> None:
325327 async def post_connect (self ) -> None :
326328 """Called immediately after connecting to server."""
327329 # Inform the server about our apps
328- apps = [
329- app .model_dump (include = {"name" , "slug" , "color" , "terminal" })
330- for app in self .config .apps
331- ]
332- if WINDOWS :
333- filter_apps = [app for app in apps if not app ["terminal" ]]
334- if filter_apps != apps :
335- log .warn (
336- "Sorry, textual-web does not currently support terminals on Windows"
337- )
338- apps = filter_apps
339-
340- await self .send (packets .DeclareApps (apps ))
330+ try :
331+ apps = [
332+ app .model_dump (include = {"name" , "slug" , "color" , "terminal" })
333+ for app in self .config .apps
334+ ]
335+ if WINDOWS :
336+ filter_apps = [app for app in apps if not app ["terminal" ]]
337+ if filter_apps != apps :
338+ log .warn (
339+ "Sorry, textual-web does not currently support terminals on Windows"
340+ )
341+ apps = filter_apps
342+
343+ await self .send (packets .DeclareApps (apps ))
344+ finally :
345+ self ._connected_event .set ()
341346
342347 async def send (self , packet : Packet ) -> bool :
343348 """Send a packet.
0 commit comments