Commit 90a9ab40 authored by Florian Müllner's avatar Florian Müllner

overrides/Gio: Add D-Bus convenience to more proxy methods

Currently it's only added to GDBusProxy's g_initable_init() and
g_async_initable_async() methods used by makeProxyWrapper(). But
there are use cases for not using the wrapper, for example to pass
a custom g-flags property; GDBusProxy's convenience constructors
may be more convenient than g_object_new()+g_initable_init(), so
monkey-patch them as well.

#122
parent 30874cb7
Pipeline #4786 passed with stages
in 4 minutes and 26 seconds
......@@ -255,6 +255,31 @@ describe('Exported DBus object', function () {
loop.run();
});
it('can call a remote method when not using makeProxyWrapper', function () {
let info = Gio.DBusNodeInfo.new_for_xml(TestIface);
let iface = info.interfaces[0];
let otherProxy = null;
Gio.DBusProxy.new_for_bus(Gio.BusType.SESSION,
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
iface,
'org.gnome.gjs.Test',
'/org/gnome/gjs/Test',
iface.name,
null,
(o, res) => {
otherProxy = Gio.DBusProxy.new_for_bus_finish(res);
loop.quit();
});
loop.run();
otherProxy.frobateStuffRemote({}, ([result], excp) => {
expect(excp).toBeNull();
expect(result.hello.deep_unpack()).toEqual('world');
loop.quit();
});
loop.run();
});
/* excp must be exactly the exception thrown by the remote method
(more or less) */
it('can handle an exception thrown by a remote method', function () {
......
......@@ -235,6 +235,16 @@ function _injectToMethod(klass, method, addition) {
};
}
function _injectToStaticMethod(klass, method, addition) {
var previous = klass[method];
klass[method] = function(...parameters) {
let obj = previous.apply(this, parameters);
addition.apply(obj, parameters);
return obj;
};
}
function _wrapFunction(klass, method, addition) {
var previous = klass[method];
......@@ -388,6 +398,10 @@ function _init() {
_injectToMethod(Gio.DBusProxy.prototype, 'init', _addDBusConvenience);
_injectToMethod(Gio.DBusProxy.prototype, 'init_async', _addDBusConvenience);
_injectToStaticMethod(Gio.DBusProxy, 'new_sync', _addDBusConvenience);
_injectToStaticMethod(Gio.DBusProxy, 'new_finish', _addDBusConvenience);
_injectToStaticMethod(Gio.DBusProxy, 'new_for_bus_sync', _addDBusConvenience);
_injectToStaticMethod(Gio.DBusProxy, 'new_for_bus_finish', _addDBusConvenience);
Gio.DBusProxy.prototype.connectSignal = Signals._connect;
Gio.DBusProxy.prototype.disconnectSignal = Signals._disconnect;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment