简体   繁体   English

在GNOME Shell扩展中包含二进制组件

[英]Including binary components in a GNOME Shell extension

Developing extensions for the GNOME Shell mostly involves the use of C APIs through GObject Introspection. 为GNOME Shell开发扩展主要涉及通过GObject Introspection使用C API。 This means that most things achievable with C can be done in JavaScript, too. 这意味着使用C可以实现的大多数事情也可以在JavaScript中完成。 But there are some cases, where features of the C APIs cannot (yet) be reproduced through the introspection bindings. 但在某些情况下,C API的功能无法(尚未)通过内省绑定进行再现。 It would be useful to be able to bridge these gaps with native C code. 能够使用本机C代码弥补这些差距将是有用的。

Can a GNOME Shell extension include binary components created from C code? GNOME Shell扩展可以包含从C代码创建的二进制组件吗? 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: 目前我正在尝试两种非理想的方法:

  1. Hard code the path, eg: ~/.local/share/gnome-shell/extensions/myextension@myname.example.com/mybinary 硬编码路径,例如:〜/ ~/.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 : 获得路径后,您可以使用Util.spawnCommandLine

const Util = imports.misc.util;
Util.spawnCommandLine('/path/to/your/bin');

Or GLib.spawn_async if you need a callback: 或者如果需要回调,请使用GLib.spawn_async

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. 但是文档非常不发达,浏览源代码还没有找到解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM