Skip to content

Commit

Permalink
bluetooth module: reinitialize dbus to fix after sleep behavior (#2221)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasers authored Dec 12, 2023
1 parent 1ecf469 commit 2f81ae9
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 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,23 @@ 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()
try:
objects = self.bluez_manager.GetManagedObjects()
except GLib.Error as err:
if err.matches(Gio.dbus_error_quark(), Gio.DBusError.SERVICE_UNKNOWN):
self._dbus_init()
objects = self.bluez_manager.GetManagedObjects()
else:
raise

temporary = {}

for path, interfaces in sorted(objects.items()):
Expand Down

0 comments on commit 2f81ae9

Please sign in to comment.