Javascript 如何对更改进行Gnome外壳扩展查询
我一直在与可怕的Gnome API文档作斗争,并提出了以下扩展:Javascript 如何对更改进行Gnome外壳扩展查询,javascript,gnome-3,gnome-shell-extensions,Javascript,Gnome 3,Gnome Shell Extensions,我一直在与可怕的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
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才能显示新内容。现在,当然有一种方法可以动态地实现这一点,但我在文档中找不到任何东西。面板中的消息基本上应该总是镜像文件中的任何内容。有什么办法吗?您需要为您的hello
文件获取一个Gio.File
句柄,然后它:
这对我有用。它将每30秒刷新一次标签值
- 添加以下导入 const Mainloop=imports.Mainloop
- 在您的init方法中
Mainloop.timeout_add(30000, function () { let stuff = GLib.spawn_command_line_sync("your_command")[1].toString(); let label = new St.Label({ text: stuff }); button.set_child(label);return true});
Mainloop.timeout_add(30000, function () {
let stuff = GLib.spawn_command_line_sync("your_command")[1].toString();
let label = new St.Label({ text: stuff });
button.set_child(label);return true});