altdesktop / python-dbus-next

🚌 The next great DBus library for Python with asyncio support
https://python-dbus-next.readthedocs.io/en/latest/
MIT License
187 stars 59 forks source link

Getting sender of method call #93

Closed elParaguayo closed 2 years ago

elParaguayo commented 2 years ago

Firstly, thanks for your work on dbus-next. It's a great library and I've helped incorporate it into Qtile.

I've recently been working on an implementation of StatusNotifierItem for Qtile.

Using this library, I've created a StatusNotifierWatcher service which applications successfully register with when they start. To do this, applications call a method called RegisterStatusNotifierItem and pass their service address. This allows me to connect to that address and create a StatusNotifierItem object from which I can extract icon and menu information.

However, it seems Gnome have their own implementation of the StatusNotifierItem specification, called Ayatana. Applications using Ayatana also call RegisterStatusNotifierItem but, instead of passing the service address, they pass the object path and I can't tell which service is providing that object so there's nothing I can do.

If I use dbus-monitor I can use a rule like type='method_call',member='RegisterStatusNotifierItem' to get details of the call, including the sender. However, the same rule won't work if used with AddMatch, presumably because I'm not a Monitor.

Is there any way to identify the sender of a method call?

acrisci commented 2 years ago

The message sender address is within the message header. The full message is exposed to you when you use the low level interface and you can get it there. This isn't exposed to you in the high level service however. What could be done for that is to inject the full message into the method call.

elParaguayo commented 2 years ago

Thanks. Thought I was already doing this with an add_message_handler call but it was set up on a different bus connection. Seems to be working now.