【发布时间】:2021-10-02 16:27:06
【问题描述】:
我想编写一个简单的 gnome 扩展程序,在我的顶栏上从文本文件中打印一些文本。我设法打印了文本,但我无法每 60 秒更新一次。甚至可以用 gjs 吗?
这是我想出的:
const {St, Clutter} = imports.gi;
const Main = imports.ui.main;
const GLib = imports.gi.GLib;
let panelButton;
function init () {
// Create a Button with "Hello World" text
panelButton = new St.Bin({
style_class : "panel-button",
});
let fileContents = String(GLib.file_get_contents("path/to/myfile.txt")[1]);
let panelButtonText = new St.Label({
text : fileContents,
y_align: Clutter.ActorAlign.CENTER,
});
panelButton.set_child(panelButtonText);
}
function enable () {
// Add the button to the panel
Main.panel._centerBox.insert_child_at_index(panelButton, 2);
}
function disable () {
// Remove the added button from panel
Main.panel._centerBox.remove_child(panelButton);
}
【问题讨论】:
-
如果不深入探讨问题。已经有一个扩展。 unix.stackexchange.com/a/659786/383311
标签: gnome gnome-shell gnome-shell-extensions gjs