changeset 3118:02492db1ce39

quick frontend (app): call `getReady` once connected to bridge: namespaces and encryption plugins are only retrieved once backend is ready, else they may not yet be available (can happen notably when the backend is start at the same time as the frontend, e.g. on Android).
author Goffi <goffi@goffi.org>
date Sat, 25 Jan 2020 21:08:26 +0100
parents 385fdd684f87
children 790489521b15
files sat/plugins/plugin_xep_0329.py sat_frontends/quick_frontend/quick_app.py
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0329.py	Sat Jan 25 21:08:25 2020 +0100
+++ b/sat/plugins/plugin_xep_0329.py	Sat Jan 25 21:08:26 2020 +0100
@@ -1,5 +1,4 @@
 #!/usr/bin/env python3
-# -*- coding: utf-8 -*-
 
 # SAT plugin for File Information Sharing (XEP-0329)
 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
--- a/sat_frontends/quick_frontend/quick_app.py	Sat Jan 25 21:08:25 2020 +0100
+++ b/sat_frontends/quick_frontend/quick_app.py	Sat Jan 25 21:08:26 2020 +0100
@@ -349,13 +349,7 @@
         log.warning(_("Can't retrieve encryption plugins: {msg}").format(msg=failure_))
 
     def onBridgeConnected(self):
-        self.bridge.namespacesGet(
-            callback=self._namespacesGetCb, errback=self._namespacesGetEb)
-        # we cache available encryption plugins, as we'll use them on earch
-        # new chat widget
-        self.bridge.encryptionPluginsGet(
-            callback=self._encryptionPluginsGetCb,
-            errback=self._encryptionPluginsGetEb)
+        self.bridge.getReady(self.onBackendReady)
 
     def _bridgeCb(self):
         self.registerSignal("connected")
@@ -400,6 +394,17 @@
         else:
             print((_("Error while initialising bridge: {}".format(failure))))
 
+    def onBackendReady(self):
+        log.info("backend is ready")
+        self.bridge.namespacesGet(
+            callback=self._namespacesGetCb, errback=self._namespacesGetEb)
+        # we cache available encryption plugins, as we'll use them on each
+        # new chat widget
+        self.bridge.encryptionPluginsGet(
+            callback=self._encryptionPluginsGetCb,
+            errback=self._encryptionPluginsGetEb)
+
+
     @property
     def current_profile(self):
         """Profile that a user would expect to use"""