Including binary components in a GNOME Shell extension

≯℡__Kan透↙ 提交于 2019-12-08 03:33:25

问题


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?


回答1:


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:

  1. Hard code the path, e.g.: ~/.local/share/gnome-shell/extensions/myextension@myname.example.com/mybinary
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!