Files
gnome-shell-extensions/extensions/example/extension.js
Giovanni Campagna c5d79240fd Introduce a convenience module for initialization
Common code for retrieving translations and GSettings schemas has
been factored out into lib/convenience.js, which is part of
every extension installation.
Since that code relies on renames done at zip file creation time,
extensions can no longer be installed with "make install". Instead,
one should create the zip file and install it with the tweak-tool.
There is also a bash script, local-install.sh, that will install
everything in zip-files.
Also, since the GSettingsSchemaSource code is not yet in a stable
GLib release, extensions using GSettings have seen their stable
shell version removed.
2011-11-19 16:54:20 +01:00

43 lines
1.2 KiB
JavaScript

// Sample extension code, makes clicking on the panel show a message
const St = imports.gi.St;
const Mainloop = imports.mainloop;
const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;
const Main = imports.ui.main;
function _showHello() {
let text = new St.Label({ style_class: 'helloworld-label', text: _("Hello, world!") });
let monitor = Main.layoutManager.primaryMonitor;
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(); });
}
// Put your extension initialization code here
function init(metadata) {
log ('Example extension initalized');
let me = imports.ui.extensionSystem.extensions[metadata.uuid];
me.convenience.initTranslations(metadata);
}
let signalId;
function enable() {
log ('Example extension enabled');
Main.panel.actor.reactive = true;
signalId = Main.panel.actor.connect('button-release-event', _showHello);
}
function disable() {
log ('Example extension disabled');
if (signalId) {
Main.panel.actor.disconnect(signalId);
signalId = 0;
}
}