Skip to content

Commit

Permalink
lookingGlass.js: Initialize melange interface at startup.
Browse files Browse the repository at this point in the history
- Prevent this initialization from launching cinnamon-looking-glass.
  The interface will be ready but won't actually launch the melange
  process until necessary.
- Set up asynchronously to prevent startup delays.
  • Loading branch information
mtwebster committed Nov 12, 2023
1 parent b885436 commit 22254e2
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions js/ui/lookingGlass.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,14 @@ class Inspector {
Signals.addSignalMethods(Inspector.prototype);


const dbusIFace =
const melangeIFace =
'<node> \
<interface name="org.Cinnamon.Melange"> \
<method name="show" /> \
<method name="hide" /> \
<method name="getVisible"> \
<arg type="b" direction="out" name="visible"/> \
</method> \
<property name="_open" type="b" access="read" /> \
</interface> \
</node>';

Expand Down Expand Up @@ -506,8 +505,6 @@ const lgIFace =
</interface> \
</node>';

const proxy = Gio.DBusProxy.makeProxyWrapper(dbusIFace);

var Melange = class {
constructor() {
this.proxy = null;
Expand All @@ -527,6 +524,7 @@ var Melange = class {
this._dbusImpl.export(Gio.DBus.session, '/org/Cinnamon/LookingGlass');

Gio.DBus.session.own_name('org.Cinnamon.LookingGlass', Gio.BusNameOwnerFlags.REPLACE, null, null);
this.ensureProxy();
}

_update_keybinding() {
Expand All @@ -535,18 +533,35 @@ var Melange = class {
}

ensureProxy() {
if (!this.proxy)
this.proxy = new proxy(Gio.DBus.session, 'org.Cinnamon.Melange', '/org/Cinnamon/Melange');
let nodeInfo = Gio.DBusNodeInfo.new_for_xml(melangeIFace);

Gio.DBusProxy.new(
Gio.DBus.session,
Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION,
nodeInfo.lookup_interface("org.Cinnamon.Melange"),
"org.Cinnamon.Melange",
"/org/Cinnamon/Melange",
"org.Cinnamon.Melange",
null,
this._onProxyReady.bind(this)
);
}

_onProxyReady(object, res) {
try {
this.proxy = Gio.DBusProxy.new_finish(res);
} catch (e) {
log('error creating org.Cinnamon.Melange proxy: %s'.format(e.message));
return;
}
}

open() {
this.ensureProxy()
this.proxy.showRemote();
this.updateVisible();
}

close() {
this.ensureProxy()
this.proxy.hideRemote();
this.updateVisible();
}
Expand Down

0 comments on commit 22254e2

Please sign in to comment.