DBUS Interface Definitions when Methods are in Different Module

In case of gnome extension, Suppose i have an Interface Definitions (in simpleModule.js) like:

  <interface name="org.gnome.Shell.Extensions.Windows">

    <method name="SimpleMethod"/>

function SimpleMethod() {
    console.debug(`Running SimpleMethod`);

The SimpleMethod is in simpleModule.js. I have imported it in extension.js by:

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const simpleModule = Me.imports.simpleModule;

class Extension {
    enable() {
        console.debug(`enabling ${Me.metadata.name}`);
        this._dbus_windows = Gio.DBusExportedObject.wrapJSObject(simpleModule.SIMPLE_DBUS_IFACE, this);
        this._dbus_windows.export(Gio.DBus.session, '/org/gnome/Shell/Extensions/Windows');


If SimpleMethod is in extension.js then the following command works.

dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/Windows org.gnome.Shell.Extensions.Windows.SimpleMethod

But when the SimpleMethod is in simpleModule, the above command does not work.

Is there any way i can keep the SimpleMethod function in simpleModule.js instead of moving it to extension.js?

If I add:

class Extension {

    SimpleMethod = simpleModule.SimpleMethod;

Then it works, but it is … not what I would like to have. In this case I have to modify two files when adding a function. I might forget later, then have to check both files.

The easiest solution is just to define a class in simpleModule with the methods and just pass that to Gio.DBusExportedObject.wrapJSObject() instead of the this object.


Thank you very much. This works.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.