Developing extensions for the GNOME Shell mostly involves the use of C APIs through GObject Introspection. This means that most things achievable with C can be done in JavaScript, too. But there are some cases, where features of the C APIs cannot (yet) be reproduced through the introspection bindings. It would be useful to be able to bridge these gaps with native C code.
Can a GNOME Shell extension include binary components created from C code? If so, how are they integrated?
I'm having the very same question. Haven't found a good way to do so yet. Currently I'm trying 2 non ideal approaches to do so:
- Hard code the path, e.g.:
~/.local/share/gnome-shell/extensions/myextension@myname.example.com/mybinary
- Install the binary globally and independent from the extension.
Once you have the path you can for example use Util.spawnCommandLine
:
const Util = imports.misc.util;
Util.spawnCommandLine('/path/to/your/bin');
Or GLib.spawn_async
if you need a callback:
const GLib = imports.gi.GLib;
let [success, pid] = GLib.spawn_async(null,
['/path/to/your/bin', '--param1','--param2'],
null,
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
null);
if (!success) {
global.log('ERROR NO SUCCESS');
return;
}
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, function (pid, status) {
GLib.spawn_close_pid(pid);
if (status !== 0 && status !== '0') {
global.log('ERROR');
}
else {
global.log('SUCCESS', status);
}
});
The piece I'm missing is if there is a way to get the extension path somehow via a helper method. But the docs are horribly underdeveloped and browsing the source code hasn't found me the solution yet.
来源:https://stackoverflow.com/questions/40919457/including-binary-components-in-a-gnome-shell-extension