Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions blueman/plugins/applet/AutoConnect.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from gettext import gettext as _
from typing import TYPE_CHECKING, Any
from blueman.bluemantyping import ObjectPath, BtAddress
Expand Down Expand Up @@ -31,6 +32,7 @@ class AutoConnect(AppletPlugin):

def __init__(self, parent: "BluemanApplet"):
super().__init__(parent)
self._last_err: dict[str, str] = {}
GLib.timeout_add(60000, self._run)

def on_manager_state_changed(self, state: bool) -> None:
Expand Down Expand Up @@ -65,12 +67,19 @@ def _run(self) -> bool:

def reply(dev: Device | None = device, service_name: str = ServiceUUID(uuid).name) -> None:
assert isinstance(dev, Device) # https://github.com/python/mypy/issues/2608
self._last_err.pop(dev["Address"], None)
Notification(_("Connected"), _("Automatically connected to %(service)s on %(device)s") %
{"service": service_name, "device": dev.display_name},
icon_name=dev["Icon"]).show()

def err(_reason: Exception | str) -> None:
pass
def err(reason: Exception | str, dev: Device | None = device) -> None:
assert isinstance(dev, Device)
reason_str = str(reason)
address = dev["Address"]
if self._last_err.get(address) == reason_str:
return
self._last_err[address] = reason_str
logging.warning(f"AutoConnect failed for {dev.display_name}: {reason_str}")

self.parent.Plugins.DBusService.connect_service(device.get_object_path(), uuid, reply, err)

Expand Down