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

4 Responses to “Jetpack 0.4 Extension Example – MailPing”

  1. shl says:

    Looks very cool, but doesn't work properly on 3.7a5pre. Always shows "Login" instead of unread messages number.

  2. zyegfryed says:

    Hi,
    Really interesting project/add-on. The widget design is simply awesome !
    I've got the same trouble as shl… I'm on Mac OSX 10.6 with FF 3.6.3.

  3. SpeedGun says:

    After looking at the code, it appears it requires you to be logged in with both Yahoo and Gmail

  4. Manuel says:

    @shl

    I´ve got the same problem.

    Hope it´ll run these days!

Leave a Reply

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: