2
votes

I have try to search here also googling. But it seem I have no luck.

I'm creating a small firefox addon, using Addon-SDK. Everything seem cool but the UI elements. It is really hard to implement.

I have read about the toolbarbutton which found here https://github.com/mozilla/addon-sdk/wiki/Community-developed-modules and the Mozilla XUL and decide to create my own toolbar button by tracking browser window, use WindowUtils.onTrack() and manipulating the Browser XUL DOM;

It's almost been done but when I try to disable and re-enable my add-on. The button didn't disappear and there were 2 button there.

This is so bad, can you show me how to destroy or remove that button also the other XUL elements when the addon was disabled or removed. We are using addon-SDK it was restart-less extension.

And my other question is what should we use when manipulate the BrowserXULDom WindowUtils or WindowMediator ? or the other, which is faster and more convenient ?

3

3 Answers

1
votes

The easiest thing to do is to use Erik Vold's toolbar library:

https://github.com/voldsoftware/toolbarbutton-jplib/blob/master/lib/toolbarbutton.js

If you're determined to write you own, I'd suggest looking at Erik's code as it does handle unloading the button.

1
votes

I have found a solution!

We can listen to the disable or uninstall event on our add-on and remove the XUL element at that time. Such as:

exports.onUnload = function(reason) {
  // remove code here
}

According to the Add-on SDK documentation, it has some bug with the add-on uninstall event but I think it will be solved soon.

In the SDK, there is a unload module, I have not tried it yet. Hope someone share about it.

The above solution is quite work for me, hope this help you too. Thank you!

0
votes

Firefox addon sdk have a bug, so if you want to detect uninstall of an addon. You have to use "disable" instead of "uninstall"

exports.onUnload = function (reason) {
         if (reason==='disable') {
            //remove code here
         }
    };