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

后端 未结 3 1694
有刺的猬
有刺的猬 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 10:57
    AddonManager.addAddonListener({
        onUninstalling: function(addon){
            // alert("uninstalling!");   
            Services.prefs.setBoolPref("extensions.CustomButton.firstrun", true);
        }
      });
    
    0 讨论(0)
  • 2021-01-13 11:12

    For bootstrap addons there is an uninstall() procedure, but for it to trigger you must use install() procedure, simply passing it two arguments and leaving the function blank will work.

    Here is what I use in my add-ons: https://gist.github.com/Noitidart/e0d3c21ab38822fbfd17

    function uninstall(aData, aReason) {
        console.info('UNINSTALLING ZOOMR reason = ', aReason);
        if (aReason == ADDON_UNINSTALL) { //have to put this here because uninstall fires on upgrade/downgrade too
            //this is real uninstall
            var prefPrefix = 'extensions.my-addon@jetpack.';
            console.log('deleting branch of: ' + prefPrefix);
            Services.prefs.deleteBranch(prefPrefix);
        }
    }
    
    0 讨论(0)
  • 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 ...

    0 讨论(0)
提交回复
热议问题