The Deep End

go to graworks.com! email!

Tuesday, July 05, 2005

PART ONE: No More Restarts for Installing Thunderbird Extensions

What came of this post was theReloadchromezilla extension; if you're looking for how to set up Thunderbird to use Reloadchromezilla, see Part Two--Part One deals with how the extension actually works.


As I wandered the Internet for how to not have to package your .xpi, install, and restart thunderbird, I happened across Ted Mielczarek's Extension Developer's Extension. Apparently, this program works beautifully and effortlessly for Firefox, but unfortunately I develop for Thunderbird. Mr. Mielczarek seemed to be having a problem with getting this to work in Thunderbird, so I opened up the .xpi (hope you don't mind; thanks for the great extension) and poked around until I got it to work.

The feature of the Extension Developer's Extension that allows you to see your changes without restarting is the "Reload All Chrome" feature. The "Reload All Chrome" feature consists of getting an instance of a @mozilla.org/chrome/chrome-registry;1 component, like this:
var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIXULChromeRegistry);
The nsIXulChromeRegistry interface is the one with the reloadChrome method.

Because the method's name is "reloadChrome," you would expect this to work. However, calling this will just mutate your Thunderbird window into a mass of deformity which is summarily unresponsive to doing whatever you normally do with Thunderbird.

I think the moral of this brief and ultimately fulfilling story is to never give up, even when confronted by the most insane difficulties. Basically, you just call reloadChrome() again!

here's the code:
function reloadTheChromeDammit(){
try {

var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIXULChromeRegistry);

chromeRegistry.reloadChrome();

var params ={out: ""};

window.open("chrome://reloadchromezilla/content/pleasewaitdialog.xul",
"_blank",
"chrome,close,titlebar,modal,centerscreen");

} catch(e) { }
}
The "dialog" pleasewaitdialog.xul is really just a window. The .xul file looks like this:



<page id="please-wait-dialog" title="Please Wait" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="pleaseWaitLoad();">
<description value="Please wait while whatever aweseome modifications you've made to your chrome are loaded">
<script src= "chrome://reloadchromezilla/content/reloadchromezillaoverlay.js">
</script>
</description></page>
The function pleaseWaitLoad() looks like this:
function pleaseWaitLoad(){
try{
var dialog = document.getElementById("please-wait-dialog");
setTimeout(function(){try{ var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIXULChromeRegistry);
chromeRegistry.reloadChrome(); window.close(); }catch(e){alert(e)}},2000);
}catch(e){
alert("in pleasewaitload "+e);
}
}
this is necessary because without setTimeout, Thunderbird executes the two reloadChrome() functions too quickly--apparently, you have to wait until Thunderbird has completely hosed itself from the first reloadChrome() before you can bring it back with another call to reloadChrome().

Hopefully this was useful to someone; an extension may follow.

Again, thank you Ted Mielczarek for being a lot better at developing Mozilla than I am!

3 Comments:

Post a Comment

<< Home