我一直在与可怕的 Gnome API 文档作斗争,并想出了这个扩展:
const St = imports.gi.St;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const GLib = imports.gi.GLib;
let label;
function init() {
label = new St.Bin({ style_class: 'panel-label' });
let stuff = GLib.spawn_command_line_sync("cat /home/user/temp/hello")[1].toString();
let text = new St.Label({ text: stuff });
label.set_child(text);
}
function enable() {
Main.panel._rightBox.insert_child_at_index(label, 0);
}
function disable() {
Main.panel._rightBox.remove_child(label);
}
这应该读取hello
文件中的任何内容并将其显示在顶部面板中。但是,如果我更改hello
文件的内容,我必须重新启动 Gnome 才能显示新内容。现在,肯定有一种方法可以动态地执行此操作,但我在文档中找不到任何内容。面板中的消息基本上应该始终反映文件中的任何内容。任何想法如何做到这一点?