Set preferences in the user branch and unset them on uninstall

前端 未结 2 1984
灰色年华
灰色年华 2020-12-19 14:01

I created a firefox add-on with the following lib/main.js:

const {Cc,Ci} = require(\"chrome\");
var pref = Cc[\"@mozilla.org/preferences-service;1\"].getServ         


        
相关标签:
2条回答
  • 2020-12-19 14:42

    Here's how I did it just now:

    function clearPrefBranch(aPrefBranchName) {                                     
      var defaultBranch = Services.prefs.getDefaultBranch(null);                    
      defaultBranch.deleteBranch(aPrefBranchName);                                  
    }    
    

    Then, just call clearPrefBranch with an argument of extensions.mypluginname (assuming you used the naming convention, and you should be able to delete all of your extension's installed preferences.

    EDIT:

    The code I used inside of my main.js file:

    const {Cc,Ci,Cm,Cr,Cu} = require("chrome");                                     
    Cu.import("resource://gre/modules/Services.jsm");  
    
    exports.onUnload = function(aOptions, aCallbacks) {                             
      MyPlugin.shutdown();                                                           
    };
    
    function clearPrefBranch(aPrefBranchName) {                                     
      var defaultBranch = Services.prefs.getDefaultBranch(null);                    
      defaultBranch.deleteBranch(aPrefBranchName);                                  
    }
    
    var MyPlugin = {
      shutdown: function() {                                                      
        prefLoader.clearPrefBranch('extensions.oopstab');                         
    
      }
    }; 
    
    0 讨论(0)
  • 2020-12-19 14:43

    I solved the second part (uninstall) 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 add-on.

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