1

Recently I am getting started with GNOME extensions development. By executing gnome-shell-extension-tool --create-extension in terminal I have created hello world extension but when I change the code to build a pop-up like extension I am getting this error enter image description here

The JS code I am using is

const St = imports.gi.St;
const Mainloop = imports.mainloop;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;
const Lang = imports.lang;
const PopupMenu = imports.ui.popupMenu;
const PanelMenu = imports.ui.panelMenu;
const Gettext = imports.gettext;
const MessageTray = imports.ui.messageTray;

const _ = Gettext.gettext;

function _myButton() {
    this._init();
}

_myButton.prototype = {
    __proto__: PanelMenu.Button.prototype,

    _init: function() {
        PanelMenu.Button.prototype._init.call(this, 0.0);
        this._label = new St.Label({ style_class: 'panel-label', text: _("HelloWorld Button") });
        this.actor.set_child(this._label);
        Main.panel._centerBox.add(this.actor, { y_fill: true });

        this._myMenu = new PopupMenu.PopupMenuItem(_('HelloWorld MenuItem'));
        this.menu.addMenuItem(this._myMenu);
        this._myMenu.connect('activate', Lang.bind(this, _showHello));
    },

    _onDestroy: function() {}
};

function _showHello() {

    let text = new St.Label({ style_class: 'helloworld-label', text: _("Hello, world!") });
    let monitor = global.get_primary_monitor();

    global.stage.add_actor(text);
    text.set_position(Math.floor (monitor.width / 2 - text.width / 2),
                      Math.floor(monitor.height / 2 - text.height / 2));

    Mainloop.timeout_add(3000, function () { text.destroy(); });
}


function main(extensionMeta) {

    let userExtensionLocalePath = extensionMeta.path + '/locale';
    Gettext.bindtextdomain("helloworld", userExtensionLocalePath);
    Gettext.textdomain("helloworld");

    let _myPanelButton = new _myButton();
}

Can anyone tell me why I am getting this error. I am using Fedora 20 with GNOME Shell 3.10.2.1

Isham Mohamed
  • 2,629
  • 1
  • 14
  • 27

1 Answers1

2

You are lacking the enable() and disable() functions in extension.js. These 2 are mandatory: enable() is the entry point after your extension is loaded (instead of main()); and disable() is called after deactivation in gnome-tweak-tool. These basic functions must be present in all extensions, including the "Hello World" example you mentioned.

Gnome Shell documentation is scarce and deficient. I'm guessing you are basing your code on very old guidelines, for the main() function was deprecated since 3.2. Read these references: 1, 2

usermynut
  • 37
  • 5