Using Gio.DBusProxy.makeProxyWrapper in the global scope of the extension

Hi there.

Do you think it is wrong to use Gio.DBusProxy.makeProxyWrapper in the global scope of the extension? In other words, is the code below incorrect?

const { Gio } = imports.gi;

const BrightnessInterface = loadInterfaceXML(`org.gnome.SettingsDaemon.Power.Screen`);
const BrightnessProxy = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);

As stated in the documentation, Gio.DBusProxy.makeProxyWrapper creates a reusable class that can be used to create a proxy, but it doesn’t create any objects. Therefore, in my opinion, the code above is correct. Or am I wrong somewhere?

Well, even Functions are objects in JavaScript. Is this in reference to a review you received for your extension?

Yes. My extension was rejected during review.

I guess it might be a gray area, but there’s really no downside to making the call in enable() and dropping it in disable().

Hmm, okay. So how do I do it correctly?

enable() {
    const ProxyWrapper = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);
    this._proxy = new Proxy(...);
}

disable() {
    delete this._proxy;
}

or

enable() {
    this._proxyWrapper = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);
    this._proxy = new this._proxyWrapper(...);
}

disable() {
    delete this._proxy;
    delete this._proxyWrapper;
}

The first is pretty much how I would do it. I usually assign null instead of using delete, but I don’t think that matters.

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