GNOME 外壳扩展按钮



我正在尝试仅使用JavaScript编写扩展。我通过Hello World用Python编写了它!法典。但是,在开始时,我的菜单项按钮不起作用。另外,我无法使用Hello World添加菜单项!法典。我想,我想念一些东西。

按钮代码在这里:

const Lang = imports.lang;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
const TimeButton = new Lang.Class({
    Name: "Salah Time",
    Extends: PanelMenu.Button,
    _init: function () {
        let box = new St.BoxLayout({
            style_class: "system-status-icon"
        });
        let label = new St.Label({text: "Salah Time"});
        box.add_child(label);
        this.actor.addActor(box);
    }
});
function init() {
}
function enable() {
    let but = new TimeButton();
    Main.panel._leftBox.insert_child_at_index(but, 1);
}
function disable() {
    Main.panel._leftBox.remove_child(but);
}

GJS没有很多教程。我已经在尝试通过阅读其他扩展来写作。

谢谢。

const Lang = imports.lang;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
const TimeButton = new Lang.Class({
    Name: "TimeButton",
    Extends: PanelMenu.Button,
    _init: function () {
        this.parent(null, "TimeButton");
        // Icon
        this.icon = new St.Icon({
            icon_name: "appointment-symbolic",
            style_class: "system-status-icon"
        });
        this.actor.add_actor(this.icon);
        // Menu
        this.menuItem = new PopupMenu.PopupMenuItem("Salah Time", {});
        this.menu.addMenuItem(this.menuItem);
    }
});
function init() {
}
function enable() {
    let indicator = new TimeButton();
    Main.panel.addToStatusArea("should-be-a-unique-string", indicator);
    // hide
    Main.panel.statusArea["should-be-a-unique-string"].actor.visible = false;
    // change icon
    Main.panel.statusArea["should-be-a-unique-string"].icon.icon_name = "appointment-soon-symbolic";
    // show
    Main.panel.statusArea["should-be-a-unique-string"].actor.visible = true;
}
function disable() {
    // you could also track "indicator" and just call indicator.destroy()
    Main.panel.statusArea["should-be-a-unique-string"].destroy();
}

希望对某人有所帮助(如果你不在身边了(。

相关内容

  • 没有找到相关文章

最新更新