« December 2003 | Main | February 2004 »

January 14, 2004

IE Behaviors in Mozilla

http://lists.w3.org/Archives/Public/www-style/2004Jan/0141.html - the power of XBL strikes back, with some minor baby mangling.

Posted by doron at 7:23 AM

January 5, 2004

Mozilla Extension Updating Code

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:


<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.

Posted by doron at 2:16 PM