DBus proxy wrapper doesn't expose method from interface definition (original) (raw)
I’m trying to get started with GNOME extension development. I have the following DBus interface definition:
const DBUS_IFACE = `
<node>
<interface name="io.github.pieterdd.StretchBreak">
<method name="GetIdleInfo">
<arg type="s" direction="out" />
</method>
</interface>
</node>`;
Here’s the proxy:
const Proxy = Gio.DBusProxy.makeProxyWrapper(DBUS_IFACE);
const proxy = Proxy(
Gio.DBus.session,
'io.github.pieterdd.StretchBreak',
'/io/github/pieterdd/StretchBreak',
);
What I don’t quite understand is that no methods are detected. console.log('methods', proxy.get_interface_info().methods)
produces the following output:
GNOME Shell-Message: 11:12:45.116: methods Array [
{}
]
Here’s what the DBus call I’m trying to do programmatically looks like on the command line:
$ dbus-send --print-reply --dest=io.github.pieterdd.StretchBreak /io/github/pieterdd/StretchBreak io.github.pieterdd.StretchBreak.GetIdleInfo
method return time=1746263834.143574 sender=:1.4671 -> destination=:1.4708 serial=12 reply_serial=2
string "{"idle_since_seconds":0,"last_checked":"2025-05-03T09:17:13.977912405Z","last_mode_state":{"state":"Normal","muted_until":null,"progress_towards_break":[7,535264056],"progress_towards_reset":[0,0],"idle_state":{"state":"Active","active_since":"2025-05-03T09:17:06.442648349Z"}}}"
What might I be doing wrong?
fmuellner (Florian Müllner) May 3, 2025, 6:23pm 2
It doesn’t look like you are doing anything wrong.
What you are seeing is a limitation of the console.log()
implementation, which simply passes the parameter to JSON.stringify()
, and that doesn’t know how to handle GDBusMethodInfo
instances (and thus just prints {}
).
You can get a slightly less confusing result with
console.log(`methods ${proxy.get_interface_info().methods}`)
That should give you something like`
methods [boxed instance wrapper GIName:Gio.DBusMethodInfo jsobj@0x1e8bf3b670b0 native@0x13439340]
which isn’t super expressive either, but at least it’s showing something rather than an empty object
pdd May 3, 2025, 7:02pm 3
You’re onto something. When I do this:
console.log('methods', proxy.get_interface_info().methods.map((m) => m.name));
I get this:
methods Array [
"GetIdleInfo"
]
The reason I’m trying this is that this line didn’t work for me:
proxy.GetIdleInfo(callback);
That yields this error:
JS ERROR: TypeError: proxy.GetIdleInfo is not a function
I’ve since discovered that I need to call GetIdleInfoRemote
instead. Thanks helping me narrow down where the issue is!