[Project_owners] Extension Updating Code
doron at nexgenmedia.net
Mon Jan 5 12:30:19 EST 2004
I've written some code for an Mozilla extension to upgrade itself.
The class (nsExtensionUpdater) is at
http://nexgenmedia.net/nsExtensionUpdater.js. What it allows is to
update the .jar file your extension added to Mozilla. Obviously, the
user still needs to restart mozilla for the update to take effect.
The code should work no matter where the extension was added
(profileDir/chrome or mozilla/chrome), as it checks to see where the jar
file is currently installed.
A progress function has to be passed to the JS "class" so that you can
write your own UI. The progress function is called at certain
conditions (error occured, no updated available, new update available,
update installed). If an update is available,
the progress function gets called and must return true for the update to
be installed. This allows an "Do you want to proceed" dialog (say using
the confirm() dialog) to be used.
An XML file is used to store update information such as the latest
version and where the latest version of the jar file can be downloaded
from. The location of the XML file is passed to the constructor of the
class. An example of the XML structure:
The code is still somewhat ugly, but wanted to share this since I
haven't seen anything similar out there. I tested on 1.5, should work
in FB/TB as well.
Mini example of how its used:
updater = new
-1 An error has occured
0 No new update available
1 New update available. If we are to proceed and install
the update, return true, else return false.
2 New update installed
var rv = true;
case -1 :
alert("An Error Has Occured")
case 1 :
// here is where you should ask if the user really wants to
install the update
// return true to do the update, false to not.
rv = confirm("An update is available. Do you want to install it?");
case 2 :
progressFunc gets called during certain conditions, basically a hacked
up progress listener.
More information about the Project_owners