Combinging disconnect code to try and minimize errors with the logic
[theonering] / src / connection.py
index 41ea912..22d6885 100644 (file)
@@ -232,13 +232,9 @@ class TheOneRingConnection(
                For org.freedesktop.telepathy.Connection
                """
                try:
-                       self.disconnect()
+                       self.disconnect(telepathy.CONNECTION_STATUS_REASON_REQUESTED)
                except Exception:
                        _moduleLogger.exception("Error durring disconnect")
-               self.StatusChanged(
-                       telepathy.CONNECTION_STATUS_DISCONNECTED,
-                       telepathy.CONNECTION_STATUS_REASON_REQUESTED
-               )
 
        @gtk_toolbox.log_exception(_moduleLogger)
        def RequestChannel(self, type, handleType, handleId, suppressHandler):
@@ -277,8 +273,15 @@ class TheOneRingConnection(
 
                return props
 
-       def disconnect(self):
+       def disconnect(self, reason):
                _moduleLogger.info("Disconnecting")
+               # Not having the disconnect first can cause weird behavior with clients
+               # including not being able to reconnect or even crashing
+               self.StatusChanged(
+                       telepathy.CONNECTION_STATUS_DISCONNECTED,
+                       reason,
+               )
+
                for plumber in self._plumbing:
                        plumber.stop()