Including binary components in a GNOME Shell extension

早过忘川 提交于 2019-12-08 08:36:29

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.

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