Skip to content

Commit

Permalink
bluetooth: reinitialize dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
lasers committed Dec 4, 2023
1 parent 9859d64 commit 4a489f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions py3status/modules/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
{'color': '#00FF00', 'full_text': u'Microsoft Bluetooth Notebook Mouse 5000'}
"""

from gi.repository import Gio
from gi.repository import Gio, GLib


class Py3status:
Expand All @@ -105,12 +105,7 @@ class Py3status:
thresholds = [(False, "bad"), (True, "good")]

def post_config_hook(self):
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
iface = "org.freedesktop.DBus.ObjectManager"
self.bluez_manager = Gio.DBusProxy.new_sync(
bus, Gio.DBusProxyFlags.NONE, None, "org.bluez", "/", iface, None
)

self._dbus_init()
self.names_and_matches = [
("adapters", "org.bluez.Adapter1"),
("devices", "org.bluez.Device1"),
Expand All @@ -120,8 +115,30 @@ def post_config_hook(self):
for name in ["format", "format_adapter", "format_device"]:
self.thresholds_init[name] = self.py3.get_color_names_list(getattr(self, name))

def _dbus_init(self):
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
iface = "org.freedesktop.DBus.ObjectManager"
self.bluez_manager = Gio.DBusProxy.new_sync(
bus, Gio.DBusProxyFlags.NONE, None, "org.bluez", "/", iface, None
)

def _get_bluez_data(self):
objects = self.bluez_manager.GetManagedObjects()
for retry in range(0, 2):
self.py3.log(" --- RETRY {} ---".format(retry))
try:
objects = self.bluez_manager.GetManagedObjects()
self.py3.log(" --- SUCCESS ---")
except GLib.Error as err:
self.py3.log(" --- FAILED ---")
if err.matches(Gio.dbus_error_quark(), Gio.DBusError.SERVICE_UNKNOWN):
self._dbus_init()
self.py3.log(" --- MATCHED ---")
else:
self.py3.log(" --- RAISED ---")
raise
else:
break

temporary = {}

for path, interfaces in sorted(objects.items()):
Expand Down
2 changes: 1 addition & 1 deletion py3status/screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

SEP_BORDER = 4

FONT = "DejaVuSansMono.ttf"
FONT = "/nix/store/7asidy86rm4qp8l3lhc8nbdm1q75fcav-dejavu-fonts-2.37/share/fonts/truetype/DejaVuSansMono.ttf"

# Pillow does poor font rendering so we are best off creating huge text and
# then shrinking with anti-aliasing. SCALE is how many times bigger we render
Expand Down

0 comments on commit 4a489f4

Please sign in to comment.