fix: Store D-Bus agent instance globally to prevent GC

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-12-30 19:59:28 +00:00
parent 19cf54b2c2
commit d67ad2ef2a

View File

@@ -17,6 +17,7 @@ from dbus_next import Variant
bus = None bus = None
agent_instance = None
# --- Bluetooth constants and agent --- # --- Bluetooth constants and agent ---
BLUEZ_SERVICE = 'org.bluez' BLUEZ_SERVICE = 'org.bluez'
@@ -104,8 +105,9 @@ async def get_adapter():
return None return None
async def register_agent(): async def register_agent():
agent = Agent(AGENT_IFACE) global agent_instance
bus.export(AGENT_PATH, agent) agent_instance = Agent(AGENT_IFACE)
bus.export(AGENT_PATH, agent_instance)
introspection = await bus.introspect(BLUEZ_SERVICE, '/org/bluez') introspection = await bus.introspect(BLUEZ_SERVICE, '/org/bluez')
manager_obj = bus.get_proxy_object(BLUEZ_SERVICE, '/org/bluez', introspection) manager_obj = bus.get_proxy_object(BLUEZ_SERVICE, '/org/bluez', introspection)