Software Development

Creating a quick and easy GNOME 3 extension

One of the good aspects of GNOME 3 is its extension framework. We take a baby step into this world by making an icon for the top panel.

Following on from yesterday's article on replacing NetworkManager with wicd, you would have noticed that there was no simple way to access the wicd network settings.

An icon in the top panel would fix this situation, and to get there a GNOME 3 extension is required.

The final result we are after: our wicd icon is on the far left.

To start a new extension run the following command and answer the questions that appear; the uuid should have the format of an email address, but not necessarily be tied to one.

gnome-shell-extension-tool --create-extension

Once completed the tool will create a uuid named folder in ~/.local/share/gnome-shell/extensions/ and put three skeleton files in there.

The one we are interested in is the extension.js file --- to get the wicd icon to appear, we need to change its contents to:

const StatusIconDispatcher = imports.ui.statusIconDispatcher;

function init(metadata) {

StatusIconDispatcher.STANDARD_TRAY_ICON_IMPLEMENTATIONS['wicd-client.py'] = 'wicd-gtk';

}

In order to enable our new extension, we will need to manipulate GNOME's gsettings by hand.

To see which extensions we used:

gsettings get org.gnome.shell enabled-extensions

Now add your extension's uuid to the array; for instance, to set only our new extension as enabled we would use:

gsettings set org.gnome.shell enabled-extensions['your_uuid@goes.here.example.com']

To get the extension to start, we need to restart GNOME 3, which is done by hitting Alt+F2 and typing an "r" and pressing return.

The window decorations will disappear, and when they reappear we should see our icon in the right side of the top panel.

In case it doesn't, the way to debug extensions is via Looking Glass, a built-in utility in GNOME 3 that is activated via Alt+F2 and typing "lg" at the prompt. Clicking on the errors tab will show that we are missing an enable function (this error will appear even if the icon does).

To rectify this error, we had empty enable and disable stubs to the extension.js file:

const StatusIconDispatcher = imports.ui.statusIconDispatcher;

function init(metadata) {

StatusIconDispatcher.STANDARD_TRAY_ICON_IMPLEMENTATIONS['wicd-client.py'] = 'wicd-gtk';

}

function enable() {

//nothing to do here

}

function disable() {

//nothing to do here

}

And there you have it.

This is far from the world's greatest extension, but it shows the basic structure of how GNOME extensions work, and wicd users now have an icon to replace the standard NetworkManager icon on the panel.

About

Some would say that it is a long way from software engineering to journalism, others would correctly argue that it is a mere 10 metres according to the floor plan.During his first five years with CBS Interactive, Chris started his journalistic advent...

0 comments

Editor's Picks