Firefox Addon: how to remove preferences when addon is being uninstalled?

后端 未结 3 1698
有刺的猬
有刺的猬 2021-01-13 10:44

I have the following piece of code in my Firefox addon:

var firstrun = Services.prefs.getBoolPref(\"extensions.CustomButton.firstrun\");

if (firstrun) {
  /         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-13 11:15

    In my Add-On, where I set this on install:

    const {Cc,Ci} = require("chrome");
    var pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
    pref.setIntPref("network.http.response.timeout", 3600*24);
    

    I solved it like this, that in my main.js I added this code at the end:

    exports.onUnload = function(reason) {
        //called when add-on is 
        //    uninstalled
        //    disabled
        //    shutdown
        //    upgraded
        //    downgraded
        pref.clearUserPref("network.http.response.timeout");
    };
    

    That worked on disabling and uninstalling the addon.

    Note: this is still not perfect, see comments. I will have to work on this ...

提交回复
热议问题