Wednesday, April 13, 2011

Experience with Jetpack - Create an add-on for Mozilla

- This is for my record/experience but you can find a lot of info out there on this same example -
- The reason I am revisiting this is that after installing Firefox 4.0 my add-on on 3.6 stop working :(  -
- Will post solution on the next post - 

There are 2 ways to work. One is locally, what is explained below, and the other is with the web based system (Add-on Builder):
https://builder.mozillalabs.com/

The youtube video http://www.youtube.com/watch?v=lKN4_fOKEWQ describes this second one but the text below describes the first one. Both examples actually do the same application.

-------------
There are other links of interest:
https://developer.mozilla.org/en/extensions
https://jetpack.mozillalabs.com/
https://developer.mozilla.org/en/Extensions/Firefox
https://developer.mozilla.org/En/Firefox_addons_developer_guide >> This is a nice guide to follow no matter what with a good introduction to web technologies.
-------------

On the locally based system, start by getting the environment:
https://jetpack.mozillalabs.com/

So, for the command line local operation basically start by getting Python and install it.
Then download SDK

After installation, you will have a directory like:
C:\Program Files\python\jetpack-sdk-0.9
On Windows command, you should run from the root directory of the SDK (the above address) bin\activate. (On lynux you would use "source"...) Nevertheless, on my case, if you open the .bat there are some commands that are not really well executed and get some errors. I clean it up and created new_activate.bat.

If it works, the last line after setting up the environment eventually calls python and displays a message back saying that you can execute "cfx docs". This is actually the cfx.bat. (There is another cfx txt file inside the same directory but the stuff inside is Unix or Python (?), not DOS batch file). Within that file (cfx.bat), python is executed again, but the path variable without commas makes python miss the path, so, actually I modified cfx and add the "" on the path:
python "%VIRTUAL_ENV%\bin\cfx" %1 %2 %3 %4 %5 %6 %7 %8 %9


I think what is happening is that every time we execute cfx.bat, this calls the python + parameters instruction inside the bat file, python interprets what we want to do based on those parameters and executes it before going back to the DOS console.

============= Trying to understand this ===========

I.e, at the end of cfx.bat, Python will launch the browser and within it, it will open the docs. On the Mozilla website, it says "This is the cfx command-line program. It's your primary interface to the Jetpack SDK. You use it to launch Firefox and test your add-on, package your add-on for distribution, view documentation, and run unit tests.". But actually I can't really make sense of it:
 
Nevertheless when we type "cfx docs" in the Python command line it doesn't work. So, what is that really doing? The stuff inside cfx file (without .bat) seems to be a unix command:
#! /usr/bin/env python import cuddlefish if __name__ == '__main__':
    cuddlefish.run()

http://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script
========================================

Anyhow, after typing cfx docs in the DOS command line, Firefox now opens a self-hosted web page at http://127.0.0.1:8888/

Follow then the tutorials... In few words, you have to create then a directory for the project you want to build, inside packages directory. Once you create the right files inside, jetpack SDK will automatically detect them. One file is a JSON (http://en.wikipedia.org/wiki/JSON. It is basically a way to create simple descriptive files, with property and value for that property.) which describes the package. The others are modules (.js) and the main.js which is the center of the project.

The one in the text is also explained here:
http://www.youtube.com/watch?v=lKN4_fOKEWQ

It should be relatively easy to run the translator example in Google without any problems. It is impressively powerful!

By the way, if we want to use the Mozrunner we better put also the "" in the bat file or otherwise Python won't interpret it right.

To add the add-on, I can't seem to find a menu on the add-on manager on Mozilla, so, I just dragged the xpi in the add-on manager. Still, I seem to need to re-start and in some instructions says that you don't.
I found this: https://wiki.mozilla.org/Extension_Manager:Bootstrapped_Extensions
http://www.accessfirefox.org/Install_Addon_Manually.php

No comments:

Post a Comment