Skip to content

Commit

Permalink
AutoConnect: Automatically convert path to address
Browse files Browse the repository at this point in the history
If we find a dbus objectpath in the autoconnect tuple automatically convert it.
  • Loading branch information
infirit committed Sep 16, 2024
1 parent 8a5e491 commit 625b3c2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion blueman/plugins/applet/AutoConnect.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from gettext import gettext as _
from typing import TYPE_CHECKING, Union, Optional, Any
from blueman.bluemantyping import ObjectPath
from blueman.bluemantyping import ObjectPath, BtAddress

from gi.repository import GLib

from blueman.Sdp import ServiceUUID
from blueman.bluez.Device import Device
from blueman.config.AutoConnectConfig import AutoConnectConfig
from blueman.gui.Notification import Notification
from blueman.plugins.AppletPlugin import AppletPlugin

Expand Down Expand Up @@ -40,8 +41,24 @@ def on_adapter_property_changed(self, path: ObjectPath, key: str, value: Any) ->
if key == "Powered" and value:
self._run()

@staticmethod
def __fix_settings(path: ObjectPath, uuid: str) -> BtAddress:
config = AutoConnectConfig()
address = path.replace("_", ":")[-17:]

data = set(config["services"])
data.remove((path, uuid))
data.add((address, uuid))
config["services"] = data

return BtAddress(address)

def _run(self) -> bool:
for btaddress, uuid in self.get_option('services'):
# We accidentally stored the dbus object path in 2.4
if btaddress.startswith("/org/bluez"):
btaddress = self.__fix_settings(btaddress, uuid)

device = self.parent.Manager.find_device(btaddress)
if device is None or device.get("Connected"):
continue
Expand Down

0 comments on commit 625b3c2

Please sign in to comment.