home · contact · privacy
From Client.connect thread, move anything not measurably blocking UI back into main...
authorChristian Heller <c.heller@plomlompom.de>
Thu, 2 Oct 2025 18:28:14 +0000 (20:28 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 2 Oct 2025 18:28:14 +0000 (20:28 +0200)
src/ircplom/client.py

index 2714cccd4d50d71d65227edfd2ddbd344ed53b96..619d554a09750ba87031129d45f9bf55189d2619 100644 (file)
@@ -850,25 +850,30 @@ class Client(ABC, ClientQueueMixin):
                     hostname=self.db.hostname, port=self.db.port,
                     _q_out=self._q_out, client_id=self.client_id)
             except IrcConnException as e:
-                self.db.connection_state = f'failed to connect: {e}'
-                if isinstance(e, IrcConnTimeoutException):
-                    if not self._retry_connect_in_s > 0:
-                        self._retry_connect_in_s = 1
-                    self._client_trigger('_delayed_retry_connect')
+                self._client_trigger('_on_connecting_exception', e=e)
             except Exception as e:  # pylint: disable=broad-exception-caught
                 self._put(ExceptionEvent(CrashingException(e)))
             else:
-                self._expected_pong = ''
-                self._retry_connect_in_s = -1
-                self.db.connection_state = 'connected'
-                self.caps.start_negotation()
-                self.send('USER', self.db.user_wanted,
-                          '0', '*', self.db.realname)
-                self.send('NICK', self.db.nick_wanted,)
+                self._client_trigger('_on_connected')
 
         # Do this in a thread, not to block flow of other (e.g. TUI) events.
         Thread(target=connect, daemon=True, args=(self,)).start()
 
+    def _on_connecting_exception(self, e: IrcConnException) -> None:
+        self.db.connection_state = f'failed to connect: {e}'
+        if isinstance(e, IrcConnTimeoutException):
+            if not self._retry_connect_in_s > 0:
+                self._retry_connect_in_s = 1
+            self._delayed_retry_connect()
+
+    def _on_connected(self) -> None:
+        self._expected_pong = ''
+        self._retry_connect_in_s = -1
+        self.db.connection_state = 'connected'
+        self.caps.start_negotation()
+        self.send('USER', self.db.user_wanted, '0', '*', self.db.realname)
+        self.send('NICK', self.db.nick_wanted,)
+
     def _delayed_retry_connect(self) -> None:
         def delayed_connect(self, wait_s: int, retry_connect_id: UUID
                             ) -> None: