Skip to content

Instantly share code, notes, and snippets.

@nkoep
Last active December 17, 2015 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkoep/b7f07350d860678ad763 to your computer and use it in GitHub Desktop.
Save nkoep/b7f07350d860678ad763 to your computer and use it in GitHub Desktop.
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const BUS_NAME = "org.freedesktop.Notifications";
const OBJECT_PATH = "/" + BUS_NAME.replace(/\./g, "\/");
const NotificationDaemonIface = <interface name="org.freedesktop.Notifications">
<method name="Notify">
<arg type="s" direction="in"/>
<arg type="u" direction="in"/>
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
<arg type="as" direction="in"/>
<arg type="a{sv}" direction="in"/>
<arg type="i" direction="in"/>
<arg type="u" direction="out"/>
</method>
</interface>;
function BusName() {
this._init();
}
BusName.prototype = {
_init: function() {
var owner_id = Gio.bus_own_name(
Gio.BusType.SESSION, // bus
BUS_NAME, // bus name
Gio.BusNameOwnerFlags.REPLACE, // owner flags
null, // bus_acquired_cb
Lang.bind(this, function(connection, name, userdata) {
print("Acquired bus name: " + name);
print("Exporting object: " + OBJECT_PATH);
this._export_object();
}), // name_acquired_cb
null, // name_lost_cb
null // userdata
);
},
_export_object: function() {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(
NotificationDaemonIface, this);
this._dbusImpl.export(Gio.DBus.session, OBJECT_PATH);
}
};
function main() {
var bus_name = new BusName();
var main_loop = new GLib.MainLoop(null, 0);
main_loop.run();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment