From 625b3c27e6d85007a5d6deb936cab84e505ed530 Mon Sep 17 00:00:00 2001 From: Sander Sweers Date: Fri, 13 Sep 2024 15:13:50 +0200 Subject: [PATCH] AutoConnect: Automatically convert path to address If we find a dbus objectpath in the autoconnect tuple automatically convert it. --- blueman/plugins/applet/AutoConnect.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/blueman/plugins/applet/AutoConnect.py b/blueman/plugins/applet/AutoConnect.py index 9e84ac7ce..659faf611 100644 --- a/blueman/plugins/applet/AutoConnect.py +++ b/blueman/plugins/applet/AutoConnect.py @@ -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 @@ -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