2
votes

I have problem with simple-prefs module in my addon (simple-prefs documentation). I'm trying to use menulist or radio types. Problem is addon isn't loaded or started - function main isn't called.
I don't have this problem when I use cfx run command, which starts new, clear instace of Firefox - everything works correctly. I tried run this addon on two different computers, unfortunately with the same result.
Below I put code snippets:

main.js:

var prefs = require("simple-prefs").prefs;
...
exports.main = function (options, callbacks) {
    console.log("Addon loaded: " + self.loadReason);
    var modLogic = pageMod.PageMod({
        include: "*",
        contentScriptWhen: "start",
        contentScriptFile: data.url("myContentScript.js"),
        onAttach: function (worker) {
            console.log("Page worker attached to: " + worker.tab.url);
            // here I'm using prefs object: if(prefs.decision === "Y")
        }
    });
}

package.json:

{
    "name": "myaddon",
    ...
    "preferences" : [{
        "name": "decision",
        "title": "someTitle",
        "type": "radio", // or menulist
        "value": "D",
        "options": [{
                "value": "D",
                "label": "Default"
            },
            {
                "value": "Y",
                "label": "Yes"
            },
            {
                "value": "N",
                "label": "No"
            }
        ]
    }]
}

I'm using addon-sdk 1.12 and Firefox 18.0. In my code snippets can be bugs - I've just written it here.

2
There is no matter, if this value is string or integer - it doesn't work. - Tomasz Dzięcielewski
Have you confirmed that the use of the simple-prefs module is the cause of the erratic behavior? - paa
Yes. When I removed radio/menulist preference and replaced it with bool preference, addon started working. - Tomasz Dzięcielewski

2 Answers

2
votes

I'd created this example repo a while ago:

https://github.com/canuckistani/jp-prefs-example

All of the functionality works for me, see this screenshot:

https://dl.dropbox.com/u/44296964/Screen%20Shot%202013-01-18%20at%201.50.31%20PM.png

I'm also using Firefox 18 and SDK 1.12. In your example you have a comment in your JSON, that might be causing you problems.

0
votes

That module will be changed in future versions so I don't know how safe is it to be used. I use simple-storage to keep data between browser session. Also the cfx environment has sometimes some weird behavior not registering types correctly. I use JSON.parse() just to make sure.