You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* The bus communication happens over a Unix socket, with the path `/run/user/1000/bus`.
33
-
34
-
*`org.freedesktop.Notifications` on the left panel is the `connection name`.
35
-
36
-
* The process that has connected with this name is `/usr/bin/gjs /usr/share/gnome-shell/org.gnome.Shell.Notifications` and has the pid of `4373`.
37
-
38
-
* This process exposes one object: `/org/freedesktop/Notifications`.
39
-
Note that the object name is the same as the connection name, where the dots have been replaced with slashes.
40
-
This is not a requirement, as the objects exposed by a process can have any name.
41
-
42
-
<!-- markdownlint-disable MD101 -->
43
-
* The object has 4 interfaces: `org.freedesktop.DBus.Introspectable`, `org.freedesktop.DBus.Peer`, `org.freedesktop.DBus.Properties` and `org.freedesktop.Notifications`.
44
-
Note that the last one (`org.freedesktop.Notifications`) is the same as the connection name, but this again is just a coincidence, not a requirement.
45
-
<!-- markdownlint-enable MD101 -->
46
-
47
-
* The interface `org.freedesktop.Notifications` has some methods that can be called, such as `Notify`.
48
-
49
-
## Calling D-Bus Methods
50
-
51
-
The application behind `org.freedesktop.Notifications` is responsible with desktop notifications (the small bubbles of text that appear at the top of the screen when some event happens).
52
-
When an application wants to send a notification it needs to connect to D-Bus and call the `Notify` method from the `org.freedesktop.Notifications` interface.
53
-
54
-
In this example, we want to call the `Notify` method ourselves.
55
-
To do this, we must first understand the signature of this method:
This doesn't tell us much, but we can find more documentation [here](https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html#basic-design), since `freedesktop` is an open standard.
60
-
61
-
We'll set the arguments to the following (for our simple case, most of them will be unused):
62
-
63
-
*`app_name`: `""`
64
-
65
-
*`replaces_id`: `0`
66
-
67
-
*`app_icon`: `""`
68
-
69
-
*`summary`: `"This is the title"`
70
-
71
-
*`body`: `"This is the content"`
72
-
73
-
*`actions`: `[]`
74
-
75
-
*`hints`: `{}`
76
-
77
-
*`expire_timeout`: `-1`
78
-
79
-
Now the question is how to actually call the method.
80
-
Normally, we would have to write an application that connects to D-Bus and executes the call.
81
-
But for demonstrative purposes there are easier ways.
82
-
83
-
One way is directly from d-feet.
84
-
If we double-click on the `Notify` method in the right-side pane of d-feet, a window will open that allows us to call the method with any arguments that we want:
Use the `dbus` python bindings to get the computer's battery level using a python script.
164
-
You can start from the documentation [here](https://dbus.freedesktop.org/doc/dbus-python/tutorial.html#).
165
-
You need to read the sections `Connecting to the Bus`, `Proxy objects`, and `Interfaces and methods`.
166
-
167
-
There's also a skeleton you can use in `chapters/app-interact/arena/support/dbus/get_battery_level.py`.
168
-
169
-
In summary, your script will start by connecting to the `System Bus`.
170
-
Then you'll use the `get_object` method to obtain a proxy object.
171
-
On this proxy object, you can actually do the method call as explained [here](https://dbus.freedesktop.org/doc/dbus-python/tutorial.html#interfaces-and-methods):
172
-
173
-
```text
174
-
To call a method, call the method of the same name on the proxy object, passing in the interface name via the dbus_interface keyword argument
175
-
```
176
-
177
-
So, if you want to call the method `this.is.an.interface.method` with the arguments `A` and `B` you can do it like this:
178
-
179
-
```python
180
-
result = proxy.method(A, B, dbus_interface="this.is.an.interface")
There was a D-Bus call to `org.mozilla.firefox.ZGVmYXVsdC1yZWxlYXNl`, on the object `/org/mozilla/firefox/Remote`, method `OpenURL` from the `org.mozilla.firefox` interface.
225
-
Indeed, we see that this object exists in d-feet as well:
226
-
227
-

228
-
229
-
We can try to call the `OpenURL` method ourselves, directly from d-feet.
230
-
The method has only one argument of the type `Array of [Byte]`.
231
-
Although there's no documentation for it, we can use the same byte array that we saw in `dbus-monitor`:
(Note that `77 77 77 2e 67 6f 6f 67 6c 65 2e 63 6f 6d` at the end is the string `www.google.com`, so that's another confirmation that we're on the right track).
0 commit comments