最近,我开始了GNOME扩展开发。通过在终端中执行gnome-shell-extension-tool --create-extension,我已经创建了hello world扩展,但是当我更改代码来构建类似弹出窗口的扩展时,我得到了这个错误

我使用的JS代码是
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();
}有人能告诉我为什么会出现这个错误吗?我正在使用带有GNOME Shell 3.10.2.1的Fedora 20
发布于 2014-08-14 12:45:18
您在extension.js中缺少enable()和disable()函数。这两项是必需的:enable()是加载扩展后的入口点(而不是main());disable()是在gnome-tweak tool中停用后调用的。这些基本函数必须出现在所有扩展中,包括您提到的"Hello World“示例。
Gnome Shell文档很少,而且存在缺陷。我猜你的代码是基于非常古老的指导方针,因为main()函数从3.2开始就被弃用了。阅读这些参考资料:1、2
https://stackoverflow.com/questions/24205927
复制相似问题