# HG changeset patch # User Goffi # Date 1580156228 -3600 # Node ID 1a12bbd80943dec31d6f516324c085b819a6e6a8 # Parent bbf992b0be0d4e4f74d34387dde56fb2a218cc06 android: autoconnect profile using the new `profileAutoconnectGet` backend method: thanks to this method, Cagou know which profile is started automatically in backend, and can start it in frontend too. diff -r bbf992b0be0d -r 1a12bbd80943 cagou/__init__.py --- a/cagou/__init__.py Mon Jan 27 21:17:08 2020 +0100 +++ b/cagou/__init__.py Mon Jan 27 21:17:08 2020 +0100 @@ -1,5 +1,4 @@ -#!/usr//bin/env python2 -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) diff -r bbf992b0be0d -r 1a12bbd80943 cagou/core/cagou_main.py --- a/cagou/core/cagou_main.py Mon Jan 27 21:17:08 2020 +0100 +++ b/cagou/core/cagou_main.py Mon Jan 27 21:17:08 2020 +0100 @@ -515,7 +515,8 @@ self.app.showWidget() self.bridge.getVersion(callback=self._getVersionCb) self.app.initFrontendState() - self.postInit() + if local_platform.do_postInit(): + self.postInit() def postInit(self, __=None): # FIXME: resize doesn't work with SDL2 on android, so we use below_target for now diff -r bbf992b0be0d -r 1a12bbd80943 cagou/core/platform_/android.py --- a/cagou/core/platform_/android.py Mon Jan 27 21:17:08 2020 +0100 +++ b/cagou/core/platform_/android.py Mon Jan 27 21:17:08 2020 +0100 @@ -80,12 +80,33 @@ # XXX: we use a separated socket instead of bridge because if we # try to call a bridge method in on_pause method, the call data # is not written before the actual pause - s = self._frontend_status_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + s = self._frontend_status_socket = socket.socket( + socket.AF_UNIX, socket.SOCK_STREAM) s.connect(os.path.join(SOCKET_DIR, SOCKET_FILE)) s.sendall(STATE_RUNNING) + def profileAutoconnectGetCb(self, profile=None): + if profile is not None: + G.host.options.profile = profile + G.host.postInit() + + def profileAutoconnectGetEb(self, failure_): + log.error(f"Error while getting profile to autoconnect: {failure_}") + G.host.postInit() + + def do_postInit(self): + G.host.bridge.profileAutoconnectGet( + callback=self.profileAutoconnectGetCb, + errback=self.profileAutoconnectGetEb + ) + return False + def onProfilePlugged(self, profile): log.debug("ANDROID profilePlugged") + G.host.bridge.setParam( + "autoconnect_backend", C.BOOL_TRUE, "Connection", -1, profile, + callback=lambda: log.info(f"profile {profile} autonnection set"), + errback=lambda: log.error(f"can't set {profile} autonnection")) for method, *args in self.cache: method(*args) del self.cache diff -r bbf992b0be0d -r 1a12bbd80943 cagou/core/platform_/base.py --- a/cagou/core/platform_/base.py Mon Jan 27 21:17:08 2020 +0100 +++ b/cagou/core/platform_/base.py Mon Jan 27 21:17:08 2020 +0100 @@ -48,6 +48,9 @@ def on_initFrontendState(self): pass + def do_postInit(self): + return True + def on_pause(self): pass