我也有同样的问题。目前还没有找到好的方法。目前我正在尝试两种非理想的方法来做到这一点:
- 对路径进行硬编码,例如:
~/.local/share/gnome-shell/extensions/[email protected] /cdn-cgi/l/email-protection/mybinary
- 全局安装二进制文件并独立于扩展。
一旦你有了路径,你可以使用Util.spawnCommandLine
:
const Util = imports.misc.util;
Util.spawnCommandLine('/path/to/your/bin');
Or 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);
}
});
我缺少的是是否有一种方法可以通过辅助方法以某种方式获取扩展路径。但文档非常不发达,浏览源代码还没有找到解决方案。