我认为应该使用D-Bus。基本上,我想要那样的东西 - https://wiki.gnome.org/Gjs/Examples/DBusClient - 但反过来说。
在扩展程序中,会有一个函数:
function f(s) { doSomethingWithS; }
运行后会调用此函数:
$ <something> "abc"
...在终端中,s == "abc"
。
在#gnome-shell
{@ 1}}上@jasper和@owen提出建议后,我调整了https://github.com/GNOME/gnome-shell/blob/master/js/ui/magnifierDBus.js中的一些代码:
irc.gnome.org
现在,发出后:
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Main = imports.ui.main;
let text;
function init() {
text = new St.Label({ text: "0:0", style_class: 'panel-text' });
}
function enable() {
Main.panel._rightBox.insert_child_at_index(text, 0);
}
function disable() {
Main.panel._rightBox.remove_child(text);
}
const TextInTaskBarIface = '<node> \
<interface name="com.michalrus.TextInTaskBar"> \
<method name="setText"> \
<arg type="s" direction="in" /> \
</method> \
</interface> \
</node>';
const TextInTaskBar = new Lang.Class({
Name: 'TextInTaskBar',
_init: function() {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(TextInTaskBarIface, this);
this._dbusImpl.export(Gio.DBus.session, '/com/michalrus/TextInTaskBar');
},
setText: function(str) {
text.text = str;
}
});
......没有任何反应。
答案 0 :(得分:6)
最终,gnome-shell扩展D-Bus服务器的工作版本:
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Main = imports.ui.main;
let text = null;
let textDBusService = null;
function init() {
text = new St.Label({ text: "0:0", style_class: 'panel-text' });
textDBusService = new TextInTaskBar();
}
function enable() {
Main.panel._rightBox.insert_child_at_index(text, 0);
}
function disable() {
Main.panel._rightBox.remove_child(text);
}
const TextInTaskBarIface = '<node> \
<interface name="com.michalrus.TextInTaskBar"> \
<method name="setText"> \
<arg type="s" direction="in" /> \
</method> \
</interface> \
</node>';
const TextInTaskBar = new Lang.Class({
Name: 'TextInTaskBar',
_init: function() {
text.text = "abc";
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(TextInTaskBarIface, this);
this._dbusImpl.export(Gio.DBus.session, '/com/michalrus/TextInTaskBar');
},
setText: function(str) {
text.text = str;
}
});
致电:
$ gdbus call --session --dest org.gnome.Shell --object-path /com/michalrus/TextInTaskBar --method com.michalrus.TextInTaskBar.setText 'some text'