3

D-Bus を使用する必要があると思います。基本的には、 https://wiki.gnome.org/Gjs/Examples/DBusClientのようなものが欲しいのですが、その逆です。

拡張機能には、次の関数があります。

function f(s) { doSomethingWithS; }

そして、この関数は実行後に呼び出されます:

$ <something> "abc"

…ターミナルで、s == "abc".


#gnome-shellonで @Jasper と @owen からの提案の後、 https : //github.com/GNOME/gnome-shell/blob/master/js/ui/magnifierDBus.jsirc.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;
    }
});

今、発行した後:

% dbus-send --dest=com.michalrus.TextInTaskBar /com/michalrus/TextInTaskBar \
    com.michalrus.TextInTaskBar.setText string:"123"

… 何も起こりません。

4

1 に答える 1

7

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'
于 2015-10-07T21:13:49.287 に答える