Saturday, August 8, 2009

Firefox Addons for Prism

If you havent tried Mozilla's Prism yet, I suggest you do. Basically it lets you run webapps more like a desktop application instead of having to run it in your browser that's already cluttered with a ton of tabs. I have stuff I use often like Gmail, Facebook, and VMware Server Console set up as Prism webapps and I find it alot easier to get to them instead of having to open my Firefox window and then wade through a bunch of tabs.

Unfortunately, Prism currently doesnt support FF addons (extensions) yet, but luckily will in the future. However, most addons should just work since both FF and Prism are based on the same subsystems. So...lets go ahead and fool Prism!

First, download the addon .XPI file. This file is really a .ZIP, so feel free to rename it or just open it with your favorate archive viewer. Inside you should find a file named install.rdf. This is where all the magic happens as it defines the target application for the addon. Open the file in a text editor and you should see something like this:
<em:targetapplication>
<!-- Firefox -->
<description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minversion>3.0a1</em:minversion>
<em:maxversion>3.0.*</em:maxversion>
</description>
</em:targetapplication>
The two lines that conserve us are the em:id, and versions. Prism checks these values to make sure they match to what it expects. If it doesnt it tells you to go away! After digging around a bit I found the values that are needed for Prism:
<em:targetapplication>
<!-- Prism -->
<description>
<em:id>prism@developer.mozilla.org</em:id>
<em:minversion>0.4</em:minversion>
<em:maxversion>1.0.0.*</em:maxversion>
</description>
</em:targetapplication>
You can have more than one targetApplication tag, so just add the above right after the one for Firefox in your addon and you're all set!

If you're not sure how to do the above, or are just lazy you can use the script below to convert the .XPI automatically! Unfortunately this will only work on linux so Windows and Mac people will have to stick to the instructions above.
#!/bin/bash
xpiFile=$1
tempDir=`mktemp -d`
tempZipFile=`mktemp`
tempRdfFile=`mktemp`

function cleanup {
# get rid of temporary working files
rm -rf $tempDir $tempZipFile $tempRdfFile > /dev/null
}

# make sure the XPI exists
if [ ! -e "$xpiFile" ]; then
echo "$xpiFile does not exist"
cleanup
exit
fi

# extract the files from the original package
unzip -d $tempDir $xpiFile > /dev/null

# make sure what you need is there
installRdfFile="$tempDir/install.rdf"
if grep -q "prism@developer.mozilla.org" $installRdfFile; then
echo "$xpiFile is already compatible with Prism, doing nothing"
cleanup
exit
fi

# replace stuff
sed "s_<em:targetApplication>_\
<em:targetApplication>\
<!-- Prism -->\
<Description>\
<em:id>prism@developer.mozilla.org</em:id>\
<em:minVersion>0.4</em:minVersion>\
<em:maxVersion>1.0.0.*</em:maxVersion>\
</Description>\
</em:targetApplication>\
&_" < $installRdfFile > $tempRdfFile
mv $tempRdfFile $installRdfFile

# rebuild the package
pushd $tempDir > /dev/null
rm $tempZipFile # i just needed the name, not the actual file
zip -r $tempZipFile * > /dev/null
popd > /dev/null
mv $tempZipFile $xpiFile

cleanup
Just save the below as mkPrismXpi.sh, make it executable, and run it as such:
./mkPrismXpi.sh myAddon.xpi

No comments:

Post a Comment