[Project_owners] Extension Updating Code

Doron Rosenberg doron at nexgenmedia.net
Mon Jan 5 13:39:40 EST 2004


The code is MPL'ed.  Sure, feel free to reuse it for jslib.

Pete Collins wrote:

> Doron Rosenberg wrote:
>
>> I've written some code for an Mozilla extension to upgrade itself.
>
>
> Excellent, we were going to write a general purpose updater. Can I 
> include this code or a variation in jslib?
>
> Is it MPL'd?
>
> --pete
>
>>
>> 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:
>>
>> <?xml version="1.0"?>
>> <extensionUpdateInformation>
>>  <latestVersion>0.2</latestVersion>
>>  <location>http://goat.austin.ibm.com:8080/xulbluepages.jar</location>
>> </extensionUpdateInformation>
>>
>> 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:
>>
>> var updater;
>> function bluepagesAutoUpdate(){
>>  updater = new 
>> nsExtensionUpdater("http://goat.austin.ibm.com:8080/update.xml", 
>> "0.1", "xulbluepages.jar");
>>  updater.getUpdate(progressFunc);
>> }
>>
>> /*
>> aProgressNum
>>   -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
>> */
>>
>> function progressFunc(aProgressNum){
>>
>>  var rv = true;
>>
>>  switch (aProgressNum){
>>
>>    case -1 :
>>      alert("An Error Has Occured")
>>      break;
>>
>>    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?");
>>      break;
>>
>>    case 2 :
>>      alert("Install Successfull")
>>      break;  }
>>
>>  return rv;
>> }
>>
>> progressFunc gets called during certain conditions, basically a 
>> hacked up progress listener.
>>
>> _______________________________________________
>> Project_owners mailing list
>> Project_owners at mozdev.org
>> http://mozdev.org/mailman/listinfo/project_owners
>>
>
>




More information about the Project_owners mailing list