I have the following piece of code in my Firefox addon:
var firstrun = Services.prefs.getBoolPref("extensions.CustomButton.firstrun");
if (firstrun) {
// alert("first run");
Services.prefs.setBoolPref("extensions.CustomButton.firstrun", false);
installButton("nav-bar", "custom-button-1");
} else {
// alert("not first run");
}
In addon_dir/defaults/preferences/pref.js, I have the following string:
pref("extensions.CustomButton.firstrun", true);
When addon runs for the first time, the code above understands it and installs a button on the toolbar. Also, it adds the following string to profile_dir/prefs.js:
user_pref("extensions.CustomButton.firstrun", false);
It works fine. The only thing that bothers is this string in profile_dir/prefs.js is not cleared when I uninstall the addon. So, if I install this addon for the second time, the firstrun value is false, and the button is not added to the toolbar.
Question: is it possible to remove addon preferences (in my case, user_pref("extensions.CustomButton.firstrun", false);) when addon is uninstalled?
A note: I have read this article, but still have no idea what event to wait for. Any working example? I believe it is a common operation for addon creators and am very surprised there are no articles explaining these matters in detail.
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With