Skip to content

Commit

Permalink
AutoConnect: Store bluetooth address instead of object path
Browse files Browse the repository at this point in the history
Fixes autoconnect plugin.
  • Loading branch information
infirit committed Sep 13, 2024
1 parent 45f53c2 commit 8a5e491
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion blueman/config/AutoConnectConfig.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Tuple
from blueman.bluemantyping import BtAddress
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
Expand All @@ -9,7 +10,7 @@ class AutoConnectConfig(Gio.Settings):
def __init__(self) -> None:
super().__init__(schema_id="org.blueman.plugins.autoconnect")

def bind_to_menuitem(self, item: Gtk.CheckMenuItem, data: Tuple[str, str]) -> None:
def bind_to_menuitem(self, item: Gtk.CheckMenuItem, data: Tuple[BtAddress, str]) -> None:
def switch(active: bool) -> None:
services = set(self["services"])
if active:
Expand Down
4 changes: 3 additions & 1 deletion blueman/gui/manager/ManagerDeviceMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from gettext import gettext as _
from operator import attrgetter
from typing import Dict, List, Tuple, Optional, TYPE_CHECKING, Union, Iterable
from blueman.bluemantyping import BtAddress

from blueman.bluemantyping import ObjectPath
from blueman.Functions import create_menuitem, e_
Expand Down Expand Up @@ -328,14 +329,15 @@ def generate(self) -> None:
config = AutoConnectConfig()
generic_service = ServiceUUID("00000000-0000-0000-0000-000000000000")
object_path = self.SelectedDevice.get_object_path()
btaddress: BtAddress = self.SelectedDevice["Address"]
generic_autoconnect = (object_path, str(generic_service)) in set(config["services"])

if row["connected"] or generic_autoconnect or autoconnect_items:
self.append(self._create_header(_("<b>Auto-connect:</b>")))

if row["connected"] or generic_autoconnect:
item = Gtk.CheckMenuItem(label=generic_service.name)
config.bind_to_menuitem(item, (str(object_path), str(generic_service)))
config.bind_to_menuitem(item, (btaddress, str(generic_service)))
item.show()
self.append(item)

Expand Down
4 changes: 2 additions & 2 deletions blueman/plugins/applet/AutoConnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def on_adapter_property_changed(self, path: ObjectPath, key: str, value: Any) ->
self._run()

def _run(self) -> bool:
for address, uuid in self.get_option('services'):
device = self.parent.Manager.find_device(address)
for btaddress, uuid in self.get_option('services'):
device = self.parent.Manager.find_device(btaddress)
if device is None or device.get("Connected"):
continue

Expand Down
7 changes: 4 additions & 3 deletions blueman/plugins/manager/Services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Callable
from blueman.bluemantyping import BtAddress

import cairo

Expand Down Expand Up @@ -73,14 +74,14 @@ def on_request_menu_items(
items.append(DeviceMenuItem(item, DeviceMenuItem.Group.DISCONNECT, service.priority + 100))
item.show()

object_path = device.get_object_path()
btaddress: BtAddress = device["Address"]
if services:
config = AutoConnectConfig()
autoconnect_services = set(config["services"])
for service in services:
if service.connected_instances or (object_path, service.uuid) in autoconnect_services:
if service.connected_instances or (btaddress, service.uuid) in autoconnect_services:
item = Gtk.CheckMenuItem(label=service.name)
config.bind_to_menuitem(item, (object_path, service.uuid))
config.bind_to_menuitem(item, (btaddress, service.uuid))
item.show()
items.append(DeviceMenuItem(item, DeviceMenuItem.Group.AUTOCONNECT, service.priority))

Expand Down

0 comments on commit 8a5e491

Please sign in to comment.