Jun2'10

Jetpack 0.4 Extension Example – MailPing

With the release of Jetpack SDK 0.4, developers have a variety of new APIs at their disposal. The following example will show you how to use the Page Worker and Widget APIs in your add-on code, but also have a look at the other notable APIs released in 0.4 – Simple Storage and Private Browsing.

You’ve got mail!

To show off the Jetpack SDK 0.4 release, I’ve constructed an add-on that checks Gmail and Yahoo Mail for unread inbox messages. It also lets you open tabs to both email services in a single click, and has some snazzy UI to boot!


How it’s made

First you want to create a new Widget instance – the Widget API allows you to easily add UI to Firefox in a way friendly to the user – here’s what the code looks like:

var mpWidget = require('widget').Widget({
    label:'MailPing',
    content: '...HTML content goes here...',
    onReady: function(){
	// onReady gives you access to your Widget when it's ready for manipulation

        // My code was more extensive for this example so please view the source
        // via the download link further down the page
    },
    onClick: function(){
        // This is one of the events you can use to perform actions based on user input,
        // see the documentation for the full list
    }
});

require('widget').add(mpWidget);

I also used the Page Worker API to check the message counts, here is what an instantiation of a Page Worker instance looks like:

var gmail = require('page-worker').Page({
    content: mpProviders.gmail.content,
    onReady: function(){  // The onReady function is fired each time the content option is set
        parse.run('gmail', gmail);
        gmail.onReady = function(){}
    }
});

require('page-worker').add(gmail);

Get the source files

Download this test extension package and unpack it to the packages/ subdirectory in your Jetpack SDK directory. Make sure the SDK is activated per the instructions in the docs. Then enter the mailping/ subdirectory and execute the command cfx -a firefox run to try it out.

Install the extension

To use the extension, you can install the MailPing test extension from addons.mozilla.org.

- Daniel Buchner, on behalf of the Jetpack team

About the Author

Myk Melez

Myk is a longtime Mozilla toolsmith and engineer who worked on Forumzilla, Bugzilla, and Firefox before joining labs. He loves to hack and make people happy.

More from Myk Melez »

Category

Uncategorized

About Mozilla Labs

Laboratories are where science and creativity meet to develop, research, and explore new ideas. Mozilla Labs embraces this great tradition - a virtual lab where people come together to create, experiment, and play with new Web innovations and technologies.

Newsletter

Enter your email address here to subscribe to our mailing list for announcements: