在GNOME Shell扩展中包含二进制组件 [英] Including binary components in a GNOME Shell extension

查看:143
本文介绍了在GNOME Shell扩展中包含二进制组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发GNOME Shell的扩展主要涉及通过GObject Introspection使用C API。这意味着使用C可以实现的大多数事情也可以在JavaScript中完成。 但在某些情况下,C API的功能无法(尚未)再现通过内省绑定。能够用本机C代码弥补这些差距是有用的。

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.

GNOME Shell扩展是否可以包含从中创建的二进制组件C代码?如果是这样,它们是如何整合的?

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:


  1. 硬编码路径,例如:〜/ .local / share / gnome-shell / extensions / myextension @ myname.example.com / mybinary

  2. 全局安装二进制文件并独立于扩展名。

一旦你有了路径,你就可以使用 Util.spawnCommandLine

Once you have the path you can for example use Util.spawnCommandLine:

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

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.

这篇关于在GNOME Shell扩展中包含二进制组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆