Commit b629bc06 authored by Tobias Mueller's avatar Tobias Mueller

Merged deferred bluetooth check

If Bluetooth is not available, then it might stall until the requests
times out.  So we do not lose anything by assuming no Bluetooth availability.
If Bluetooth is indeed available, we have a small window in which we
assume Bluetooth is not available while it actually is. But that time
window is relatively small. The requests completes nearly instantly
in a normal setup.
parents 1d41b36b c2476b50
......@@ -108,6 +108,8 @@ class ReceiveApp:
self.discover = None
self.bt_available = is_bt_available()
def on_keydata_downloaded(self, keydata, pixbuf=None):
key = openpgpkey_from_data(keydata)
......@@ -165,13 +167,20 @@ class ReceiveApp:
"""We show an infobar if we can only receive with Avahi and
there are zero nearby servers"""
ib = userdata
if number == 0 and not is_bt_available():
bt_usable = False
try:
if self.bt_available.result:
bt_usable = True
except AttributeError:
log.debug("We still don't know if Bluetooth is available, until proven contrary "
"we simply assume it is not")
if number == 0 and not bt_usable:
ib.show()
elif ib.is_visible():
ib.hide()
class App(Gtk.Application):
def __init__(self, *args, **kwargs):
super(App, self).__init__(*args, **kwargs)
......
......@@ -25,6 +25,8 @@ import shutil
from subprocess import call
from string import Template
from tempfile import NamedTemporaryFile
from twisted.internet import threads
try:
from urllib.parse import urlparse, parse_qs
from urllib.parse import ParseResult
......@@ -360,11 +362,17 @@ def get_local_bt_address(hci_number=0):
def is_bt_available(hci_number=0):
"""We check for bluez with a deferred thread because this is a blocking operation"""
d = threads.deferToThread(_get_bluez, hci_number)
return d
def _get_bluez(hci_number=0):
"""If the bluez object is available it means that there is a working Bluetooth"""
bus = dbus.SystemBus()
try:
dbus.Interface(bus.get_object("org.bluez", "/org/bluez/hci%i" % hci_number),
"org.freedesktop.DBus.Properties")
bus.get_object("org.bluez", "/org/bluez/hci%i" % hci_number)
log.debug("Bluetooth seems to be available in the system")
return True
except dbus.exceptions.DBusException as e:
log.debug("Bluetooth is not available: %s", e)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment