首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gjs/gnome-shell-extension:每60秒更新一次按钮文本

gjs/gnome-shell-extension:每60秒更新一次按钮文本
EN

Stack Overflow用户
提问于 2021-07-27 02:28:15
回答 1查看 78关注 0票数 0

我想写一个简单的gnome扩展,在顶部栏上打印文本文件中的一些文本。我设法打印了文本,但每隔60秒更新一次遇到了问题。用gjs能做到吗?

这是我想出来的:

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

发布于 2021-07-28 11:23:52

您需要使用GLib.timeout_add_seconds()

代码语言:javascript
复制
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 60, () => {
   updateLabel(newText);
});

顺便说一句,您可能应该使用ByteArray.toString()将从文件中获得的Uint8Array转换为字符串。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68534827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档