I have a Firefox addon made with the add-on SDK.
https://addons.mozilla.org/es/firefox/addon/board-notes/
To add a toolbar button I use a popular library for the SDK toolbarbutton.js:
https://github.com/erikvold/toolbarbutton-jplib/blob/master/lib/toolbarbutton.js
I only want to add the icon when it first installs and it works, the icon appears but after restarting the browser the icon disappears. The user has to use the right click button to open the setup browser bar and drag the icon again to the bar. Then if he restarts the icon continue correctly in its place.
I want to fix this behaviour because the most part of users probably don't know that they can recover the icon with the setup options.
I've tested some functions to detect if the icon is not in his place to move again, but by doing this if the user hides the icon, when he restarts it will appear again. And this is forbidden by Firefox policies.
I'll appreciate any help, I'm going crazy.
The code I use is this:
button = createButton(options);
if (options.loadReason == "install")
{
button.moveTo({
toolbarID: "nav-bar",
insertbefore: "home-button"
});
}
function createButton(options) {
return toolbarbutton.ToolbarButton({
id: "NoteBoard",
label: "Note Board",
tooltiptext: "Note Board",
image: data.url("noteboardMini.png"),
onCommand: function() {
openPopup();
},
onContext: (function () {
var installed = false;
return function (e, menupopup, _menuitem) {
//Install command event listener
if (!installed) {
menupopup.addEventListener("command", function (e) {
var link = e.originalTarget.value;
if (link) open(link.replace(/\?.*/ , ""));
});
installed = true;
}
var temp = (function (arr) {
arr.forEach(function (item, index) {
for (var i = index + 1; i < arr.length; i++) {
if (arr[i] && item.label == arr[i].label) {delete arr[index]}
}
});
return arr.filter(function (item){return item});
})(loggedins);
//remove old items
while (menupopup.firstChild) {
menupopup.removeChild(menupopup.firstChild)
}
function addChild (label, value) {
var item = _menuitem.cloneNode(true);
item.setAttribute("label", label);
item.setAttribute("value", value);
menupopup.appendChild(item);
}
if (temp.length) {
temp.forEach(function (obj) {
addChild(obj.label, obj.link);
});
}
else {
addChild(_("context"), "");
}
}
})()
});
}


onContextfunction run? When is thisonContextsupposed to happen? I have not yet found anything to handle it in the library you linked to. - Stephen