Use async function to load DBUS xml file
This commit is contained in:
+17
-23
@@ -555,31 +555,19 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
}
|
||||
});
|
||||
|
||||
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
||||
// loads a xml file into an in-memory string
|
||||
function loadInterfaceXml(extension, filename) {
|
||||
async function loadInterfaceXml(extension, filename) {
|
||||
const interfacesDir = extension.dir.get_child('.');
|
||||
|
||||
const file = interfacesDir.get_child(filename);
|
||||
const fd = Gio.File.new_for_path(file.get_path());
|
||||
const [contents, etag] = await fd.load_contents_async(null);
|
||||
|
||||
let [result, contents] = GLib.file_get_contents(file.get_path());
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
const decoded_content = decoder.decode(contents);
|
||||
|
||||
if (result) {
|
||||
// HACK: The "" + trick is important as hell because file_get_contents returns
|
||||
// an object (WTF?) but Gio.makeProxyWrapper requires `typeof() == "string"`
|
||||
// Otherwise, it will try to check `instanceof XML` and fail miserably because there
|
||||
// is no `XML` on very recent SpiderMonkey releases (or, if SpiderMonkey is old enough,
|
||||
// will spit out a TypeError soon).
|
||||
if (contents instanceof Uint8Array)
|
||||
{
|
||||
const decoder = new TextDecoder();
|
||||
contents = decoder.decode(contents);
|
||||
}
|
||||
const res = `<node>${contents}</node>`;
|
||||
return res;
|
||||
} else {
|
||||
throw new Error(`Generic monitor: Could not load file: ${filename}`);
|
||||
}
|
||||
const res = `<node>${decoded_content}</node>`;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
class GenericMonitorDBUS {
|
||||
@@ -588,9 +576,15 @@ class GenericMonitorDBUS {
|
||||
this.monitor_groups = {};
|
||||
this.actor_clicked = {};
|
||||
this.ClutterSettings = Clutter.Settings.get_default();
|
||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml(extension, 'dbus.xml'), this);
|
||||
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
||||
this._dbusImpl.emit_signal('onActivate', null);
|
||||
this._dbusImpl = null;
|
||||
loadInterfaceXml(extension, 'dbus.xml')
|
||||
.then( (xml) =>
|
||||
{
|
||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(xml, this);
|
||||
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
||||
this._dbusImpl.emit_signal('onActivate', null);
|
||||
})
|
||||
.catch((e) => { this.logger.error(e); });
|
||||
}
|
||||
|
||||
emitSignal(name, value) {
|
||||
|
||||
Reference in New Issue
Block a user